Skip to content

Replace deprecated torchvision decode_image with TorchCodec - #3979

Open
hippi345 wants to merge 1 commit into
pytorch:mainfrom
hippi345:fix/data-tutorial-torchcodec-3978
Open

hippi345 wants to merge 1 commit into
pytorch:mainfrom
hippi345:fix/data-tutorial-torchcodec-3978

Conversation

@hippi345

Copy link
Copy Markdown

Replace deprecated torchvision decode_image with TorchCodec

Summary

This PR addresses issue #3978 by replacing the deprecated torchvision.io.decode_image function with torchcodec.decoders.decode_image in the Datasets & DataLoaders tutorial.

Changes

  • Updated beginner_source/basics/data_tutorial.py: Changed import from torchvision.io.decode_image to torchcodec.decoders.decode_image
  • Updated .ci/docker/requirements.txt: Added torchcodec dependency

Background

Starting with recent versions of torchvision, the decode_image function has been deprecated in favor of TorchCodec, which is now the recommended way to decode images in the PyTorch ecosystem. The function's documentation explicitly states:

[DEPRECATED] Use TorchCodec instead.

Technical Details

The change maintains full API compatibility:

  • TorchCodec's decode_image accepts the same arguments (file path as string)
  • Returns tensors in the same format (CHW layout with uint8 dtype by default)
  • Supports the same image formats (JPEG, PNG, WebP, GIF, AVIF, HEIC)

The tutorial code continues to work exactly as before, just using the non-deprecated API.

Testing

Verified that the fix works correctly:

  1. Confirmed the import of torchcodec.decoders.decode_image succeeds
  2. Tested the CustomImageDataset class with sample images
  3. Verified image decoding returns correct tensor shapes and dtypes
  4. Confirmed the code runs successfully on CPU without GPU requirements

All functionality is preserved and the deprecation warning is eliminated.

Fixes #3978

The torchvision.io.decode_image function is deprecated in favor of
TorchCodec. This change updates beginner_source/basics/data_tutorial.py
to use torchcodec.decoders.decode_image instead.

The change maintains API compatibility as TorchCodec's decode_image
accepts the same arguments (file path) and returns tensors in the same
format (CHW uint8 by default).

Also adds torchcodec to requirements.txt to ensure it is available
during builds.

Fixes pytorch#3978
@pytorch-bot

pytorch-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/3979

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla

meta-cla Bot commented Oct 15, 2026

Copy link
Copy Markdown

Hi @hippi345!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@hippi345
hippi345 marked this pull request as ready for review October 15, 2026 15:44
@meta-cla

meta-cla Bot commented Oct 15, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the cla signed label Oct 15, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/docker
  • ciflow/docs

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

1 similar comment
@pytorch-bot

pytorch-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/docker
  • ciflow/docs

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feedback about Datasets & DataLoaders

1 participant