pytorch / pytorch/vision

torchvision.io.read_image should take file path or image encoded as bytes

Open
#7,751 3 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🚀 The feature

Currently torchvision.io.read_image() expects a file path as input.

In many practical cases, the image is encoded as bytes

It would be nice to have a torchvision method to read this and convert to a tensor

Expected behavior

img_t = torchvision.io.read_image(str or bytes)
Motivation, pitch

Ease of use
Good user experience

Alternatives

I use the following code

image = Image.open(io.BytesIO(image))
image = transforms.ToTensor()(image)
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the torchvision.io.read_image entry point described in the issue and compare its current path handling with the bytes-based PIL and io.BytesIO alternative shown. Determine how encoded bytes should be accepted and converted to a tensor, then add coverage for both string paths and bytes input. The issue does not name specific files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, computer-vision
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.