pytorch-image-models icon indicating copy to clipboard operation
pytorch-image-models copied to clipboard

[FEATURE] Anti Aliasing For EfficientNet Blocks

Open rsomani95 opened this issue 4 years ago • 1 comments

It would be great to have the option to add AntiAliasDownsampleLayer to efficientnet blocks. We could see a boost in accuracy, and it'd definitely provide models with more stable predictions on videos.

If you're open to it, I'd like to put in a PR (with some guidance :) ).

If I understand Adobe's implementation here correctly, the (only) place to apply it would be right after a depthwise conv layer with stride > 1.

In your efficientnet implementation, would right after these lines would be the right places to add a downsampling layer (with an additional if stride > 1)? https://github.com/rwightman/pytorch-image-models/blob/9cc7dda6e5fcbbc7ac5ba5d2d44050d2a8e3e38d/timm/models/efficientnet_blocks.py#L175-L177

For GhostNet, I think this would be the right place to add it: https://github.com/rwightman/pytorch-image-models/blob/9cc7dda6e5fcbbc7ac5ba5d2d44050d2a8e3e38d/timm/models/ghostnet.py#L84-L89


To make the most of compute, would it be feasible to patch in a downsampling layers in these areas after loading one of the many already pretrained models? Adobe recommends doing this in the official repo (source) and since there's no params added, it should in theory be doable.

Curious to hear your thoughts.

rsomani95 avatar Apr 30 '21 11:04 rsomani95

@rsomani95 it's already implemented in the resnet.py and densenet.py models here. I didn't go further and add to more models because it does have a runtime penalty, but is often a (marginal) improvement. It does require retraining the model, you can't just add it without dropping the perf. It's only a partial drop, so you could in theory add the layer, load the old weights (since my blurpool impl doesn't add loadable params like some) and then fine-tune on imagenet...

Look for aa_layer

  • https://github.com/rwightman/pytorch-image-models/blob/a2727c1bf78ba0d7b5727f5f95e37fb7f8866b1f/timm/models/densenet.py
  • https://github.com/rwightman/pytorch-image-models/blob/master/timm/models/resnet.py#L263-L268

I'd certainly accept a PR for EfficientNet/MobileNetV3 family (same blocks), BUT I'd want to see at least one model trained from scratch to better than original accuracy to merge. If you lack the compute, could leave a PR open and wait until I have a chance to try training...

rwightman avatar Apr 30 '21 17:04 rwightman