IDEA-Research / detrex

detrex is a research platform for DETR-based object detection, segmentation, pose estimation and other visual recognition tasks.
https://detrex.readthedocs.io/en/latest/
Apache License 2.0
2.01k stars 209 forks source link

Is it possible to resize of image data before augmentation? #179

Closed momopusheen closed 1 year ago

momopusheen commented 1 year ago

Dear authors, thanks for your excellent work!

I have datas in various sizes. As I'm using a FPN-like structure, the input image size should be resized to [512, 512]

Now I realize this resize approach by modifying the detr_data_mapper.py

if self.augmentation_with_crop is None: image, transforms = T.apply_transform_gens(self.augmentation, image) else: if np.random.rand() > 0.5: image, transforms = T.apply_transform_gens([T.Resize((512, 512))], image)

However, in original code, it looks like several augmentation methods were set here:

`if np.random.rand() > 0.5:

image, transforms = T.apply_transform_gens(self.augmentation, image)`

Is it possible if I want to do the resize as well as using the augmentation? I mean, augment the resized [512, 512] images?

Thanks for your consideration!

rentainhe commented 1 year ago

Maybe you can try to add one more resize augmentation as the first augmentation in the config~ @momopusheen

rentainhe commented 1 year ago
dataloader.train = L(build_detection_train_loader)(
    dataset=L(get_detection_dataset_dicts)(names="coco_2017_train"),
    mapper=L(DetrDatasetMapper)(
        augmentation=[
            L(T.ResizeShortestEdge)(
                short_edge_length=512,
                max_size=512,
            ),
            L(T.RandomFlip)(),
            L(T.ResizeShortestEdge)(
                short_edge_length=(480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800),
                max_size=1333,
                sample_style="choice",
            ),
        ],
        augmentation_with_crop=[
            L(T.ResizeShortestEdge)(
                short_edge_length=512,
                max_size=512,
            ),
            L(T.RandomFlip)(),
            L(T.ResizeShortestEdge)(
                short_edge_length=(400, 500, 600),
                sample_style="choice",
            ),
            L(T.RandomCrop)(
                crop_type="absolute_range",
                crop_size=(384, 600),
            ),
            L(T.ResizeShortestEdge)(
                short_edge_length=(480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800),
                max_size=1333,
                sample_style="choice",
            ),
        ],
        is_train=True,
        mask_on=False,
        img_format="RGB",
    ),
    total_batch_size=16,
    num_workers=4,
)

I'm not sure if this works for you, just a simple example, you can try to use a Resize augmentation to replace the ResizeShortEdge Augmentation, you can refer to d2's documentation to check the augmentation function there

rentainhe commented 1 year ago

I'm closing this issue~ Feel free to reopen it if needed~