简体   繁体   English

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

[英]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.

相关问题 / image / Tensor Tensor上的ValueError(“activation_5 / Softmax:0”,shape =(?,4),dtype = float32)不是此图的元素 - ValueError at /image/ Tensor Tensor(“activation_5/Softmax:0”, shape=(?, 4), dtype=float32) is not an element of this graph ValueError: Tensor(&quot;ExponentialDecay_4:0&quot;, shape=(), dtype=float32) - ValueError: Tensor("ExponentialDecay_4:0", shape=(), dtype=float32) python - ValueError: Tensor Tensor(&quot;dense_2/Softmax:0&quot;, shape=(?, 43), dtype=float32) 不是这个图的一个元素 - python - ValueError: Tensor Tensor("dense_2/Softmax:0", shape=(?, 43), dtype=float32) is not an element of this graph ValueError: Tensor Tensor(&quot;mrcnn_detection/Reshape_1:0&quot;, shape=(1, 100, 6), dtype=float32) 不是这个图的一个元素 - ValueError: Tensor Tensor("mrcnn_detection/Reshape_1:0", shape=(1, 100, 6), dtype=float32) is not an element of this graph AssertionError:无法计算 output 张量(“softmax_layer/Identity:0”,shape=(None, 27, 8870),dtype=float32) - AssertionError: Could not compute output Tensor(“softmax_layer/Identity:0”, shape=(None, 27, 8870), dtype=float32) ValueError:Tensor(“ BN_1 / moments / Squeeze:0”,shape =(32,256,32),dtype = float32)必须与Tensor来自同一图 - ValueError: Tensor(“BN_1/moments/Squeeze:0”, shape=(32, 256, 32), dtype=float32) must be from the same graph as Tensor 错误:断言错误:无法计算输出张量(“dense_2/truediv:0”,形状=(无,无,1),dtype=float32) - Error: AssertionError: Could not compute output Tensor(“dense_2/truediv:0”, shape=(None, None, 1), dtype=float32) AssertionError:无法计算 output 张量(“dense_17/Sigmoid:0”,shape=(None,1),dtype=float32) - AssertionError: Could not compute output Tensor(“dense_17/Sigmoid:0”, shape=(None, 1), dtype=float32) 警告:tensorflow:模型是用形状 (20, 37, 42) 构建的,用于输入 Tensor(“input_5:0”, shape=(20, 37, 42), dtype=float32),但是 - WARNING:tensorflow:Model was constructed with shape (20, 37, 42) for input Tensor(“input_5:0”, shape=(20, 37, 42), dtype=float32), but Tensor Tensor(&quot;predictions/Softmax:0&quot;, shape=(?, 1000), dtype=float32) 不是这个图的元素 - Tensor Tensor("predictions/Softmax:0", shape=(?, 1000), dtype=float32) is not an element of this graph
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM