Open PIL image from zip (Kaggle competition)


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):

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 as myfile:
            #             img =
            img =

    return img

names = get_files_names(train_file_path)

img = get_image(train_file_path, names[1])

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?


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?