How to fix the error in PPO rlwatertank : Model input sizes must match the dimensions specified in the corresponding observation and action info specifications.

5 visualizzazioni (ultimi 30 giorni)
open_system('rlwatertank')
obsInfo = rlNumericSpec([3 1],'LowerLimit',[-inf -inf 0 ]','UpperLimit',[ inf inf inf]');
obsInfo.Name = 'observations';
obsInfo.Description = 'integrated error, error, and measured height';
numObs = obsInfo.Dimension(1);
actInfo = rlNumericSpec([1 1],'LowerLimit',-10','UpperLimit',10);
actInfo.Name = 'Action';
numAct = actInfo.Dimension(1);
env = rlSimulinkEnv('rlwatertank','rlwatertank/RL Agent',...
obsInfo,actInfo);
env.ResetFcn = @(in)localResetFcn(in);
Ts = 1.0;
Tf = 200;
rng(0)
criticNet = [
imageInputLayer([obsInfo.Dimension 1],'Normalization','none','Name','observations')
fullyConnectedLayer(10,'Name', 'fc_in')
reluLayer('Name', 'relu')
fullyConnectedLayer(1,'Name','out')];
% set some training options for the critic
criticOpts = rlRepresentationOptions('LearnRate',8e-3,'GradientThreshold',1);
% create the critic representation from the network
critic = rlValueRepresentation(criticNet,obsInfo,'Observation',{'observations'},criticOpts);
%actor
inPath = [ imageInputLayer([6 1 1], 'Normalization','none','Name','observations')
fullyConnectedLayer(2,'Name','infc') ]; % 2 by 1 output
% path layers for mean value (2 by 1 input and 2 by 1 output)
% using scalingLayer to scale the range
meanPath = [ tanhLayer('Name','tanh'); % output range: (-1,1)
scalingLayer('Name','scale','Scale',actInfo.UpperLimit) ]; % output range: (-10,10)
% path layers for standard deviations (2 by 1 input and output)
% using softplus layer to make it non negative
sdevPath = softplusLayer('Name', 'splus');
% conctatenate two inputs (along dimension #3) to form a single (4 by 1) output layer
outLayer = concatenationLayer(3,2,'Name','mean&sdev');
% add layers to network object
net = layerGraph(inPath);
net = addLayers(net,meanPath);
net = addLayers(net,sdevPath);
net = addLayers(net,outLayer);
% connect layers: the mean value path output MUST be connected to the FIRST input of the concatenationLayer
net = connectLayers(net,'infc','tanh/in'); % connect output of inPath to meanPath input
net = connectLayers(net,'infc','splus/in'); % connect output of inPath to sdevPath input
net = connectLayers(net,'scale','mean&sdev/in1'); % connect output of meanPath to gaussPars input #1
net = connectLayers(net,'splus','mean&sdev/in2'); % connect output of sdevPath to gaussPars input #2
% plot network
plot(net)
actorOpts = rlRepresentationOptions('LearnRate',8e-3,'GradientThreshold',1);
% create the actor using the network
Actor = rlStochasticActorRepresentation(net,obsInfo,actInfo,...
'Observation','observations',actorOpts);
agentOpts = rlPPOAgentOptions(...
'SampleTime',Ts,...
'DiscountFactor',1.0, ...
'MiniBatchSize',64);
agent = rlPPOAgent(actor,critic,agentOpts);
maxepisodes = 5000;
maxsteps = ceil(Tf/Ts);
trainOpts = rlTrainingOptions(...
'MaxEpisodes',maxepisodes, ...
'MaxStepsPerEpisode',maxsteps, ...
'ScoreAveragingWindowLength',20, ...
'Verbose',false, ...
'Plots','training-progress',...
'StopTrainingCriteria','AverageReward',...
'StopTrainingValue',800);
doTraining = true;
if doTraining
% Train the agent.
trainingStats = train(agent,env,trainOpts);
else
% Load the pretrained agent for the example.
load('WaterTankDDPG.mat','agent')
end
simOpts = rlSimulationOptions('MaxSteps',maxsteps,'StopOnError','on');
experiences = sim(env,agent,simOpts);
function in = localResetFcn(in)
% randomize reference signal
blk = sprintf('rlwatertank/Desired \nWater Level');
h = 3*randn + 10;
while h <= 0 || h >= 20
h = 3*randn + 10;
end
in = setBlockParameter(in,blk,'Value',num2str(h));
% randomize initial height
h = 3*randn + 10;
while h <= 0 || h >= 20
h = 3*randn + 10;
end
blk = 'rlwatertank/Water-Tank System/H';
in = setBlockParameter(in,blk,'InitialCondition',num2str(h));
end
i've error like this, ho to fix it?
Error using rl.representation.rlAbstractRepresentation/validateModelInputDimension (line 557)
Model input sizes must match the dimensions specified in the corresponding observation and action info specifications.
Error in rl.representation.rlAbstractActorRepresentation (line 38)
validateModelInputDimension(this)
Error in rl.representation.rlStochasticActorRepresentation (line 18)
this = this@rl.representation.rlAbstractActorRepresentation(Model, ObservationInfo, ActionInfo, Options);
Error in rlStochasticActorRepresentation (line 139)
Rep = rl.representation.rlStochasticActorRepresentation(...
Error in kodinganrlwatertankfixxxxxx (line 67)
Actor = rlStochasticActorRepresentation(net,obsInfo,actInfo,...
>>

Risposte (0)

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by