getting error while making rcnn.mat file on my dataset

조회 수: 6 (최근 30일)
Rimsha Muzaffar
Rimsha Muzaffar 2023년 9월 14일
답변: T.Nikhil kumar 2024년 4월 12일 6:20
% Load the MAT file containing your ground truth data
annoDir =
'E:\MSCS\4th_sem\advance neural network\assignment\task4\dataset_root\R1.mat';
loadedData = load(annoDir);
% Extract the groundTruth object
gTruth = loadedData.gTruth;
% Continue with the rest of your code
baseNetwork = resnet50();
% Load pre-trained ResNet-50 network
% Resize input images to a fixed size (e.g., 224x224)
inputSize = [
224 224 3];
% Define additional R-CNN specific layers
layers = [
imageInputLayer(inputSize,
'Name', 'input')
convolution2dLayer(
64, 3, 'Padding', 'same', 'Name', 'conv1')
reluLayer(
'Name', 'relu1')
maxPooling2dLayer(
2, 'Stride', 2, 'Name', 'maxpool1')
fullyConnectedLayer(
128, 'Name', 'fc1')
reluLayer(
'Name', 'relu2')
fullyConnectedLayer(
2, 'Name', 'my_classification_layer')
softmaxLayer(
'Name', 'softmax')
classificationLayer(
'Name', 'my_output')
];
% Combine the base network with R-CNN layers
lgraph = layerGraph(baseNetwork);
lgraph = addLayers(lgraph, layers);
% Connect layers appropriately
lgraph = connectLayers(lgraph,
'maxpool1', 'fc1');
% Set training options
options = trainingOptions(
'sgdm', ...
'MiniBatchSize', 32, ...
'InitialLearnRate', 1e-6, ...
'MaxEpochs', 10);
% Train the R-CNN
rcnn = trainRCNNObjectDetector(gTruth, lgraph, options,
'NegativeOverlapRange', [0 0.3]);
% Save the trained R-CNN model to a MAT file
save(
'your_rcnn_model.mat', 'rcnn');
error
Error using nnet.cnn.LayerGraph/addLayers
Layer names in layer array must be different from the names of layers in layer graph.
Error in exmp_5 (line 29)
lgraph = addLayers(lgraph, layers);

답변 (1개)

T.Nikhil kumar
T.Nikhil kumar 2024년 4월 12일 6:20
Hello Rimsha,
I can see that you are facing an error with layer names while combining your base network with custom RCNN layers.
It seems that there is a conflict in layer names between the layers you're trying to add to the ‘layerGraph’ and the existing layers within the ‘baseNetwork’ (ResNet-50). It is because ResNet-50 already includes layers with names like 'input', 'conv1', 'relu1', and so on and when you attempt to add new layers with these same names to the ‘layerGraph’, an error is thrown due to the duplicate names.
To resolve the error, you need to ensure that the new layers you're adding have unique names that don't conflict with the existing layer names within the ‘baseNetwork’. You can use the following code snippet for the layers:
layers = [
imageInputLayer(inputSize, 'Name', 'input_rcnn')
convolution2dLayer(64, 3, 'Padding', 'same', 'Name', 'conv1_rcnn')
reluLayer('Name', 'relu1_rcnn')
maxPooling2dLayer(2, 'Stride', 2, 'Name', 'maxpool1_rcnn')
fullyConnectedLayer(128, 'Name', 'fc1_rcnn')
reluLayer('Name', 'relu2_rcnn')
fullyConnectedLayer(2, 'Name', 'my_classification_layer')
softmaxLayer('Name', 'softmax_rcnn')
classificationLayer('Name', 'my_output_rcnn')
];
Since the names have changed, you must also ensure that you are connecting the correct custom layers to the appropriate layer in the ‘baseNetwork’.
Hope this helps you resolve the error.

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by