关于将ndarray(通过cv2或skimage输入的图像)转换为张量 [英] regarding transforming an ndarray(image input via cv2 or skimage) to a tensor

查看:714
本文介绍了关于将ndarray(通过cv2或skimage输入的图像)转换为张量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用opencv

image = cv2.imread('/data/TestImages/cat.jpg',cv2.IMREAD_UNCHANGED)

此读取的图像由segmentation, np_image, np_logits = sess.run([pred, image, logits])

错误消息为TypeError: Can not convert a ndarray into a Tensor or Operation.

是否有任何机制可以将表示为ndarray的图像转换为Tensorflow张量.谢谢.

Are there any mechanisms that can transform an image represented as ndarray to a Tensorflow tensor. Thanks.

推荐答案

您必须阅读sess.run函数.在数组中,作为函数的参数,您可以指定要退出运行命令的内容.在您的情况下,您可能只需要您的掠食和登录信息.

You have to read up on the sess.run function. In the array you have as argument of your function you specify what you want to get OUT of your run command. In your case, you probably only want your pred and logits.

如果要在网络中放置某些内容,则必须在图形中指定一个tf.placeholder,然后像这样输入图像:

If you want to put something IN the network you have to specify a tf.placeholder in your graph, and feed your image like this:

np_pred,np_logits = sess.run([pred, logits],feed_dict={image_placeholder: image})

希望这会有所帮助!

这篇关于关于将ndarray(通过cv2或skimage输入的图像)转换为张量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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