Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 views
in Technique[技术] by (71.8m points)

python - TensorFlow - Input 'split_dim' of 'Split' Op has type float32 that does not match expected type of int32

I've installed tensorflow using pip on ubuntu 16.04 LTS, when running this code https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/recurrent_network.py i am getting this error

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It looks like you are using an older version of Tensorflow, and need to update to Tensorflow v0.12.0 or above. The error you are getting is indicating that the split_dim value in your tf.split function is expecting an integer, but is receiving the tensor x which is of type float32.

This is because in Tensorflow versions < 0.12.0 the split function takes the arguments as:

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

The tutorial you are working from was written for versions > 0.12.0, which has been changed to be consistent with Numpy's split syntax:

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

See the changelog for details: https://github.com/tensorflow/tensorflow/blob/64edd34ce69b4a8033af5d217cb8894105297d8a/RELEASE.md


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...