<p dir="auto">same as <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="267415809" data-permission-text="Title is private" data-url="https://github.com/tensorflow/tensorflow/issues/13890" data-hovercard-type="issue" data-hovercard-url="/tensorflow/tensorflow/issues/13890/hovercard" href="https://github.com/tensorflow/tensorflow/issues/13890">#13890</a><br>
And I have tried tensorflow 1.4.0 , tensorflow 1.4.1 ,tensorflow 1.7 , all of them got a wrong value,and when I use cpu to calculate it ，it returns a right value .</p>
<h3 dir="auto">System information</h3>
<ul dir="auto">
<li><strong>Have I written custom code (as opposed to using a stock example script provided in TensorFlow)</strong>: Yes</li>
<li><strong>OS Platform and Distribution (e.g., Linux Ubuntu 16.04)</strong>: 16.04.LTS</li>
<li><strong>TensorFlow installed from (source or binary)</strong>: Source</li>
<li><strong>TensorFlow version (use command below)</strong>: 1.3.0</li>
<li><strong>Python version</strong>:  2.7.12</li>
<li><strong>Bazel version (if compiling from source)</strong>: 0.5.2</li>
<li><strong>CUDA/cuDNN version</strong>: 8.0/6.0.21</li>
<li><strong>GPU model and memory</strong>: Nvidia Tegra X2</li>
<li><strong>Exact command to reproduce</strong>:<code class="notranslate">tf.image.crop_and_resize(raw_sample, boxes, box_ind)</code></li>
</ul>
<h3 dir="auto">Describe the problem</h3>
<p dir="auto">I'm getting completly different results from tensorflow's function <code class="notranslate">tf.image.crop_and_resize(...)</code> when assigned it to gpu and cpu.<br>
In other words:<br>
-when I run this ops on CPU, I get correct results( I mean, the  right crops)<br>
-when I put it on the GPU device I get crops fulled with 0 values.</p>
<h3 dir="auto">Source code / logs</h3>
<p dir="auto">Here, you can see a simple use case:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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=&quot;croper&quot;)

    return crops


def main():

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

	print(&quot;Shape and type of image input &quot;,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()"><pre class="notranslate"><code class="notranslate">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()
</code></pre></div>