1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] during loading photo " path should be path-like or io.BytesIO, not <class...

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to load a photo to ML project and I have error: path should be path-like or io.BytesIO, not <class 'PIL.JpegImagePlugin.JpegImageFile'>

    def load_image_pixels(filename, shape):
    # load the image to get its shape
    image = load_img(filename)
    width, height = image.size
    # load the image with the required size
    image = load_img(filename, target_size=shape)
    # convert to numpy array
    image = img_to_array(image)
    # scale pixel values to [0, 1]
    image = image.astype('float32')
    image /= 255.0
    # add a dimension so that we have one sample
    image = expand_dims(image, 0)
    return image, width, height


    photo_filename = Image.open(r'C:\ML\Pies.jpg')
    # define the expected input shape for the model
    input_w, input_h = 167, 221
    # load and prepare image
    image, image_w, image_h = load_image_pixels(photo_filename, (net_w, net_w))


    I see that photo is loaded but function cannot process it. How to solve this problem.

    In the other codes I worked images opened this way could be processed like converting image to array and then processing it.

    image = Image.open(r'C:\ML\Pies.jpg')
    image = np.array(image)

    Continue reading...

Compartilhe esta Página