question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PIL.UnidentifiedImageError: cannot identify image file

See original GitHub issue

I made tsv builder for custom image inference

but error occurs when I run it with my tsv file

PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f8897ba1e50>

I find that str convert into float64 automatically when I save tsv file with pandas

here’s my custom make_tsv function


def make_tsv(datapath, img_list, start_index):

    data = pd.DataFrame({"unique_id": [], "img_id": [], "caption": [], "predicted_object_labels": [], "base64_str": []})
    for i, img_name in enumerate(img_list):
        print("index: ", i)
        print("img_name: ", img_name)
        img = Image.open(os.path.join(datapath, img_name))
        img_buffer = BytesIO()
        img.save(img_buffer, format=img.format)
        byte_data = img_buffer.getvalue()
        unique_id = start_index + i
        img_id = img_name.split(".")[-2]
        caption = ""
        predicted_object_labels = ""
        base64_str = base64.b64encode(byte_data)
        temp_dataframe = pd.DataFrame({"unique_id": [unique_id], "img_id": [img_id], "caption": [caption], \
                                            "predicted_object_labels": [predicted_object_labels], \
                                            "base64_str": [str(base64_str)]})

        data = pd.concat([data, temp_dataframe], ignore_index=True)
        
    return data

and I can’t find solution yet.

can u give me advise??

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
SangMyeongWohcommented, Mar 22, 2022

Hi, the definitions of the 4th-indexed columns are different between your tsv file (predicted_object_labels) and caption_test.tsv (base64_str). Please check the schema of your dataframe and make it conform with our provided tsv file.

Im really appreciate with your aid.

I was fool

I’ll check what u said first.

0reactions
yangapkucommented, Mar 22, 2022

By the way, the necessity of using base64_str = base64.b64encode(byte_data).decode("utf-8") instead of base64_str = base64.b64encode(byte_data) is to avoid obtaining a string like “b’/9j/4AAQSkZJRgA’” in your tsv file and further cause some errors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Image.open() cannot identify image file - Python?
When I was uploading my images, that had not been giving this error locally, I was observing UnidentifiedImageError exception thrown by PIL when ......
Read more >
PIL.UnidentifiedImageError: cannot identify image file: .ai #4392
Pillow seems to not be able to load .ai file using Pillow 7.0 File "/usr/local/lib/python3.7/site-packages/PIL/Image.py", line 2862, ...
Read more >
PIL.UnidentifiedImageError: cannot identify image file <_io ...
How to reproduce the issue ? I am experiencing an error similar to this topic: Error when executing tao classification, cannot identify image...
Read more >
cannot identify image file <_io.BytesIO object at ... - Kaggle
I don't understand this error message : UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7fcdd17f6d70>
Read more >
Getting this error Unknown: UnidentifiedImageError: cannot ...
Hi, Can someone please help me with this error. Unknown: UnidentifiedImageError: cannot identify image file <_io.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found