Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced to_tensor() with pil_to_tensor() + convert_image_dtype() #4452

Merged
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions references/detection/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def forward(self, image: Tensor,
class ToTensor(nn.Module):
def forward(self, image: Tensor,
target: Optional[Dict[str, Tensor]] = None) -> Tuple[Tensor, Optional[Dict[str, Tensor]]]:
image = F.to_tensor(image)
image = F.pil_to_tensor(image)
image = F.convert_image_dtype(image)
return image, target


Expand Down Expand Up @@ -231,7 +232,8 @@ def forward(self, image: Tensor,

is_pil = F._is_pil_image(image)
if is_pil:
image = F.to_tensor(image)
image = F.pil_to_tensor(image)
image = F.convert_image_dtype(image)
image = image[..., permutation, :, :]
if is_pil:
image = F.to_pil_image(image)
Expand Down
3 changes: 2 additions & 1 deletion references/segmentation/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def __call__(self, image, target):

class ToTensor(object):
def __call__(self, image, target):
image = F.to_tensor(image)
image = F.pil_to_tensor(image)
image = F.convert_image_dtype(image)
target = torch.as_tensor(np.array(target), dtype=torch.int64)
return image, target

Expand Down