Image stacking issue with data augmentation (Docker 0.20, Object detection) #1715
-
Hello (again) ! I am updating my code to make it compatible with version 0.20, but I'm facing an issue when data augmentation is applied for Object Detection. It's as if some Augmentors are slightly changing the size of the image (I couldn't pinpoint which ones), causing an issue when images are stacked together later. I am using a dataset of images size 256x256 pixels. Here is the error I get after the training began : 2023-02-22 10:08:21:rastervision.pytorch_learner.learner: INFO - epoch: 0
Training: 3%|████▋
[...]
File "/opt/conda/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch
return self.collate_fn(data)
File "/opt/src/rastervision_pytorch_learner/rastervision/pytorch_learner/object_detection_utils.py", line 248, in collate_fn
x = torch.stack(imgs)
RuntimeError: stack expects each tensor to be equal size, but got [3, 264, 264] at entry 0 and [3, 276, 276] at entry 1 The dimensions can be slighty different from trial to trial. I also had stack expects each tensor to be equal size, but got [3, 241, 241] at entry 0 and [3, 256, 256] at entry 1 The error disappears if I remove data augmentation completely. Since, I am using the Docker 0.20, maybe I need to make changes in the config file ? # define parameters for window selection (sliding or random)
window_opts = ObjectDetectionGeoDataWindowConfig(
method=GeoDataWindowMethod.sliding,
size=chip_sz,
stride=chip_sz)
# define pipeline of transforms for Data Augmentation
aug_transform = A.Compose([
A.OneOf([
A.RGBShift(),
A.ToGray(),
A.ToSepia(),
]),
A.OneOf([
A.RandomBrightnessContrast(),
A.RandomGamma(),
A.HueSaturationValue()
]),
A.OneOf([
A.Blur(),
A.GaussNoise()
]),
A.OneOf([
A.Flip(),
A.HorizontalFlip(),
A.VerticalFlip(),
A.Transpose(),
]),
A.OneOf([
A.RandomScale(),
A.RandomRotate90()
])
])
aug_transform = A.to_dict(aug_transform)
data = ObjectDetectionGeoDataConfig(
scene_dataset=scene_dataset,
window_opts=window_opts,
img_sz=chip_sz,
aug_transform=aug_transform
) I confess I am a bit lost between all the I kept this config based on an answer @AdeelH gave me on the old gitter here, but it may need to be modified with 0.20 ? Thanks a lot ;) Keep up the great work \o/ Laetitia |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The size error is due to I would recommend spending some time trying out these augmentation transforms on sample images from your data in a notebook to get a feel for how they affect your data and then choosing the ones that seem most useful. The full list of available transforms can be found here.
No, you're doing it right. As the new docs emphasize, RV can be used as either a framework or a library. When using it as a framework (i.e. what you are currently doing) you specify settings in
Take a look at #1666 to see if any of those apply to your config.
o7 |
Beta Was this translation helpful? Give feedback.
The size error is due to
A.RandomScale
which resizes the images. If you want to retain the image size after scaling (i.e. by cropping after upscaling and padding after downscaling), you can tryA.ShiftScaleRotate
. If you don't want the shifting and rotation, you can setshift_limit
androtate_limit
to zero.I would recommend spending some time trying out these augmentation transforms on sample images from your data in a notebook to get a feel for how they affect your data and then choosing the ones that seem most useful. The full list of available transforms can be found here.