【问题标题】:the correct way to input images for testing the tensorflow model输入图像以测试张量流模型的正确方法
【发布时间】:2016-11-24 00:21:39
【问题描述】:

我一直在尝试测试 fcn 实现posted here。我唯一改变的是设置输入图像以针对模型进行测试的方式。我的修改在下图中用红色曲线标记。

但是,运行程序导致以下错误消息TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, or numpy ndarrays. ,发生在down, up = sess.run(tensors, feed_dict=feed_dict)。我很想知道我的实现中有什么问题,以及如何修改它。在原帖中,作者使用img1 = skimage.io.imread("./test_data/tabby_cat.png") 输入图片。

如果我将batch_images=tf.expand_dims(images,0) 更改为batch_images=tf.expand_dims(img1,0),程序将输出以下错误消息。

【问题讨论】:

    标签: python image-processing tensorflow


    【解决方案1】:

    如错误所示,可用作提要的值类型是 Python 标量、字符串、列表或 numpy 数组。您尝试用作提要的是img1tf.image.decode_png 的输出,其类型为tf.Tensor。因此错误。你有两个选择:

    1) 在输入之前将 img1 转换为 numpy 数组。您可以通过简单地评估 img1 来做到这一点,如下所示:

    feed_dict = {images:img1.eval()}
    

    2) 使用img1 本身作为模型其余部分的输入。你可以这样做:

    batch_images = tf.expand_dims(img1, 0)
    

    【讨论】:

    • 嗨,Keveman,感谢您的回复。我之前尝试过第一种方法,但程序只是永远停在 feed_dict = {images:img1.eval()} 行,而不会继续前进或退出并显示一些错误消息。它只是停在那里。我刚刚尝试了第二种方法,结果包含在原始方法中。看起来模型构建过程甚至没有通过。
    • 第二种方法,试试batch_images = tf.expand_dims(tf.cast(img1, tf.float32), 0)
    • 嗨keveman,谢谢你的建议,我试过了,然后出现“TypeError: The value of a feed cannot be a tf.Tensor object.Acceptable feed values include Python scalars, strings,列表或 numpy ndarrays。" 再次出现。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-17
    • 2023-03-15
    • 2020-07-25
    • 1970-01-01
    • 2017-03-06
    • 2017-11-22
    相关资源
    最近更新 更多