TensorFlow - 'Split' Op 的输入 'split_dim' 的 float32 类型与 int32 的预期类型不匹配 [英] TensorFlow - Input 'split_dim' of 'Split' Op has type float32 that does not match expected type of int32

查看:24
本文介绍了TensorFlow - 'Split' Op 的输入 'split_dim' 的 float32 类型与 int32 的预期类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

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

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.

这是因为在 Tensorflow 版本中

0.12.0 split 函数将参数设为:

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)

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

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)

有关详细信息,请参阅变更日志:https://github.com/tensorflow/tensorflow/blob/64edd45a8280000/64edd45a82804000000000000

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

这篇关于TensorFlow - 'Split' Op 的输入 'split_dim' 的 float32 类型与 int32 的预期类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆