How to save and use the pre-trained DQN agent in the reinforcement learning tool box

13 次查看(过去 30 天)
I would like to use the DQN agent pre-trained in the following neural network to solve other problems. How can I save the pre-trained DQN agent. Also, how can I use this trained agent to solve other problems.
lgraph = layerGraph();
tempLayers = [
imageInputLayer([1 1 1],"Name","Block Actions","Normalization","none")
fullyConnectedLayer(50,"Name","fc_2")
reluLayer("Name","relu_2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
imageInputLayer([20 1 1],"Name","Block Observations","Normalization","none")
scalingLayer("Name","scaling","Scale",12)
fullyConnectedLayer(50,"Name","fc_1")
reluLayer("Name","relu_1")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
additionLayer(2,"Name","addition")
fullyConnectedLayer(10,"Name","fc_3")
reluLayer("Name","relu_3")
fullyConnectedLayer(1,"Name","stateValue")];
lgraph = addLayers(lgraph,tempLayers);

回答(1 个)

Emmanouil Tzorakoleftherakis
Hello,
Take a look at this example, and specifically the code snippet below:
if doTraining
% Train the agent.
trainingStats = train(agent,env,trainOpts);
% Save the agent
save myagent.mat agent
else
% Load the pretrained agent for the example.
load('MATLABCartpoleDQNMulti.mat','agent')
end
  3 个评论
Maha Mosalam
Maha Mosalam 2022-3-22
So when I use the pretrained agent after that to get actions, I should defined the whole algorithm , I mean(the environment action space , actor and critic layers , expect the trainig line , just
use load(myagent.mat, agent)
Maha Mosalam
Maha Mosalam 2022-3-23
Warning: Cannot load an object of class 'rlDLNetworkModel':
Its class cannot be found.
Warning: Cannot load an object of class 'rlADAMOptimizer':
Its class cannot be found.
Warning: While loading an object of class 'rl.representation.rlQValueRepresentation':
Undefined function 'getLoss' for input arguments of type 'double'.
Warning: Cannot load an object of class 'rlDLNetworkModel':
Its class cannot be found.
.....
I got these mesege when just
load(myagent.mat, agent)
then get action from that, not redefined the actor and critic, and environment

请先登录,再进行评论。

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by