Tensorflow numpy image reshape [grayscale images]

后端 未结 1 2004
情书的邮戳
情书的邮戳 2021-02-09 18:45

I am trying to execute the Tensorflow \"object_detection_tutorial.py\" in jupyter notebook, with my trained neural network data but it throws a ValueError. The file mentioned ab

相关标签:
1条回答
  • 2021-02-09 19:06

    Tensorflow expected input which is formated in NHWC format, which means: (BATCH, HEIGHT, WIDTH, CHANNELS).

    Step 1 - Add last dimension:

    last_axis = -1
    grscale_img_3dims = np.expand_dims(image, last_axis)
    

    Step 2 - Repeat the last dimension 3 times:

    dim_to_repeat = 2
    repeats = 3
    np.repeat(grscale_img_3dims, repeats, dim_to_repeat)
    

    So your function should be:

    def load_image_into_numpy_array(image):
        # The function supports only grayscale images
        assert len(image.shape) == 2, "Not a grayscale input image" 
        last_axis = -1
        dim_to_repeat = 2
        repeats = 3
        grscale_img_3dims = np.expand_dims(image, last_axis)
        training_image = np.repeat(grscale_img_3dims, repeats, dim_to_repeat).astype('uint8')
        assert len(training_image.shape) == 3
        assert training_image.shape[-1] == 3
        return training_image
    
    0 讨论(0)
提交回复
热议问题