Open PIL image from zip (Kaggle competition)

Issue

This Content is from Stack Overflow. Question asked by Kenny Smith

I am trying to read an image from kaggle competition (It is an old competition, but I would like to practice):
https://www.kaggle.com/competitions/dogs-vs-cats-redux-kernels-edition

I am trying to read images from the training file zip using this code:

def get_files_names(zip_file_path):
    with ZipFile(zip_file_path) as myzip:
        return myzip.namelist()


def get_image(zip_path, image_name):
    with ZipFile(zip_path) as myzip:
        #         print(myzip.namelist()[:10])
        with myzip.open(image_name) as myfile:
            #             img = Image.open(myfile)
            img = Image.open(myfile)

    return img

names = get_files_names(train_file_path)

img = get_image(train_file_path, names[1])

img.show()

I am getting this error:
AttributeError: 'NoneType' object has no attribute 'seek'

If I extract the file into finder (using mac), then I see this image:
enter image description here

Also, if I try to convert the RGB image into into a numpy array np.array(img), I get this result:
enter image description here

What am I doing wrong?



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?