ElegantRL
ElegantRL copied to clipboard
AttributeError: 'AgentPPO' object has no attribute 'ClassCri'
While Running the last command on eRL_demo_StockTrading.ipynb on colab
args.init_before_training(if_main=False)
args.env.draw_cumulative_return(args, torch)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-18-c641199acf36> in <module>()
----> 1 args.env.draw_cumulative_return(args, torch)
2 frames
/usr/local/lib/python3.7/dist-packages/elegantrl/envs/FinRL/StockTrading.py in draw_cumulative_return(self, args, _torch)
240 cwd = args.cwd
241
--> 242 agent.init(net_dim, state_dim, action_dim)
243 agent.save_load_model(cwd=cwd, if_save=False)
244 act = agent.act
/usr/local/lib/python3.7/dist-packages/elegantrl/agent.py in init(self, net_dim, state_dim, action_dim, learning_rate, if_use_gae, env_num, agent_id)
617
618 def init(self, net_dim, state_dim, action_dim, learning_rate=1e-4, if_use_gae=False, env_num=1, agent_id=0):
--> 619 super().init(net_dim, state_dim, action_dim, learning_rate, if_use_gae, env_num, agent_id)
620 self.traj_list = [list() for _ in range(env_num)]
621
/usr/local/lib/python3.7/dist-packages/elegantrl/agent.py in init(self, net_dim, state_dim, action_dim, learning_rate, if_per_or_gae, env_num, agent_id)
52 self.device = torch.device(f"cuda:{agent_id}" if (torch.cuda.is_available() and (agent_id >= 0)) else "cpu")
53
---> 54 self.cri = self.ClassCri(int(net_dim * 1.25), state_dim, action_dim).to(self.device)
55 self.act = self.ClassAct(net_dim, state_dim, action_dim).to(self.device) if self.ClassAct else self.cri
56 self.cri_target = deepcopy(self.cri) if self.if_use_cri_target else self.cri
AttributeError: 'AgentPPO' object has no attribute 'ClassCri'
But I am able to see that AgentPPO has ClassCri with CriticAdv
class AgentPPO(AgentBase):
def __init__(self):
super().__init__()
self.ClassAct = ActorPPO
self.ClassCri = CriticAdv
Actual Issue -
Attachments
I know how to fix this bug.
You code:
class AgentPPO(AgentBase):
def __init__(self):
super().__init__()
self.ClassAct = ActorPPO
self.ClassCri = CriticAdv
should be
class AgentPPO(AgentBase):
def __init__(self):
self.ClassAct = ActorPPO
self.ClassCri = CriticAdv
super().__init__() ###################### write before self.ClassCri = CriticAdv