tf2-object-detection-api-tutorial
tf2-object-detection-api-tutorial copied to clipboard
Reading images in RGB
The example from the TF2 Model Zoo inference tutorial notebook loads images in RGB format with:
def load_image_into_numpy_array(path):
"""Load an image from file into a numpy array.
Puts image into numpy array to feed into tensorflow graph.
Note that by convention we put it into a numpy array with shape
(height, width, channels), where channels=3 for RGB.
Args:
path: the file path to the image
Returns:
uint8 numpy array with shape (img_height, img_width, 3)
"""
img_data = tf.io.gfile.GFile(path, 'rb').read()
image = Image.open(BytesIO(img_data))
(im_width, im_height) = image.size
return np.array(image.getdata()).reshape(
(im_height, im_width, 3)).astype(np.uint8)
In this tutorial you just use cv2.imread()
which will produce numpy arrays in BGR format.
Not sure if this is has been accounted for and I just missed it but if not then it should be fixed. It should be as easy as adding
img = img[...,::-1]
here https://github.com/abdelrahman-gaber/tf2-object-detection-api-tutorial/blob/91f6e167417227b4d5fe42cf3ac770f3b0a3c3b2/detector.py#L22