-
-
Notifications
You must be signed in to change notification settings - Fork 971
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
Adds ImageToTensor module and resize for non-batched images #978
Conversation
|
||
|
||
class ImageToTensor(nn.Module): | ||
"""Converts a numpy image to a PyTorch 4d tensor image. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By numpy image, are we assuming it is uint8 or floating points within 0~1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both - it just permutes, we don;t modify dtype
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the problem. If I am a user, I would expect this function returns a value as a Kornia image, which is shaped as BCHW and ranged from 0-1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with it, but tensor_to_image
doesn't do that. And this is just the module of that function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably we could provide an extra operator TensorToDtype
or similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shijianjian another option is the following:
def image_to_tensor(image: np.ndarray, keepdim: bool = True, device: Optional[torch.device] = None, dtype: Optional[torch.dtype] = None) -> torch.Tensor:
...
tensor = ...
if dtype is None:
dtype = tensor.dtype
return tensor.to(device, dtype)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant is the conversion from 8bit image, 12bit image, or 16bit image to 0-1 scale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for that we have normalize. With the definition below you could do the job
nn.Sequential(
ImageToTensor(dtype=torch.float32),
Normalise(mean=0., std=255.),
)
I wouldn't change the default behavior of image_to_tensor
since it might a large set of users
* adapt resize for non batch * implement ImageToTensor module * handle length 2 and 3
* adapt resize for non batch * implement ImageToTensor module * handle length 2 and 3
Description
This PR implements resize to work with non batch and adds
ImageToTensor
module.Status
Ready/Work in progress/Hold
Types of changes
PR Checklist
PR Implementer
This is a small checklist for the implementation details of this PR.
If there are any questions regarding code style or other conventions check out our
summary.
make test
make build-docs
make lint
make mypy
KorniaTeam
KorniaTeam workflow
closes #IssueNumber
at the bottom ifnot already in description)
Reviewer
Reviewer workflow
kornia
design conventions?