Replace deprecated v2.ToTensor() in Matrix-Game-2/inference.py with v2.ToImage() + v2.ToDtype(scale=True)
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 90/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python, pytorch
- Domain
- computer-vision, machine-learning
Research direction
Start at Matrix-Game-2/inference.py:43 and inspect the frame_process pipeline around the deprecated transform. Validate the inference preprocessing with torchvision 0.26.0+cpu and warnings treated as errors; done means the warning is gone and the replacement produces equivalent output.
Written by the indexing model from the issue text.
Description
Summary
Matrix-Game-2/inference.py:43 instantiates torchvision.transforms.v2.ToTensor(), which is a deprecated alias: constructing it emits a UserWarning on every instantiation:
self.frame_process = v2.Compose([
v2.Resize(size=(352, 640), antialias=True),
v2.ToTensor(), # ← emits UserWarning on construction
v2.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
])
Warning text (verified on torchvision 0.26.0):
The transform
ToTensor()is deprecated and will be removed in a future release. Instead, please usev2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)]).
This warning has been present since torchvision 0.15 (when the v2 namespace was introduced) — torchvision/transforms/v2/_deprecated.py has called warnings.warn in ToTensor.__init__ since the first release.
Proposed fix
Replace v2.ToTensor() with the officially recommended equivalent inside the same v2.Compose:
self.frame_process = v2.Compose([
v2.Resize(size=(352, 640), antialias=True),
v2.ToImage(),
v2.ToDtype(torch.float32, scale=True),
v2.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
])
Validation (torchvision 0.26.0+cpu)
v2.ToTensor()(img)andv2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)])(img)produce identical output up to float precision: max abs diff = 5.96e-8 (a single last-bit rounding difference on uint8→float32 scaling; the official deprecation message itself states "Output is equivalent up to float precision").- With
warnings.simplefilter("error", UserWarning): the current code raises the deprecationUserWarning; the proposed pipeline constructs and runs cleanly.
Impact
- No deprecation
UserWarningduring inference; no behavior change to frame preprocessing.
References
- torchvision docs: v2.ToTensor (deprecated) — "[DEPRECATED] Use
v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)])instead." - torchvision source
torchvision/transforms/v2/_deprecated.py—warnings.warninToTensor.__init__, present since 0.15.
- Dominant language
- Python
- Stars
- 2.3k
- Forks
- 254
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SkyworkAI/Matrix-Game
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
SkyworkAI/Matrix-Game#80 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
SkyworkAI/Matrix-Game#77 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 76/100
SkyworkAI/Matrix-Game#86 ·
-
Third person support Open
Difficulty 5/5 Over a week Newbie friendliness 35/100
SkyworkAI/Matrix-Game#76 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
SkyworkAI/Matrix-Game#75 · 1 reaction ·
All issues in SkyworkAI/Matrix-Game
Similar issues
-
triage/confirmed
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
NousResearch/hermes-agent#118866 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100