Skip to content

Model predict with forward will fail if PIL image does not have filename attribute #2702

Description

@robmarkcole

🐛 Bug

forward here checks for the filename attribute on a PIL image and will fail with ValueError: PosixPath('.') has an empty name if not present. This is the case if the PIL image is created from bytes. My hacky solution is below:

# read file
img_bytes = file.read() 
img = Image.open(io.BytesIO(img_bytes))
img.save('/tmp/tmp.jpg')

# Reopen
img = Image.open('/tmp/tmp.jpg')
results = model(img, size=640)

To Reproduce (REQUIRED)

Run model(Image.open(io.BytesIO(img_bytes)), size=640)

Expected behavior

No failure if no filename attribute

Additional context

Previously referenced in #2246

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions