pytorch / pytorch/vision

functional : to_tensor() doesn't accommodate for PIL image mode 'I:16B'.

Open
#856 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I am trying to convert a TIFF image, read in through PIL, to Pytorch tensor. I am doing this through transorms.ToTensor(). I get the following error:

RuntimeError: shape '[1460, 1936, 5]' is invalid for input of size 5653120

The reason for the error is that the function is mistakenly extracting the number of channels as 5.

The TiffImage.mode is "I;16B". Since to_tensor hasn't got a hard coded rule for "I;16B" mode, it gets the number of channels using len(TiffImage.mode) which returns the length of the string.

cc @vfdev-5

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 at the transforms.ToTensor() entry point and reproduce the failure with a PIL TIFF image whose mode is "I;16B". Trace how the channel count is determined; done means this mode no longer produces a channel count of 5 and the image converts to a tensor successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.