Save a trained neural network for Raspberry
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
David Duran
le 18 Jan 2022
Réponse apportée : Yazan
le 28 Sep 2022
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 commentaires
yanqi liu
le 18 Jan 2022
yes,sir,i think mat file include weight data,if use m file,may be only the layers structure
Réponse acceptée
Prince Kumar
le 20 Jan 2022
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.
Plus de réponses (1)
Yazan
le 28 Sep 2022
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 commentaires
Voir également
Catégories
En savoir plus sur Image Data Workflows dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!