[英]ValueError: Model output "Tensor("activation_1/Identity:0", shape=(?, 3), dtype=float32)" has invalid shape
I am trying to run the following github code for stock market prediction:我正在尝试运行以下 github 代码进行股市预测:
https://github.com/multidqn/deep-q-trading https://github.com/multidqn/deep-q-trading
using their instructions, I run the following after installing the required libraries:使用他们的说明,我在安装所需的库后运行以下命令:
python main.py 3 0 results_folder
However, when I run the above command, I get the following error:但是,当我运行上述命令时,出现以下错误:
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.
Could you please help me fix the issue and run the code successfully?你能帮我解决问题并成功运行代码吗? I have looked for the error but did not find a solution that works.
我一直在寻找错误,但没有找到有效的解决方案。 The model architecture in their code (main.py) is as follows:
他们的代码(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'))
Thanks in advance.提前致谢。
I have the same problem with you, and I`m not so familiar with RL but I guess I reached the cause.我和你有同样的问题,我对 RL 不太熟悉,但我想我已经找到了原因。
if list(model.output.shape) != list((None, self.nb_actions)):
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}.')
According to the traceback, this is the code which causes the problem.根据回溯,这是导致问题的代码。 Your model`s output shape is a tensor object, so list(model.output.shape) will be like [Dimension(None), Dimension(3)], but list((None, self.nb_actions)) is [None, 3], so it will be judged as different.
您的模型的输出形状是一个张量对象,因此 list(model.output.shape) 将类似于 [Dimension(None), Dimension(3)],但 list((None, self.nb_actions)) 是 [None, 3],所以会被判断为不同。
So I think if there is a way that can convert shape of the model`s output to numpy or list object we can solve this problem.所以我认为如果有一种方法可以将模型输出的形状转换为 numpy 或列表对象,我们可以解决这个问题。 Sorry for my poor English!
对不起我糟糕的英语!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.