tf.image.crop_and_resize()在Jetson TX2上分配给GPU时返回0值

时间:2017-10-21 21:40:36

标签: python tensorflow tensorflow-gpu

系统信息

  • 我是否编写过自定义代码(与使用TensorFlow中提供的库存示例脚本相反):是
  • 操作系统平台和分发(例如,Linux Ubuntu 16.04):16.04.LTS
  • 从(来源或二进制)安装的TensorFlow :来源
  • TensorFlow版本(使用下面的命令):1.3.0
  • Python版:2.7.12
  • Bazel版本(如果从源代码编译):0.5.2
  • CUDA / cuDNN版本:8.0 / 6.0.21
  • GPU型号和内存:Nvidia Tegra X2
  • 重现的确切命令tf.image.crop_and_resize(raw_sample, boxes, box_ind)

描述问题

当我将其分配给gpu和cpu时,我得到了与tensorflow函数tf.image.crop_and_resize(...)完全不同的结果。 换句话说:

  • 当我在CPU上运行此操作时,我得到了正确的结果(我的意思是,正确的作物)

  • 当我把它放在GPU设备上时,我的作物被充满了0值。

源代码/日志

在这里,您可以看到一个简单的用例:

import tensorflow as tf 
import numpy as np
import cv2 #Just importing cv2 to read  image, you use PIL or anything else to load it

device='gpu' 

def img2batch_crops(input_image):
    raw_sample_tensor_4d=tf.expand_dims(input_image, 0)

    #Setting the size to crop and the final size of cropped images
    patches_top=[0,0.5]
    patches_bottom =[0.5,0.5]
    crop_size = [100,100]
    boxes=tf.stack([patches_top, patches_top, patches_bottom, patches_bottom], axis=1)

    ##Here is the bug:
        #When device == 'cpu', I got  results 
        #When device == 'gpu', I got  black cropped images( 0 values)
    with tf.device('/'+device+':0'):  
        crops=tf.image.crop_and_resize(raw_sample_tensor_4d, boxes, box_ind=tf.zeros_like(patches_top, dtype=tf.int32), crop_size=crop_size, name="croper")

    return crops


def main():

    img_data = cv2.imread('image.jpg') #Just loading the image,

    print("Shape and type of image input ",img_data.shape, img_data.dtype) #Print the shape and the type of the image, supposed to be a numpy array

    raw_image = tf.placeholder(dtype=tf.float32, shape=img_data.shape, name='input_image')

       crops = img2batch_crops(raw_image) # Adding ops to the graph

    with tf.Session() as sess:
        myBatchedImages = sess.run(crops, feed_dict={raw_image:img_data})
        cv2.imwrite('result_'+device+'.jpg',myBatchedImages[0])   ## Savej just one cropped image to see how it looks like

main()

0 个答案:

没有答案