【问题标题】:TensorFlow - Input 'split_dim' of 'Split' Op has type float32 that does not match expected type of int32TensorFlow - 'Split' Op 的输入'split_dim' 的 float32 类型与预期的 int32 类型不匹配
【发布时间】:2018-01-09 02:07:17
【问题描述】:

我在 ubuntu 16.04 LTS 上使用 pip 安装了 tensorflow,在运行此代码 https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/recurrent_network.py 时出现此错误

Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes. 
Extracting /tmp/data/train-images-idx3-ubyte.gz 
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes. Extracting /tmp/data/train-labels-idx1-ubyte.gz 
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes. 
Extracting /tmp/data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes. 
Extracting /tmp/data/t10k-labels-idx1-ubyte.gz 
Traceback (most recent call last): 
    File "deep.py", line 71, in <module>
        pred = RNN(x, weights, biases)   
    File "deep.py", line 60, in RNN
        x = tf.split(x, n_steps, 0)   
    File "/home/newuser/.local/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1234, in split
        name=name)   
    File "/home/newuser/.local/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 3241, in _split
    num_split=num_split, name=name)   
    File "/home/newuser/.local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 508, in apply_op
    (prefix, dtypes.as_dtype(input_arg.type).name)) 
TypeError: Input 'split_dim' of 'Split' Op has type float32 that does not match expected type of int32.

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    您使用的是较旧版本的 Tensorflow,需要更新到 Tensorflow v0.12.0 或更高版本。您收到的错误表明您的 tf.split 函数中的 split_dim 值需要一个整数,但正在接收 float32 类型的张量 x

    这是因为在 Tensorflow 版本

    x = tf.split(0, n_steps, x) # tf.split(axis, num_or_size_splits, value)
    

    您正在使用的教程是为 > 0.12.0 版本编写的,该版本已更改为与 Numpy 的拆分语法一致:

    x = tf.split(x, n_steps, 0) # tf.split(value, num_or_size_splits, axis)
    

    查看更新日志了解详情: https://github.com/tensorflow/tensorflow/blob/64edd34ce69b4a8033af5d217cb8894105297d8a/RELEASE.md

    【讨论】:

    • 您好 alphaleonis,我使用的是 Tensorflow 0.12.0-rc0,但它仍然有这种错误消息。
    • 是的,Tensorflow 0.12.0-rc0 和 0.12.0-rc1 是仍包含旧语法的预发布版本。新的语法更改直到 v0.12.0 才生效。您可以在此处查看更改何时提交到官方存储库:github.com/tensorflow/tensorflow/commit/…
    【解决方案2】:

    是因为参数顺序变了

    您可以在此处查看问题:https://github.com/tensorflow/tensorflow/issues/6501

    【讨论】:

    • 欢迎来到 Stack Overflow!虽然这在理论上可以回答这个问题,it would be preferable 在此处包含答案的基本部分,并提供链接以供参考。换句话说,解决方案是什么?
    • 您可以查看此链接(在上面的链接中引用了该链接):github.com/tensorflow/tensorflow/blob/…。您需要做的就是以不同的顺序编写参数。像这样: tf.split(value, num_or_size_splits, axis)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-14
    • 1970-01-01
    • 2020-10-04
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    相关资源
    最近更新 更多