Clear Filters
Clear Filters

Change 'yolov4ObjectDetector' from read-only settings.

8 views (last 30 days)
Hey.
I am trying to use the yolov4ObjectDetector to complement my Network but I am struggling with one error regarding the name of the ouput layer. However, when I try to replace the layer with an equivalent layer but with the appropriate name I receive the following error:
Unable to set the 'Network' property of class 'yolov4ObjectDetector' because it is read-only.
Error in main (line 57)
detector.Network = replaceLayer(detector.Network,'customOutputConv1',newoutput);
Do you know if it is possible to change this read-only settings?

Accepted Answer

Ayush Anand
Ayush Anand on 10 Jan 2024
Hi Rodrigo,
In MATLAB, the "Network" property of the "yolov4ObjectDetector" is read-only, which means you cannot directly modify it after the object is created. This is to ensure the integrity of the pre-trained networks and their associated properties.
If you want to modify the network architecture, such as replacing a layer with a different one, you should do this before creating the "yolov4ObjectDetector" object. You would typically modify the layers of the deep learning network and then create the object detector with the modified network.
Here's a general approach on how you could do the same:
% Load the pre-trained YOLOv4 network
net = load('yolov4Network.mat'); % Replace with your network source
lgraph = layerGraph(net);
% Replace the layer with the new layer with the correct name
newLayer = convolution2dLayer([1, 1], numFilters, 'Name', 'newOutputLayerName', 'WeightLearnRateFactor',1, 'BiasLearnRateFactor',1);
lgraph = replaceLayer(lgraph, 'customOutputConv1', newLayer);
% Create the yolov4ObjectDetector with the modified network
detector = yolov4ObjectDetector(lgraph, anchorBoxes, classNames);`
You can refer to the following link to read more on the "replaceLayer" function:
I hope this helps!
  1 Comment
Rodrigo
Rodrigo on 11 Jan 2024
Hello, Ayush.
Thank you so much for the reply. I ended up generating the network code of yolov4ObjectDetector using the Deep Network Designer, so now I can manipulate the output layers since there were some changes I needed to do for my application.
Thanks for the help :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!