Command: "exportONNXNetwork" doesn't seem to work properly.
5 views (last 30 days)
Show older comments
I am working on a machine learning project using a Faster RCNN network (specifically ResNet-50). I used the image annotation tool to annotate the photos to be used with the model, and the training of the model seems to have gone rather well. I need to export the trained model to a format compatiable with TensorFlow, but the two commands I have been using: "exportNetworkToTensorFlow" and "exportONNXNetwork" do not seem to be working propely. Any help would be appreciated!
The "exportNetworkToTensorFlow" command yields this (the app is installed):
>> net = BridRCNN.Network;
>> exportNetworkToTensorFlow(net, "myModel")
Unrecognized function or variable 'exportNetworkToTensorFlow'.
The "exportONNXNetwork" command yields this:
>> net = BridRCNN.Network;
>> exportONNXNetwork(net,"testModel.onnx")
Warning: ONNX does not support layer 'nnet.cnn.layer.RegionProposalLayer'. Exporting to ONNX operator 'com.MathWorks.Placeholder'.
> In nnet.internal.cnn.onnx/NNTLayerConverter/makeLayerConverter (line 276)
In nnet.internal.cnn.onnx/ConverterForNetwork/networkToGraphProto (line 112)
In nnet.internal.cnn.onnx/ConverterForNetwork/toOnnx (line 45)
In nnet.internal.cnn.onnx.exportONNXNetwork (line 17)
In exportONNXNetwork (line 38)
Error using warning
Error filling holes for nnet_cnn_onnx:onnx:ROIMaxPooling2DLayerScalesUnequal. Floating point numbers are not allowed as holes. They should be converted to character vectors.
Error in nnet.internal.cnn.onnx.ConverterForROIMaxPooling2DLayer/toOnnx (line 23)
warning(message('nnet_cnn_onnx:onnx:ROIMaxPooling2DLayerScalesUnequal', ...
Error in nnet.internal.cnn.onnx.ConverterForNetwork/networkToGraphProto (line 115)
= toOnnx(layerConverter, nodeProtos, TensorNameMap, TensorLayoutMap);
Error in nnet.internal.cnn.onnx.ConverterForNetwork/toOnnx (line 45)
modelProto.graph = networkToGraphProto(this);
Error in nnet.internal.cnn.onnx.exportONNXNetwork (line 17)
modelProto = toOnnx(converter);
Error in exportONNXNetwork (line 38)
nnet.internal.cnn.onnx.exportONNXNetwork(Network, filename, varargin{:});
It seems to me like there is a value that is stored as a floating point number instead of a character. I am not sure how to fix it, however.
This is the code I used to train the model:
%% Gather Relavent Image Labeller Data
data = load('MRO135Labels.mat');
%% Transform Truth Table into Usable Table
[imds,blds] = objectDetectorTrainingData(data.gTruth);
%% Combine Datastores
ds = combine(imds,blds);
%% Set up the Network Layers
inputImageSize = [400 600 3];
numClasses = 11;
network = 'resnet50';
featureLayer = 'activation_40_relu';
%% Anchor Boxes
numAnchors = 5;
anchorBoxes = estimateAnchorBoxes(blds,numAnchors);
%% Finally Constructing the Model
%lgraph = layerGraph(inputImageSize, numClasses, anchorBoxes, network, featureLayer);
lgraph = fasterRCNNLayers(inputImageSize, numClasses, anchorBoxes, network, featureLayer);
%% Configure Traininig Options
options = trainingOptions('sgdm', ...
'MiniBatchSize', 1, ...
'InitialLearnRate', 1e-3, ...
'MaxEpochs', 7, ...
'VerboseFrequency', 15, ...
'CheckpointPath', tempdir);
%% Train Detector
detector = trainFasterRCNNObjectDetector(ds, lgraph, options, ...
'NegativeOverlapRange',[0 0.3], ...
'PositiveOverlapRange',[0.6 1]);
%% Test Detector
img = imread('MRO135.jpg');
[bbox, score, label] = detect(detector, img);
%% Display Detection Results
detectedImg = insertShape(img,'Rectangle',bbox);
figure
imshow(detectedImg)
%% Save Model
BridRCNN = detector;
save BridRCNN
0 Comments
Answers (1)
Sivylla Paraskevopoulou
on 2 Dec 2022
Which MATLAB version are you using? The exportNetworkToTensorFlow function was introduced in R2022b.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!