Save a trained neural network for Raspberry
10 次查看(过去 30 天)
显示 更早的评论
I have loaded AlexNet and retrained the neural network using my own images. When I run the script it it does everything properly and trains the NN properly. The new trained NN is saved to the workspace as myNet as as a .mat file. I was wondering if it's possible to save it as an .M file so I can deploy it to a Raspberry PI 4.
clc;
clear all;
close all;
alex = alexnet; % Load Neural Network AlexNet
layers = alex.Layers; %Identify Layers in Alexnet
layers(23) = fullyConnectedLayer(6); %Six Unique Images will be identified at Layer 23
layers(25) = classificationLayer %Layer 25 is the Classification Layer and properly identifies the object
allImages = imageDatastore('robot','IncludeSubfolders', true, 'LabelSource', 'foldernames'); % Identifies the images that are stored are the computer and the labels associated with them
[trainingImages, testImages] = splitEachLabel(allImages, 0.8, 'randomized'); % seperates the files into different groups for training and validation. (80% for training and 20% for validation)
opts = trainingOptions("sgdm", 'InitialLearnRate', 0.001, 'MaxEpochs', 5, 'MiniBatchSize', 64, 'Plots','training-progress'); % Different options for training the Neural Network
myNet = trainNetwork(trainingImages, layers,opts); %Will save the trained network based off AlexNet as myNet
predictedLabels = classify(myNet, testImages); % This will identify images using the trained network by using the validation images
accuracy = mean(predictedLabels ==testImages.Labels) % This will display a percentage of how accurate the model is at identifying the images.
camera = webcam; % Connect to the camera
while true
picture = camera.snapshot; % Take a picture using connected Camera
picture = imresize(picture,[227,227]); % Resize the picture to 277x277 Pixel size
label = classify(myNet, picture); % Classify the picture
image(picture); % Displays the picture
title(char(label)); % Shows the label above the picture
drawnow; % Continuously updates image from Webcam
end
2 个评论
yanqi liu
2022-1-18
yes,sir,i think mat file include weight data,if use m file,may be only the layers structure
采纳的回答
Prince Kumar
2022-1-20
Hi,
Please look at the following MATLAB answers:
- https://www.mathworks.com/matlabcentral/answers/1621010-how-to-deploy-custom-deep-learning-model-in-raspberry-pi-4
- https://www.mathworks.com/matlabcentral/answers/487789-deploy-deep-nueral-network-to-raspberry-pi?s_tid=answers_rc1-1_p1_Topic
Hope this helps.
更多回答(1 个)
Yazan
2022-9-28
I have the same problem; did you find a solution.
Can you share your solution please, I have another question, how did you manage to turn your Matlab code into a function?
Thank you
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!