【问题标题】:Data Type not understood in tensorflow张量流中不理解的数据类型
【发布时间】:2018-03-06 18:44:41
【问题描述】:
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

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

【问题讨论】:

  • 贴出X_train的定义
  • @Maxim X_train = np.array([[....],[....]....[...]]),它是一个 30x355 的 numpy 数组跨度>

标签: python-2.7 tensorflow neural-network deeplearning4j


【解决方案1】:

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

参数:

  • x:张量。

试试这个:

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

【讨论】:

  • 它确实有助于消除有关不正确数据的错误,但现在抛出了一个新错误,这是由于我无法将“x”传递给函数。 ---&gt; 96 parameters = model(X_train, Y_train, X_test, Y_test) in model(X_train, Y_train, X_test, Y_test, learning_rate, num_epochs, print_cost) ---&gt; 73 _ , minibatch_cost = sess.run([optimizer, cost], feed_dict={X: X_train, Y: Y_train}) TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.
  • @Abhinandan 这看起来像是另一个问题。请参阅stackoverflow.com/q/42560209/712995 或随时提出新问题。
猜你喜欢
  • 1970-01-01
  • 2018-05-03
  • 1970-01-01
  • 2016-07-25
  • 1970-01-01
  • 2011-07-23
  • 2020-08-16
  • 1970-01-01
  • 2022-01-14
相关资源
最近更新 更多