load agent
actor = getActor(saved_agent);
actorNetwork = getNetworkFromRepresentation(actor);
newActorNetwork = actorNetwork;
for ct = 1:numel(newActorNetwork.Layers)
if isa(newActorNetwork.Layers(ct),'rl.layer.ScalingLayer')
newLayer = nnet.onnx.layer.ElementwiseAffineLayer(...
newActorNetwork.Layers(ct).Name,...
newActorNetwork.Layers(ct).Scale,...
newActorNetwork.Layers(ct).Bias);
newActorNetwork = replaceLayer(newActorNetwork,newActorNetwork.Layers(ct).Name,newLayer);
end
end
actionLayerName = newActorNetwork.Layers(end).Name;
observationLayerName = newActorNetwork.Layers(1).Name;
actionInfo = actor.ActionInfo;
observationInfo = actor.ObservationInfo;
newActor = rlRepresentation(newActorNetwork,observationInfo,actionInfo,...
'Observation',observationLayerName,'Action',actionLayerName,actor.Options);
saved_agent = setActor(saved_agent,newActor);
generatePolicyFunction(saved_agent)
cfg = coder.gpuConfig('mex');
cfg.TargetLang = 'C++';
cfg.GpuConfig.Enabled = true;
cfg.DeepLearningConfig = coder.DeepLearningConfig('cudnn');
argstr = '{ones(4,1)}';
codegen('-config','cfg','evaluatePolicy','-args',argstr,'-report');
Best Answer