Info

此问题已关闭。 请重新打开它进行编辑或回答。

Activations differ with increased number of input.

1 次查看(过去 30 天)
I input the first frame of an image sequence to a pre-trained network and get activation from a certain layer, no problem here. But when I test it in this loop:
% workdat is HxWx3xS image sequence
% extract_from_here is the layer I want to extract activation/feature map from
for i = 1: size(workdat, 4)
tmp = activations(net, workdat(:,:,:,1:i), extract_from_here, 'OutputAs', 'columns');
ac(:,i) = tmp(:,1);
end
Then, the interesting case happens when I do the comparison below:
for k = 1:size(ac,2)
prc(:,k) = 100*abs((ac(:,1)-ac(:,k))./ac(:,1));
end
So what I do is just comparing activation of first frame in the sequence between activations of the same frame when the activations are extracted by giving HxWx3xN to the network where N is running from 1 to S.
In prc array, I've seen errors of 3.4 %. Why is this the case? Why MATLAB extracts activation of the same image different when I input it to CNN alone and when I input it to CNN with more images?
Note: When I input the same image to the network multiple times alone, I get no difference:
ac1 = activations(net, workdat(:,:,:,1), extract_from_here, 'OutputAs', 'columns');
ac2 = activations(net, workdat(:,:,:,1), extract_from_here, 'OutputAs', 'columns');
nnz(ac1-ac2) % always gives 0.

回答(1 个)

Raunak Gupta
Raunak Gupta 2020-9-1
Hi,
I tried to reproduce the same with Example mentioned here which uses Alexnet and MerchData. The percentage error calculated for me was ranging from very low of 10^-7 to 0.1%. This issue is occurring due to the ‘MiniBatch’ Name-Value pair in activations function. If you keep the MiniBatchSize as 1, there is no difference in output with the above approach. Below is the code that I tried.
unzip('MerchData.zip');
imds = imageDatastore('MerchData', ...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
img = readall(imds);
net = alexnet;
bigImage = zeros(227,227,3,75);
for i=1:75
bigImage(:,:,:,i) = img{i};
end
for i = 1: size(bigImage, 4)
tmp = activations(net, bigImage(:,:,:,1:i), 'fc7', 'OutputAs', 'columns', 'MiniBatchSize',1);
ac(:,i) = tmp(:,1);
end
for k = 1:size(ac,2)
prc(:,k) = 100*abs((ac(:,1)-ac(:,k))./ac(:,1));
end
max(prc(:)) % Gives output 0
I have brought this issue of MiniBatchSize to the notice of our developers. They will investigate the matter further.

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by