How to use tic/toc function efficiently if the code has many loops and every loops takes half an hour?
7 次查看(过去 30 天)
显示 更早的评论
Hi, I am using tic/toc function to meausre my custom CNN architecture classification time. I try to find fastest(prediction time, in this case in matlab classify function) custom model. To do this i have 7 for loops... In loops i change the input data size, number of filters in first and second conv layer, filter sizes in first and second conv layer, strides and so on.... I used the tic toc function in the loops as shown in below.
for
for
.
.
layers = ....
net = trainNetwork(augimdsTrain,layers,options);
tic ;
[YPred,probs] = classify(net,augtestDS);
toc
time(a)= toc
.
.
end
end
There are 432 possibilities depending on for loops. First 3-4 loops give good results(i mean tic/toc function). But after some hours tic/toc function doesnt give good results. The time is increasing always... i expect max time must be around 3seconds but after 2 days of running code tic/toc time rised to 8 seconds. I stoped the code using ctrl+c and i runed the code again(code starts with clc clear all close all) but the tic/toc time was again around 8 seconds.. then i closed and opend the matlab. ı runed the code just for 1 loop and it gives expected small times around 2 seconds. What should be the problem when i use tic/toc function for type of huge loops and huge running time of codes? How to make tic/toc function working for big loops? I think matlab using more memory depending on runing time. Maybe there is an easy solution.
Thank you for advising me on this topic.
Hakan
5 个评论
Walter Roberson
2020-2-9
accuracy(a)= mean(YPred == testDS.Labels)
a=a+1;
You are not pre-allocating the accuracy array, so every iteration of your seven-deep loops you would be growing accuracy. That will get slower and slower as you go.
You are also not pre-allocating
for v = 1 : numel(varSize)
for num_of_filt_conv1_j = 1: numel(num_of_filt_conv1)
for size_of_filt_conv1_j = 1: numel(size_of_filt_conv1)
for stride1_j = 1: numel(stride1)
for num_of_filt_conv2_j = 1:numel(num_of_filt_conv2)
for size_of_filt_conv2_j = 1: numel(size_of_filt_conv2)
for stride2_j = 1:numel(stride2)
The upper bounds appear to be known ahead of time before the for v loop starts, so you can multiply them all out to find the size of accuracy that you will need.
You have the same issue with time(a)
Also, every iteration you are displaying all of time and all of accuracy, not just the latest value. You should be putting a semi-colon on the end of the assignment statements.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!