AI4Finance-Foundation / AI4Finance-Foundation/FinRL-Tutorials

Error in FinRL_PortfolioAllocation_Explainable_DRL

未关闭
#39 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
Jupyter Notebook
星标
1.2k
派生
435
PR 合并指标
30 天内没有已合并 PR

描述

Hello
I add deep network to code and code have error. can you help me?
thanks.
part of code:
```
class Net(BaseFeaturesExtractor):
def __init__(self, observation_space: gym.spaces.Box, stock_dim: int = 28):
super(Net, self).__init__(observation_space, stock_dim)
self.conv1 = nn.Conv2d(1, 32, kernel_size=3)
self.conv2 = nn.Conv2d(32, 64, kernel_size=3)
self.fc3 = nn.Linear(672,stock_dim)
`

def forward(self, x):
x = F.relu(self.conv1(x))
x = F.relu(self.conv2(x))
x = nn.Flatten()(x)
# x = x.view(x.size(0), -1)
x = F.relu(self.fc3(x))
return x
policy_kwargs ={
'features_extractor_class':Net,
}
model = PPO("MlpPolicy", env= env_train, policy_kwargs=policy_kwargs)
model.learn(total_timesteps=100000)
```
Error:

ValueError Traceback (most recent call last)
[](https://localhost:8080/#) in
----> 1 model.learn(total_timesteps=100000)

3 frames
[/usr/local/lib/python3.8/dist-packages/stable_baselines3/common/buffers.py](https://localhost:8080/#) in add(self, obs, action, reward, episode_start, value, log_prob)
435
436 # Same reshape, for actions
--> 437 action = action.reshape((self.n_envs, self.action_dim))
438
439 self.observations[self.pos] = np.array(obs).copy()

ValueError: cannot reshape array of size 1792 into shape (1,28)

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。