regarding transforming an ndarray(image input via cv2 or skimage) to a tensor

纵然是瞬间 提交于 2019-12-12 03:45:41

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/42353188/regarding-transforming-an-ndarrayimage-input-via-cv2-or-skimage-to-a-tensor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!