Filter löschen
Filter löschen

continue training my YOLOv2 network from a previous training status

6 Ansichten (letzte 30 Tage)
I am working on a YOLOv2 project, and I am testing with training different inputs. Currently, my training started always from a "empty" initial status when I trained it with "[detector, info] = trainYOLOv2ObjectDetector(dsTrain,lgraph, opts);"
I want to continue training from the last status instead an initial status, e.g.,
In the 1st time, I trained the network for 5 Epoches, and I find the performance is not good. I want to increase the Training epcho number to 10. But I donot want to start it completely from initial status, but the previous stauts, in which 5 training Epoches was done. In this case, I have to only "continue" the training by 5 Epoches. My Training option Setting is as follows:
opts = trainingOptions("rmsprop",...
InitialLearnRate=0.001,...
MiniBatchSize=4,...
MaxEpochs=6,...
LearnRateSchedule="piecewise",...
LearnRateDropPeriod=5,...
VerboseFrequency=30, ...
L2Regularization=0.001,...
ValidationData=dsVal, ...
ValidationFrequency=50, ...
OutputNetwork="best-validation-loss", ...
Plots="training-progress");
Which setting should I change?

Akzeptierte Antwort

Sai Teja G
Sai Teja G am 24 Nov. 2023
Hi Tai,
I understand that you are looking for a way to increase the number of epochs for training a model which is already trained for certain epochs.
To continue training from where you left off, you can use the previously trained detector as the starting point for further training. When you train for the first time and get the `detector` object, you can use this object as an input to `trainYOLOv2ObjectDetector` for subsequent training sessions.
Here's what you need to do:
1. After your first training session, save the trained `detector` object to a file:
[detector, info] = trainYOLOv2ObjectDetector(dsTrain, lgraph, opts);
save('trainedDetector.mat', 'detector');
2. When you want to continue training, load the `detector` object from the file and use it as the network input to `trainYOLOv2ObjectDetector`. Also, adjust the `MaxEpochs` in your `trainingOptions` to account for the additional epochs you want to train for:
% Load the previously trained detector
load('trainedDetector.mat', 'detector');
% Adjust the training options for additional epochs
opts = trainingOptions("rmsprop",...
InitialLearnRate=0.001,...
MiniBatchSize=4,...
MaxEpochs=10, ... % Total epochs you want to train (including previous epochs)
LearnRateSchedule="piecewise",...
LearnRateDropPeriod=5,...
VerboseFrequency=30, ...
L2Regularization=0.001,...
ValidationData=dsVal, ...
ValidationFrequency=50, ...
OutputNetwork="best-validation-loss", ...
Plots="training-progress");
% Continue training
[detector, info] = trainYOLOv2ObjectDetector(dsTrain, detector.Network, opts);
In the code above, `MaxEpochs` is set to 10, which assumes that you want to train for a total of 10 epochs, including the 5 epochs you've already completed. The training will resume from the state saved in `detector.Network`.
Make sure to replace `'trainedDetector.mat'` with the actual path to your saved detector file.
By using the saved `detector` object, you're effectively continuing the training from the last saved state, which includes the learned weights and biases up to that point. This way, you don't have to train from scratch, and you can incrementally improve your model by training for additional epochs as needed.
Hope it helps!

Weitere Antworten (0)

Kategorien

Mehr zu Recognition, Object Detection, and Semantic Segmentation finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by