在tensorflow的tf.nn.softmax函数

时间:2018-06-10 04:25:32

标签: python tensorflow version invalid-argument

我有一个在1.2.1版本的tensorflow中完美运行但在1.7.0中生成InvalidArgumentError的脚本。
另外,只要从特定的softmax函数中删除'dim = 0',我就可以在1.7.0中运行脚本。

这适用于我在1.2中运行的脚本,但不适用于1.7:

a = tf.nn.softmax(tf.reshape(a, [3, 1]), dim=0)
b = tf.reduce_prod(1 - c * d, reduction_indices=1)

这是1.7中的追溯(指向上面以b开头的行):

Traceback (most recent call last):
  File "/home/usrnm/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1327, in _do_call
    return fn(*args)
  File "/home/usrnm/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1312, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "/home/usrnm/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1420, in _call_tf_sessionrun
    status, run_metadata)
  File "/home/usrnm/.local/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 516, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 10 values, but the requested shape has 40
  [[Node: gradients/Prod_grad/Reshape_2 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](gradients/Prod_grad/transpose, gradients/Prod_grad/Reshape_2/shape)]]
  [[Node: gradients/TopKV2_9_grad/Reshape_1/_1153 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_34185_gradients/TopKV2_9_grad/Reshape_1", tensor_type=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

当我从softmax中删除dim = 0时,脚本在1.2和1.7中运行

a = tf.nn.softmax(tf.reshape(a, [3, 1]))
b = tf.reduce_prod(1 - c * d, reduction_indices=1)

...但是,softmax将被用于最后一个无用的维度。

我不明白的是:1.2和1.7以及添加dim = 0之前和之后,我所有张量的形状都是相同的

例如 - 这是在1.7中设置dim = 0之前的形状:

a: Tensor("Softmax_87:0", shape=(3, 1), dtype=float32)
b: Tensor("Prod_29:0", shape=(10,), dtype=float32)
c: Tensor("Sigmoid_117:0", shape=(1, ?), dtype=float32)
d: Tensor("add_658:0", shape=(10, ?), dtype=float32)

之后:

a: Tensor("transpose_233:0", shape=(3, 1), dtype=float32)
b: Tensor("Prod_29:0", shape=(10,), dtype=float32)
c: Tensor("Sigmoid_117:0", shape=(1, ?), dtype=float32)
d: Tensor("add_658:0", shape=(10, ?), dtype=float32)

我尝试使用调试器,但目前stuck on an error正在使用它。

非常感谢任何线索。

0 个答案:

没有答案