tensor转换为图片,关于将ndarray(通过cv2或skimage输入的图像)转换为张量

I have read an image as follows using opencv

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

This read image cause the error message when it was called by segmentation, np_image, np_logits = sess.run([pred, image, logits])

The error message is as TypeError: Can not convert a ndarray into a Tensor or Operation.

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

解决方案

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.

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})

Hope this helps!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值