Repository navigation
Conversation
and shift_intensity Signed-off-by: KumoLiu <[email protected]>
|
Should we consider channel-wise values to clip? Thanks. |
|
I think the range 0-255 comes from the dtype uint8, perhaps what's missing is a >>> torchvision.transforms.functional.adjust_contrast((torch.rand([1, 3, 3])*512).to(torch.uint8), 1)
tensor([[[232, 40, 211],
[ 65, 238, 172],
[198, 2, 93]]], dtype=torch.uint8) |
Casting to uint8 would effectively clip but we want to be able to do it in floating point anyway. There's a number of times where I've used |
|
Hi @wyli, thanks for your suggestions, I'm confused about why casting to uint8 can replace clipping. It seems the return values of the two operations are different. Am I missing anything? Thanks! |
Hi @ericspod, thanks for your suggestions! I think having a |
I don't think having a transform multiple times in a sequence is a problem unless there's performance reasons making that slow. I have had multiples of the same transform in the past. So if there's no overriding performance concern motivating keeping |
|
sure, just to clarify my previous comment, the main motivation of clipping 0-255 is to simulate training examples in uint8, as a data augmentation method. if we add a dtype preserving option, then the problem is solved. preserving the types is not necessarily just bound = _max_value(img1.dtype)
return (ratio * img1 + (1.0 - ratio) * img2).clamp(0, bound).to(img1.dtype) |
|
Maybe you can also consider the existing Thanks. |
|
Hi @wyli, I see your point! |
it seems the current transform doesn't preserve the original dtype, and it's not possible to specify output dtype...maybe we can improve this, but at the moment the resampling backend doesn't support many dtypes anyway. so I don't have a strong opinion about this PR, was just mentioning the potential of adding |
I agree with @ericspod , I recommend have a separate clipping transform, instead of cluttering existing transforms. Adding clipping option only to 2 of these augmentation transforms seems somewhat arbitrary, and adding it to All augmentation transforms is too much. |
|
I think in MONAI/monai/transforms/intensity/array.py Line 238 in 624e832 Thanks! |
agreed, I think this is a bug MONAI/monai/transforms/intensity/array.py Line 238 in 624e832 I think we should do similarly this logic: https://github.com/pytorch/vision/blob/ad128b753c7e8cc0c600dfddac22ff48fc73c9d9/torchvision/transforms/functional_tensor.py#L64 |
|
@KumoLiu these are great improvements that you are making. Thanks for putting effort on this, but for hovernet pipeline, please use colorjitter instead as it should include all these color augmentations: https://github.com/Project-MONAI/tutorials/blob/7eccb858f0286a40fdd0a2fd4bfbb0702af8e6ef/pathology/tumor_detection/ignite/camelyon_train_evaluate.py#L89-L91 |
Yes, I have used it. Thanks! |
|
After discussion, I will close this PR and create another PR later. |
|
FYI, torchvision clips value to [0, 1] for floating points or [0, 255] for uint8 type for any blending operation and adjust_gamma (which is what actually |
Signed-off-by: KumoLiu [email protected]
Part of #5517.
Description
If we have an RGB image, after shifting intensity, the intensity will go beyond the original range. Users may want to clip the data to the 0-255 range. This PR adds
clip_rangeargument inShiftIntensityandAdjustContrastto help do that.Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.