Skip to content
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

数据增强扩充 #48

Open
sevenandseven opened this issue Oct 12, 2024 · 1 comment
Open

数据增强扩充 #48

sevenandseven opened this issue Oct 12, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@sevenandseven
Copy link

功能描述

把马赛克数据增强和mixup等数据增强方式放入

用例

你好,我想把马赛克数据增强和mixup等数据增强方式放入代码中,看他检测效果怎么样,我应该怎么添加代码?

补充信息

No response

@sevenandseven sevenandseven added the enhancement New feature or request label Oct 12, 2024
@xiuqhou
Copy link
Owner

xiuqhou commented Oct 14, 2024

Hi @sevenandseven
我在代码已经集成了Mosaic和Mixup数据增强,以及优化后的CachedMosaic和CachedMixup,在定义数据增强的时候使用就可以了(参考下方代码),不需要更改其他代码。推荐使用CachedMosaic和CachedMixup,这两个效率更快。

mosaic_mixup = T.Compose([
    T.RandomHorizontalFlip(),
    Mosaic(p=1.0),  # Mosaic p是随机增强的概率
    MixUp(p=1.0),  # Mixup
    T.PILToTensor(),
    T.ConvertImageDtype(torch.float),
    T.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
    T.SanitizeBoundingBox(labels_getter=labels_getter),
])

我也在transforms/presets.py文件中给出了几个示例(mosaiccached_mosaicmixupcached_mixupmixup_mosaiccached_mixup_mosaicmosaic_mixupcached_mosaic_mixup),参考这些您可以用mosaic和mixup来自定义其他的数据增强,然后在configs/train_config.py中使用。

训练前可以用tools/visualize_datasets.py可视化数据增强的结果,下面是一些示例代码和产生的可视化结果:

CachedMosaic:

python tools/visualize_datasets.py --coco-img data/coco/val2017 --coco-ann data/coco/annotations/instances_val2017.json --transform cached_mosaic --show-dir visualization/coco_mosaic --font-scale 0.5 --text-alpha 0.7

000000005477

CachedMixup:

python tools/visualize_datasets.py --coco-img data/coco/val2017 --coco-ann data/coco/annotations/instances_val2017.json --transform cached_mixup --show-dir visualization/coco_mixup --font-scale 0.5 --text-alpha 0.7

000000001296

同时使用CachedMosaic和CachedMixup:

python tools/visualize_datasets.py --coco-img data/coco/val2017 --coco-ann data/coco/annotations/instances_val2017.json --transform cached_mosaic_mixup --show-dir visualization/coco --font-scale 0.5 --text-alpha 0.7

上面这行命令在COCO数据集上应用了transforms/presets.py中定义的cached_mosaic_mixup数据增强,可视化结果如下:

000000002587

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants