Skip to content

Reading images in RGB #6

Open
Open
@ehofesmann

Description

@ehofesmann

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

im_height, im_width, _ = img.shape

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Reading images in RGB · Issue #6 · abdelrahman-gaber/tf2-object-detection-api-tutorial