微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ValueError:模型输出“Tensor(“activation_1/Identity:0”, shape=(?, 3), dtype=float32)”的形状无效

如何解决ValueError:模型输出“Tensor(“activation_1/Identity:0”, shape=(?, 3), dtype=float32)”的形状无效

我正在尝试运行以下 github 代码进行股市预测:

https://github.com/multidqn/deep-q-trading

使用他们的说明,我在安装所需的库后运行以下命令:

python main.py 3 0 results_folder

但是,当我运行上述命令时,出现以下错误

Using TensorFlow backend.
WARNING:tensorflow:From /Users/anisschohra/.local/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py:68: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

WARNING:tensorflow:From /Users/anisschohra/.local/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py:508: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

WARNING:tensorflow:From /Users/anisschohra/.local/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py:3837: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

Traceback (most recent call last):
  File "main.py",line 92,in <module>
    ensembleFolderName=sys.argv[3]
  File "/Users/anisschohra/deep-q-Trading/deepQTrading.py",line 68,in __init__
    enable_double_dqn=True,enable_dueling_network=True)
  File "/Users/anisschohra/.local/lib/python3.7/site-packages/rl/agents/dqn.py",line 107,in __init__
    raise ValueError(f'Model output "{model.output}" has invalid shape. DQN expects a model that has one dimension for each action,in this case {self.nb_actions}.')
ValueError: Model output "Tensor("activation_1/Identity:0",shape=(?,3),dtype=float32)" has invalid shape. DQN expects a model that has one dimension for each action,in this case 3.

您能帮我解决问题并成功运行代码吗?我一直在寻找错误,但没有找到有效的解决方案。他们的代码(main.py)中的模型架构如下:

model = Sequential()
model.add(Flatten(input_shape=(1,1,68)))
model.add(Dense(35,activation='linear'))
model.add(LeakyReLU(alpha=.001))
model.add(Dense(nb_actions))
model.add(Activation('linear'))

提前致谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。