Code Monkey home page Code Monkey logo

Comments (6)

kamransoomro84 avatar kamransoomro84 commented on June 18, 2024 1

Ok. I downgraded to pillow 9.5.0 and now it works.

from fastbook.

ed-kung avatar ed-kung commented on June 18, 2024

I have the same problem. The problem is that im.mode='RGBA' which throws a KeyError in JpegImagePlugin.py:

KeyError                                  Traceback (most recent call last)
File ~/mambaforge/lib/python3.10/site-packages/PIL/JpegImagePlugin.py:639, in _save(im, fp, filename)
    638 try:
--> 639     rawmode = RAWMODE[im.mode]
    640 except KeyError as e:

KeyError: 'RGBA'

I tried converting the images to RGB and re-saving them, but no luck, so I'm guessing fastai converts them to RGBA somewhere along the way?

fns = get_image_files(path)
for fn in fns:
    im = Image.open(fn)
    im = im.convert('RGB')
    im.save(fn)

from fastbook.

kamransoomro84 avatar kamransoomro84 commented on June 18, 2024

@couzhei @ed-kung I have this issue too. Did either of you guys figure out a solution?

from fastbook.

couzhei avatar couzhei commented on June 18, 2024

I actually dropped this investigation a while ago since I found out @jph00 is onto preparing the second edition of the book while the recent course of fastai didn't cover the type of production fastai API intended (@jph00 changed the focus quite rightfully into another tool called Gradio, which I believe is the new hype around the community, also great advertising came from both deeplearning.ai and Huggingface communities), but out of curiosity about @ed-kung's investigations I ran through it and it is apparently fine now! I don't know what made this happen but I list possible options that might be suspicious, so i t might not be an actual solution, I guess from fastbook import * might make the python management system confused that all the dependencies are provided or don't upgrade your existing packages, or it might relate to the version of your notebook (I downgraded it), also I seemed to have newer version of lxml, httpcore, and httpx compared to the previous environment.

from fastbook.

kamransoomro84 avatar kamransoomro84 commented on June 18, 2024

Strange. I have the current latest versions of every package so no clue what might be causing it! And yes, I'm using Gradio as well.

from fastbook.

spa-dev avatar spa-dev commented on June 18, 2024

I tried converting the images to RGB and re-saving them, but no luck, so I'm guessing fastai converts them to RGBA somewhere along the way?

The open_thumb function of this widget converts to RBGA. I deleted the .convert('RGBA') part of the code below and the widget no longer throws a KeyError. Seems to work, but I have no idea whether that's needed for something else.

def _open_thumb(
    fn:Path|str, # A path of an image
    h:int, # Thumbnail Height
    w:int # Thumbnail Width
) -> Image: # `PIL` image to display
    "Opens an image path and returns the thumbnail of the image"
    return Image.open(fn).to_thumb(h, w).convert('RGBA')

The rest of the code is here: https://github.com/fastai/fastai/blob/master/fastai/vision/widgets.py

from fastbook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.