Reputation: 2450
I'm trying to capture the cropped image using bounding boxes from Faster R-CNN implemented by TensorFlow API. (especially, I followed and customized this tutorial from tensorflow)
My code following the tutorial above is below:
for image_path in TEST_IMAGE_PATHS[0:1]:
image = Image.open(image_path)
image_np = load_image_into_numpy_array(image)
image_np_expanded = np.expand_dims(image_np, axis=0)
(_image_tensor,_boxes, scores, classes, num) = sess.run(
[image_tensor,detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: image_np_expanded})
test = tf.image.crop_and_resize(image=image_np_expanded,
boxes=[[0.27640104,0.2573258,0.57859987,0.7340185]],
box_ind=[0],
crop_size=[50,50])
plt.figure()
plt.imshow(image_np)
plt.figure()
plt.imshow(test[0].eval())
when the code above is executed, the result shows the picture below:
As you can see, the second one which is the cropped image is broken. The value of bounding box is the first value of the variable '_boxes' which is "_boxes[0]"
Is there anything I'm missing? I'm stuck with this issue.
Upvotes: 0
Views: 2173
Reputation: 3124
TensorFlow offers tf.image.convert_image_dtype for the conversion between int and float. It is in particular useful when converting back to int (and using saturate=True
). But I would recommend using it in either direction.
Upvotes: 1
Reputation: 1280
It seems that tf.image.crop_and_resize
expects pixel values in the range [0,1]. Changing your code to
test = tf.image.crop_and_resize(image=image_np_expanded/255., ...)
solved the problem for me.
Upvotes: 0