python-2.7 - tensorflow 中不理解的数据类型

标签 python-2.7 tensorflow neural-network deeplearning4j

mean , variance = tf.nn.moments(X_train, axes = 1, keep_dims = True)

我正在尝试使用 tf.nn.moments() 获取均值和方差,如上所示。但是,我遇到了以下错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-43-fc383f99b15b> in <module>()
     33 Y_train = Y_train.reshape(1,355)
     34 X_mean = tf.reduce_mean(X_train, axis = 1, keepdims = True)
---> 35 mean , variance = tf.nn.moments(X_train, axes = 1, keep_dims = True)
     36 X_train = tf.divide(tf.subtract(X_train,mean),tf.sqrt(variance))
     37 #Y_train = Y_train/(Y_train.max(axis = 1, keepdims = True))

/Users/abhinandanchiney/anaconda2/lib/python2.7/site-      packages/tensorflow/python/ops/nn_impl.pyc in moments(x, axes, shift, name, keep_dims)
    664     # sufficient statistics. As a workaround we simply perform the operations
    665     # on 32-bit floats before converting the mean and variance back to fp16
--> 666     y = math_ops.cast(x, dtypes.float32) if x.dtype == dtypes.float16 else x
    667     # Compute true mean while keeping the dims for proper broadcasting.
    668     mean = math_ops.reduce_mean(y, axes, keepdims=True, name="mean")

 TypeError: data type not understood

请在我出错的地方提供帮助。

最佳答案

tf.nn.moments期待一个张量,而不是一个 numpy 数组:

Args:

  • x: A Tensor.

试试这个:

x = tf.convert_to_tensor(X_train)
mean , variance = tf.nn.moments(x, axes = 1, keep_dims = True)

关于python-2.7 - tensorflow 中不理解的数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49137905/

相关文章:

python - 如何使用 Python Pandas 聚合、获取百分比以及重新分配列和行?

Python正则表达式查找特殊字符和中间的字符

python - 从 Keras 预训练网络检索图像的三重模型

tensorflow - 具有交叉熵的像素级 softmax 用于多类分割

machine-learning - 选择权重初始化之间的初始损失(迭代=0)有很大不同。为什么?

Python Pandas - 读取包含多个表的 csv 文件

python - ipython 不工作

python - 创建自定义初始时的 tensorflow.python.framework.errors_impl.NotFoundError

machine-learning - 如何确定卷积神经网络层中使用的特征图数量?

python - 神经网络没有经过训练,交叉熵保持不变