【问题标题】:Can not convert a ndarray into a Tensor or Operation error in TensorFlow model无法将 ndarray 转换为张量或 TensorFlow 模型中的操作错误
【发布时间】:2018-07-25 07:09:12
【问题描述】:

我正在 TensorFlow 中实现 Wasserstein DCGAN。运行此行时发生错误:train_image = sess.run(image_batch)。处理这个异常又抛出一个异常

Fetch argument array([[[0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        ...,
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0]],

       [[0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        ...,
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0]],

       [[0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        ...,
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0]],

       ...,

       [[0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        ...,
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0]],

       [[0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        ...,
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0]],

       [[0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        ...,
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0]]], dtype=uint8) has invalid type <class 'numpy.ndarray'>, must be a string or Tensor. (Can not convert a ndarray into a Tensor or Operation.)

我正在使用通过此命令获取的 MNIST 数据集 -->

from keras.datasets import mnist (X_train, Y_train), (X_test, Y_test) = mnist.load_data()

完整的源代码:https://github.com/tanmay-bhatnagar/W-DCGAN 将 TensorFlow 1.4.1 和 python 3.6 与所有其他库的最新版本一起使用。 请询问任何其他所需的详细信息。

【问题讨论】:

  • rain_image = sess.run(image_batch) 行的目的是什么?您不能将 numpy 数组传递到那里。
  • 你的process_data函数返回numpy数组但是pokeGan的返回tensorflow操作(可以传入sess.run()
  • 这可能有效。在返回之前将tf.reshape(image_batch, [-1,64,64,1]) 添加到process_data
  • 或者你也可以np.reshape()直接喂到real_image
  • 您是否从代码中删除了train_image = sess.run(image_batch)?你应该保留它。

标签: python-3.x tensorflow deep-learning keras conv-neural-network


【解决方案1】:

在传递(X_train, Y_train), (X_test, Y_test) 之前,请确保您使用tf.convert_to_tensor() 将它们转换为代码中的张量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-29
    • 1970-01-01
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多