필터 지우기
필터 지우기

error while transferring weights of a trained CNN network to an empty CNN network

조회 수: 1 (최근 30일)
Hi,
I am trying to transfer the weights of layer 11 from 'original_net' to layer 11 of 'layers_final'. Both have same structure and 'layer_final' is just the empty, untrained version of 'original net'. i am using the following command:
Layers_final(11).Weights = net_1.Layers(11).Weights
I get the following error while doing so:
Error using nnet.cnn.layer.TransposedConvolution2DLayer/set.Weights (line 204)
Expected input to be of size 4x4x8x1, but it is of size 4x4x8x8.
code for layers_final:
imageLayer_final = imageInputLayer([32,32,1]);
encodingLayers_final = [ ...
convolution2dLayer(3,16,'Padding','same'), ...
reluLayer, ...
maxPooling2dLayer(2,'Padding','same','Stride',2), ...
convolution2dLayer(3,8,'Padding','same'), ...
reluLayer, ...
maxPooling2dLayer(2,'Padding','same','Stride',2), ...
convolution2dLayer(3,8,'Padding','same'), ...
reluLayer, ...
maxPooling2dLayer(2,'Padding','same','Stride',2)];
decodingLayers_final = [ ...
createUpsampleTransponseConvLayer(2,8), ...
reluLayer, ...
createUpsampleTransponseConvLayer(2,8), ...
reluLayer, ...
createUpsampleTransponseConvLayer(2,16), ...
reluLayer, ...
convolution2dLayer(3,1,'Padding','same'), ...
clippedReluLayer(1.0), ...
regressionLayer];
layers_final = [imageLayer,encodingLayers,decodingLayers];
net_original attached with the question.
Thanks

채택된 답변

Srivardhan Gadila
Srivardhan Gadila 2020년 2월 24일
If the function createUpsampleTransponseConvLayer is the helper function from the example Prepare Datastore for Image-to-Image Regression then change the 'NumChannels' Name-Value Pair Argument to 'auto' or don't mention it in the transposedConv2dLayer function.
% helper function from the example Prepare Datastore for Image-to-Image Regression
function out = createUpsampleTransponseConvLayer(factor,numFilters)
filterSize = 2*factor - mod(factor,2);
cropping = (factor-mod(factor,2))/2;
numChannels = 1;
out = transposedConv2dLayer(filterSize,numFilters, ...
'NumChannels',numChannels,'Stride',factor,'Cropping',cropping);
end
Since the layer is defined with 'NumChannels' (number of channels of the input to this transposedConv2dLayer) as 1 hence it can accept wieghts of size "filterSize x filterSize x numFilters x numChannels" which is 4x4x8x1 in this case.
Change the function as follows:
function out = createUpsampleTransponseConvLayer(factor,numFilters)
filterSize = 2*factor - mod(factor,2);
cropping = (factor-mod(factor,2))/2;
out = transposedConv2dLayer(filterSize,numFilters, ...
'Stride',factor,'Cropping',cropping);
end
and then define the layers.
  댓글 수: 3
Srivardhan Gadila
Srivardhan Gadila 2020년 3월 9일
I have heard that this issue is known and the concerned parties might be working on it.
Radians
Radians 2021년 1월 15일
Hello
I know its been long now but if I try to perform the same operation with the transpose convolution function as follows:
O_dltconv1=dltranspconv(O_maxpool3,K_tconv_1,B_tconv_1,'Stride',2,'Cropping',1);
with:
K>> size(O_maxpool3)
ans =
4 4 8 500
K>> size(K_tconv_1)
ans =
4 4 8
K>> size(B_tconv_1)
ans =
1 1 8
I get the following error:
Number of channels to convolve (1, specified by the size of the 'U' dimension of the weights) must be equal
to the size of the 'C' dimension of the input data (8).
Could you please highlight what am I doing wrong, since I set the channels of the transpose convolution filter to 1 as you said?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by