pytorch / pytorch/pytorch.github.io

Error when padding PIL image in mode P

Open
#811 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
285
Forks
317
PR merge metrics
No merged PRs in 30d

Description

To regenerate the issue:

F.pad(Image.fromarray(np.zeros((300,300))).convert('P'), (3,3))

Error messages:

Traceback (most recent call last):
File "/home/npmhung/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "", line 1, in
File "/home/npmhung/miniconda3/envs/pytorch/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 454, in pad
return F_pil.pad(img, padding=padding, fill=fill, padding_mode=padding_mode)
File "/home/npmhung/miniconda3/envs/pytorch/lib/python3.7/site-packages/torchvision/transforms/functional_pil.py", line 153, in pad
image = ImageOps.expand(img, border=padding, **opts)
File "/home/npmhung/miniconda3/envs/pytorch/lib/python3.7/site-packages/PIL/ImageOps.py", line 403, in expand
draw.rectangle((0, 0, width - 1, height - 1), outline=color, width=border)
File "/home/npmhung/miniconda3/envs/pytorch/lib/python3.7/site-packages/PIL/ImageDraw.py", line 259, in rectangle
self.draw.draw_rectangle(xy, ink, 0, width)
TypeError: an integer is required (got type tuple)

Contributor guide

No contributing guide indexed for this repository

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 torchvision.transforms.functional.py and functional_pil.py at the pad call, then inspect the PIL ImageOps.expand and ImageDraw.rectangle frames shown in the traceback. Run the provided F.pad reproduction with a mode-P image and confirm padding completes without the TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python, pytorch
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.