Error using ("Weights","none") for pretrained networks

조회 수: 1 (최근 30일)
Eirik Furuholt
Eirik Furuholt 2021년 5월 1일
편집: Yomna Genina 2021년 5월 5일
Hi all,
When i run this code:
lgraph = googlenet("Weights","none");
detectorGooglenet= trainFastRCNNObjectDetector(trainingDataTable,lgraph,options)
these errors return:
Invalid network.
Caused by:
Network: The network must contain one ROI input layer. See the documentation for more details about creating Fast R-CNN networks.
Network: The network must contain one R-CNN box regression layer. See the documentation for more details about creating Fast R-CNN networks.
Network: The network must contain one ROI max pooling layer. See the documentation for more details about creating Fast or Faster R-CNN networks.
Layer 'output': The input size must be 1×1×3. The classification layer expects the third input dimension to be the number of object classes the network should to detect (2 classes) plus 1. The additional class is required for the "background" class. See the documentation for more details about creating Fast or Faster R-CNN networks.
When i run this code i get no erros.
lgraph = googlenet("Weights","none");
detectorGooglenet= trainFastRCNNObjectDetector(trainingDataTable,'googlenet',options)
I dont know whats wrong, and the cloud cumputer i run this on dosent have the support package for the pretrained network. Can anyone explain the diffrence in the networks and why it appears that some layers suddenly are "missing"? and dose anyone know of a solution to the problem so i can run the first code example?
Thanks for reading!

채택된 답변

Yomna Genina
Yomna Genina 2021년 5월 5일
편집: Yomna Genina 2021년 5월 5일
trainFastRCNNObjectDetector requires the input lgraph to be a valid Fast R-CNN network, that's why it errors when a GoogLeNet network is passed in, as it's not a Fast R-CNN network.
However trainFastRCNNObjectDetector can convert a pretrained network into a Fast R-CNN network if you pass in the name of the pretrained network as a string, in this case, "googlenet". This is why the second call you showed runs without errors.
If you are unable to install the GoogLeNet support package then you would need to manually convert it into a valid Fast R-CNN network before passing it in to trainFastRCNNObjectDetector.
Here's an example of creating a Fast R-CNN network using GoogLeNet as its backbone.
lgraph = googlenet("Weights", "none");
Replace classification layers
numClasses = 1; % Change this to your number of classes
newFCLayer = fullyConnectedLayer(numClasses + 1);
lgraph = replaceLayer(lgraph, 'loss3-classifier', newFCLayer);
newClsLayer = classificationLayer();
newSoftmax = softmaxLayer();
lgraph = replaceLayer(lgraph, 'prob', newSoftmax);
lgraph = replaceLayer(lgraph, 'output', newClsLayer);
Add regression layers
regLayers = [fullyConnectedLayer(4 * (numClasses), 'Name',"fcBoxDeltas",...
'WeightLearnRateFactor', 1, ...
'BiasLearnRateFactor', 2, ...
'WeightL2Factor', 1,...
'BiasL2Factor', 0),...
rcnnBoxRegressionLayer('Name', "boxDeltas")];
lgraph = addLayers(lgraph, regLayers);
lgraph = connectLayers(lgraph, "pool5-drop_7x7_s1", "fcBoxDeltas");
Add ROI Pooling
outLayers = ["inception_4e-1x1","inception_4e-3x3_reduce","inception_4e-5x5_reduce","inception_4e-pool"];
for i = 1:numel(outLayers)
lgraph = disconnectLayers(lgraph, 'inception_4d-output', outLayers{i});
end
roiPooling = roiMaxPooling2dLayer([14 14], "Name", "roiPooling");
lgraph = addLayers(lgraph, roiPooling);
% Connect feature layer to the ROI pooling layer
lgraph = connectLayers(lgraph, 'inception_4d-output', "roiPooling" + "/in");
for i = 1:numel(outLayers)
% Connect ROI Pooling layer to disconnected layers.
lgraph = lconnectLayers(lgraph, "roiPooling", outLayers{i});
end
% Add ROI input layer and connect to ROI pooling layer.
roiInput = roiInputLayer('Name',"roiInput");
lgraph = addLayers(lgraph, roiInput);
lgraph = connectLayers(lgraph, "roiInput", "roiPooling" + '/roi');
View the Fast R-CNN network architecture
analyzeNetwork(lgraph);
See this example on creating an R-CNN network using ResNet-50 and this documentation page for more information about designing Fast R-CNN networks. It's worth noting that converting a pretrained network into a Fast R-CNN can be done more easily using Deep Network Designer.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by