Re-build Resnet 50 but error

1 view (last 30 days)
가람 이
가람 이 on 13 Jun 2021
Answered: Anshika Chaurasia on 16 Jun 2021
Hello, any other guys solve this problem ? i was change the some code but tooks error . can u anyother guys solve this problem ?
original code is running
orginal code is here :
inputSize = [256 192 3]; originalNet = resnet18;
lgraph = layerGraph(originalNet); lgraph = removeLayers(lgraph,'pool5');
lgraph = removeLayers(lgraph,'fc1000'); lgraph = removeLayers(lgraph,'prob');
lgraph = removeLayers(lgraph,'ClassificationLayer_predictions');
layers = [
transposedConv2dLayer(4,256,"Name","transposed-conv_1","Cropping","same","Stride",[2 2], "BiasLearnRateFactor", 0)
%batchNormalizationLayer("Name","batchnorm_1")
reluLayer("Name","relu_1")
transposedConv2dLayer(4,256,"Name","transposed-conv_2","Cropping","same","Stride",[2 2],"BiasLearnRateFactor",0)
%batchNormalizationLayer("Name","batchnorm_2")
reluLayer("Name","relu_2")
transposedConv2dLayer(4,256,"Name","transposed-conv_3","Cropping","same","Stride",[2 2],"BiasLearnRateFactor",0)
%batchNormalizationLayer("Name","batchnorm_3")
reluLayer("Name","relu_3")
convolution2dLayer(1,numJoints,"Name","conv2d_final")
];
lgraph = addLayers(lgraph,layers);
lgraph = connectLayers(lgraph,'res5b_relu','transposed-conv_1/in');
dlnet = dlnetwork(lgraph);
i was change the like that :
inputSize = [256 192 3]; originalNet = resnet50;
lgraph = layerGraph(originalNet);
lgraph = removeLayers(lgraph,'avg_pool');
lgraph = removeLayers(lgraph,'fc1000');
lgraph = removeLayers(lgraph,'fc1000_softmax');
lgraph = removeLayers(lgraph,'ClassificationLayer_fc1000');
layers = [
transposedConv2dLayer(4,256,"Name","transposed-conv_1","Cropping","same","Stride",[2 2], "BiasLearnRateFactor", 0)
%batchNormalizationLayer("Name","batchnorm_1")
reluLayer("Name","relu_1")
transposedConv2dLayer(4,256,"Name","transposed-conv_2","Cropping","same","Stride",[2 2],"BiasLearnRateFactor",0)
%batchNormalizationLayer("Name","batchnorm_2")
reluLayer("Name","relu_2")
transposedConv2dLayer(4,256,"Name","transposed-conv_3","Cropping","same","Stride",[2 2],"BiasLearnRateFactor",0)
%batchNormalizationLayer("Name","batchnorm_3")
reluLayer("Name","relu_3")
convolution2dLayer(1,numJoints,"Name","conv2d_final")
];
lgraph = addLayers(lgraph,layers);
lgraph = connectLayers(lgraph,'activation_49_relu','transposed-conv_1/in');
dlnet = dlnetwork(lgraph);
  1 Comment
가람 이
가람 이 on 13 Jun 2021
additional code is here
% Convert dlnetwork to SeriesNetwork
if ~doTraining
modelFile = "simplePoseNet";
else
simplePoseNet = layerGraph(dlnet);
simplePoseNet = replaceLayer(simplePoseNet,'data',...
imageInputLayer(inputSize,"Name","data","Normalization","zscore",...
"Mean",simplePoseNet.Layers(1).Mean,...
"StandardDeviation",simplePoseNet.Layers(1).StandardDeviation));
simplePoseNet = addLayers(simplePoseNet,regressionLayer("Name","RegressionLayer_conv15_fwd"));
simplePoseNet = connectLayers(simplePoseNet,'conv2d_final','RegressionLayer_conv15_fwd/in');
simplePoseNet = assembleNetwork(simplePoseNet);
SkeletonConnectionMap = skeleton;
save("simplePoseNet_"+postfix+"_final",'simplePoseNet','SkeletonConnectionMap');
modelFile = "simplePoseNet_"+postfix+"_final";
end

Sign in to comment.

Answers (1)

Anshika Chaurasia
Anshika Chaurasia on 16 Jun 2021
Hi,
The error is because the size of Mean array argument in imageInputLayer is not correct. Since you have changed the inputSize, the size of Mean array also needed to be changed.
The valid Mean array size are 256x192x3 array or 1x1x3 array of means per channel.
For the more information refer to properties section in imageInputLayer documentation.
Hope it helps!

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!