Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 142 additions & 67 deletions docs/examples/getting_started/torchvision_api.ipynb
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Bug — incorrect description, line ~109] ToPureTensor is not about "PIL.Imagetorch.Tensor conversion". Per dali/python/nvidia/dali/experimental/torchvision/v2/totensor.py, it "Signals the pipeline to return a torch.Tensor instead of the default output type" and is a no-op marker — it works on any pipeline (HWC or CHW); typical use is on a CHW pipeline where the input is already a torch.Tensor and you want to force a plain-tensor return regardless of pipeline default. There is no PIL involvement.

Also, torchvision's own v2.ToPureTensor semantically converts tv_tensors back to plain torch.Tensor, so linking it from a row whose description talks about PIL conversion is doubly confusing for users coming from torchvision.

Suggested rewrite:

ToPureTensor | v2.ToPureTensor | Marker placed in a Compose op list — signals the pipeline to return a plain torch.Tensor regardless of the pipeline's default output type. Does not modify the data. |

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Minor — line ~104, PILToTensor row] Description omits the dtype/range, which is the main reason a user picks PILToTensor over to_tensor: per totensor.py, PILToTensor causes the HWC pipeline to return a uint8 CHW tensor with values in [0, 255] (no scaling), whereas the functional to_tensor (line ~133) returns float32 in [0, 1]. Without that detail the table doesn't help the reader choose between them.

Also the wording "return-type hint for Compose" reads like a Python type hint. Suggest applying this phrasing consistently to PILToTensor (L104), ToPILImage (L108), and ToPureTensor (L109):

Marker placed at the end of a Compose op list — signals the HWC pipeline to return a uint8 CHW torch.Tensor (values in [0, 255], no scaling) instead of PIL.Image. The conversion is performed by Compose; the operator does not modify the data.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Nit, optional — line ~132, to_pil_image row] Implementation in v2/functional/totensor.py rescales floating-point input by *255 and clips to uint8 (unless mode == "F"). Worth a half-sentence in the table so users aren't surprised that a float32 tensor in [0, 1] round-trips through to_pil_image/pil_to_tensor correctly while the same tensor in [0, 255] does not.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Minor — line ~223, regenerated stderr cell] The new cell output contains an absolute path from the developer's machine: /home/mdabek/.local/lib/python3.10/site-packages/matplotlib/projections/__init__.py:63: UserWarning: Unable to import Axes3D...

Two issues:

  1. It leaks a username into shipped docs.
  2. The matplotlib Axes3D UserWarning is environmental noise (multiple matplotlib installs on mdabek's box), not something a reader of the notebook should see.

Easiest fix: re-execute the notebook in the official build container (where this warning doesn't fire), or wrap the matplotlib import in warnings.filterwarnings("ignore", ...) and re-run before committing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Large diffs are not rendered by default.