-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix ToPIL #1648
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
Fix ToPIL #1648
Conversation
Signed-off-by: Behrooz <3968947+behxyz@users.noreply.github.com>
Signed-off-by: Behrooz <3968947+behxyz@users.noreply.github.com>
Signed-off-by: Behrooz <3968947+behxyz@users.noreply.github.com>
Also include ToNumpyD, ToNumpyDict, TorchVisionD, and TorchVisionDict Signed-off-by: Behrooz <3968947+behxyz@users.noreply.github.com>
Signed-off-by: Behrooz <3968947+behxyz@users.noreply.github.com>
Signed-off-by: Behrooz <3968947+behxyz@users.noreply.github.com>
Signed-off-by: Behrooz <3968947+behxyz@users.noreply.github.com>
Signed-off-by: Behrooz <3968947+behxyz@users.noreply.github.com>
Signed-off-by: Behrooz <3968947+behxyz@users.noreply.github.com>
Signed-off-by: Behrooz <3968947+behxyz@users.noreply.github.com>
|
How about changing this: And then this: if isinstance(img, PILImage.Image):
return img
if isinstance(img, torch.Tensor):
img = img.detach().cpu().numpy()
return PILImage.fromarray(img)to this: if not has_pil:
raise RuntimeError("ToPIL requires pillow to be installed")
if isinstance(img, PILImage.Image):
return img
if isinstance(img, torch.Tensor):
img = img.detach().cpu().numpy()
return PILImage.fromarray(img)And then any tests can have the decorator added Is that what you're looking for? |
|
Your tests would also need to use |
thanks please add the relevant tests to this list: https://github.com/Project-MONAI/MONAI/blob/master/tests/min_tests.py#L29 so that they'll be skipped in the minimal test pipeline |
|
Thank you @rijobro and @wyli! |
|
It fails at load_submodule, where more submodules have error than ["monai.engines", "monai.handlers] Line 135 in 9ae3005
|
sorry it's incorrect. perhaps it's because of this |
@wyli, sure, but how it can solve the issue with MONAI/tests/test_pil_reader.py Line 18 in 9ae3005
|
could remove all type hints with |
Exactly, that's the problem. Does anyone know a better solution for this? which is not particular to PIL. It's a pity to remove type checking for this. @Nic-Ma @rijobro @wyli |
I fixed it by keeping type checking as follow: if TYPE_CHECKING:
from PIL.Image import Image as PILImageImage
from PIL.Image import fromarray as PILImageFromArray
has_pil = True
else:
PILImageFromArray, has_pil = optional_import("PIL.Image", name="fromarray")
PILImageImage, _ = optional_import("PIL.Image", name="Image") |
Signed-off-by: Behrooz <3968947+behxyz@users.noreply.github.com>
Signed-off-by: Behrooz <3968947+behxyz@users.noreply.github.com>
Fixes #1638
Description
Add ToPIL and ToPILD along with the unittests
Status
Ready/Work in progress/Hold
Types of changes
./runtests.sh --codeformat --coverage../runtests.sh --quick.make htmlcommand in thedocs/folder.