无法在tensorflow模型中将ndarray转换为Tensor或Operation错误 [英] Can not convert a ndarray into a Tensor or Operation error in TensorFlow model

查看:579
本文介绍了无法在tensorflow模型中将ndarray转换为Tensor或Operation错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在TensorFlow中实现Wasserstein DCGAN.运行以下行时发生错误:train_image = sess.run(image_batch).处理此异常会引发另一个异常

I am implementing a Wasserstein DCGAN in TensorFlow. The error occurs when this line is run : train_image = sess.run(image_batch). The handling of this exception throws another exception

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数据集->

I am using the MNIST dataset fetched using this command -->

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

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. 请询问是否需要其他详细信息.

COMPLETE SOURCE CODE : https://github.com/tanmay-bhatnagar/W-DCGAN Using TensorFlow 1.4.1 and python 3.6 with latest version of all other libraries. Please ask for any other details that are required.

推荐答案

在通过(X_train, Y_train), (X_test, Y_test)之前,请确保您使用的是

Before passing (X_train, Y_train), (X_test, Y_test), make sure you are using tf.convert_to_tensor() to convert them to tensors in your code.

这篇关于无法在tensorflow模型中将ndarray转换为Tensor或Operation错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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