TensorFlow-“split”Op的输入“split_dim”的float32类型与预期的int32类型不匹配

2024-09-25 08:36:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我在ubuntu 16.04lts上用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.

Tags: nameinpybytestensorflowlinetrainfile
2条回答

因为参数顺序已经改变了

你可以在这里看到问题:https://github.com/tensorflow/tensorflow/issues/6501

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

这是因为在Tensorflow版本<;0.12.0中,split函数将参数作为:

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

相关问题 更多 >