Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

FFNet: Simple and Efficient Architectures for Semantic Segmentation

FFNets are families of Simple and Efficient Architectures, which we demonstrate the effectiveness of for the task of Semantic Image Segmentation. This repository provides the model definitions and pre-trained weights for the models introduced in the paper Simple and Efficient Architectures for Semantic Segmentation, published at the Efficient Deep Learning for Computer Vision Workshop at CVPR 2022.

FFNet stands for "Fuss-Free Networks", and utilize a simple ResNet-like backbone, and a tiny convolution-only head to produce multi-scale features that are useful for various tasks. FFNet 4-stage

Our key takeaway is that when comparing with various architectures and approaches with a tad more `fuss', ResNet based approaches were being put at a massive disadvantage due to the severly limited receptive fields of ResNet-50/101, owing to the use of bottleneck blocks. While this problem has been acknowledged in prior work, attempts to remedy it have typically involved the use of dilated convolutions to increase the receptive field. Dilated convolutions tend to be slow on current hardware. We show that using deep ResNets with basic-blocks as the backbone/encoder, along with a tiny FPN-like convolutional head/decoder, closes the gap entirely to various SoTA image segmentation models.

We propose various sub-families of FFNets, comprised entirely of well supported convolutional blocks, and show their efficacy on desktop and mobile hardware. The networks provided are for various input/output ratios, and would be useful for a wide variety of tasks beyond just image segmentation.

We argue that such simple architectures should be the go-to baselines for various computer vision tasks, and even where they might lack in accuracy against more complex models, the simplicity of optimizing and deploying them makes these a worthy consideration. See the paper for details of the models, and extensive comparisons.

License

This software may be subject to U.S. and international export, re-export, or transfer (“export”) laws. Diversion contrary to U.S. and international law is strictly prohibited. See the included license.

Citing

If you use the models or the weight definitions, please cite the following publication:

 @inproceedings{mehta2022simple,
title={Simple and Efficient Architectures for Semantic Segmentation},
author={Mehta, Dushyant and Skliar, Andrii and Ben Yahia, Haitam and Borse, Shubhankar and Porikli, Fatih and Habibian, Amirhossein and Blankevoort, Tijmen},
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
pages={2628--2636},
year={2022}
}

Setup

Docker Business

docker build --no-cache -t ffnet_release docker/
docker run --ipc=host --gpus all --rm -it -v "<path_of_imagenet>:/workspace/imagenet/" -v "<path_of_cityscapes>:/workspace/cityscapes/" -v "<path_of_model_weights>:/workspace/ffnet_weights/" -v "<local_path_to_repo>:/workspace/ffnet_release/" -e PYTHONPATH=/workspace/ffnet_release -w /workspace/ffnet_release ffnet_release 

Setting paths

config.py: Paths to imagenet and cityscapes, as well as to the directory with the model weights are here. The default paths are as above in the docker command. In case you choose to map them to a different path, please update the respective paths in config.py

Notes on Dependencies

For inference and evaluation on ImageNet and Cityscapes, the provided docker container suffices. The only somewhat extraneous dependency is SciPy, which is only being used to create a gaussian kernel in ffnet_blocks.py. You can create a gaussian filtering kernel in another way, or replace the anti-aliased downsampling implemented as gaussian filtering + strided convolution with another operation similar in spirit. YMMV.

Pre-trained models

We make weights available with supervised ImageNet pretraining, intended for further downstream usage, as well as weights for Cityscapes semantic segmentation. Use the included script fetch_pre_trained_weights.sh under the model_weights directory, to download the weights. Update 14 March 2024 We also release ImageNet Self Supervised Training weights, trained using PixPro, for downstream usage on tasks such as semantic segmentation, instance segmentation, scene depth, object detection etc.

Usage

This repository provides the model definitions for ImageNet image classification, and Cityscapes semantic segmentation, as well as code for evaluating on the respective datasets. The model definitions are split across files for deployment scenario based grouping. We also provide example model definitions for interfacing with training pipelines.

ImageNet evaluation

python scripts/evaluate_imagenet.py --gpu_id 0 --model_name classification_ffnet54S_BBX_mobile

Cityscapes evaluation

python scripts/evaluate_cityscapes.py --gpu_id 0 --model_name segmentation_ffnet40S_BBB_mobile_pre_down --fp16

Inference time evaluation

python scripts/evaluate_timing.py --num_iter 200 --gpu_id 0 --model_name segmentation_ffnet122NS_CBB_mobile

Model Documentation

GPU Models (Large)

Images of 1024x2048 are input to these models, and feature maps of 256x512 are output. These models provide a much better speed-accuracy tradeoff than HRNets, as shown in the paper. The 3-stage models (ffnet122N/74N/46N) also provide a much better speed-accuracy tradeoff than DDNets, FANets, and the models listed under "GPU Models (Small)". *= 3-stage FFNets

Comparisons of Large GPU Models

FFNet GPU LargeModel Name In RepoImageNet Backbone ModelCityscapes AccuracyFP32 (ms)FP16 (ms)
ResNet 101 A-A-Asegmentation_ffnet101_AAAclassification_ffnet101_AAX82.111959
ResNet 50 A-A-Asegmentation_ffnet50_AAAclassification_ffnet50_AAX79.68845
ResNet 150 A-A-Asegmentation_ffnet150_AAAclassification_ffnet150_AAX84.415281
ResNet 134 A-A-Asegmentation_ffnet134_AAAclassification_ffnet134_AAX84.113570
ResNet 86 A-A-Asegmentation_ffnet86_AAAclassification_ffnet86_AAX83.210555
ResNet 56 A-A-Asegmentation_ffnet56_AAAclassification_ffnet56_AAX82.58242
ResNet 34 A-A-Asegmentation_ffnet34_AAAclassification_ffnet34_AAX81.46734
ResNet 150 A-B-Bsegmentation_ffnet150_ABBclassification_ffnet150_AAX83.712571
ResNet 86 A-B-Bsegmentation_ffnet86_ABBclassification_ffnet86_AAX83.57845
ResNet 56 A-B-Bsegmentation_ffnet56_ABBclassification_ffnet56_AAX82.15632
ResNet 34 A-B-Bsegmentation_ffnet34_ABBclassification_ffnet34_AAX80.34125
ResNet 150 S B-B-Bsegmentation_ffnet150S_BBBclassification_ffnet150S_BBX84.110466
ResNet 86 S B-B-Bsegmentation_ffnet86S_BBBclassification_ffnet86S_BBX82.66743
ResNet 122 N C-B-B*segmentation_ffnet122N_CBBclassification_ffnet122N_CBX83.75844
ResNet 74 N C-B-B*segmentation_ffnet74N_CBBclassification_ffnet74N_CBX834232
ResNet 46 N C-B-B*segmentation_ffnet46N_CBBclassification_ffnet46N_CBX81.93427

GPU Models (Small)

Images of 1024x2048 are input to these models, and feature maps of 128x256 are output. These models provide a better speed-accuracy tradeoff than DDRNets and FANets, as shown in the paper.

Comparisons of Small GPU Models

FFNet GPU SmallModel Name In RepoImageNet Backbone ModelCityscapes AccuracyFP32 (ms)FP16 (ms)
ResNet 101 A-A-Asegmentation_ffnet101_dAAAclassification_ffnet101_AAX80.43629
ResNet 50 A-A-Asegmentation_ffnet50_dAAAclassification_ffnet50_AAX79.42720
ResNet 150 A-A-Asegmentation_ffnet150_dAAAclassification_ffnet150_AAX82.34137
ResNet 134 A-A-Asegmentation_ffnet134_dAAAclassification_ffnet134_AAX823835
ResNet 86 A-A-Asegmentation_ffnet86_dAAAclassification_ffnet86_AAX81.43028
ResNet 56 A-A-Asegmentation_ffnet56_dAAAclassification_ffnet56_AAX80.72522
ResNet 34 A-A-Asegmentation_ffnet34_dAAAclassification_ffnet34_AAX79.12118
ResNet 18 A-A-Asegmentation_ffnet18_dAAAclassification_ffnet18_AAX76.51914
ResNet 150 A-A-Csegmentation_ffnet150_dAACclassification_ffnet150_AAX81.93733
ResNet 86 A-A-Csegmentation_ffnet86_dAACclassification_ffnet86_AAX81.12626
ResNet 34 A-A-Csegmentation_ffnet34_dAACclassification_ffnet34_AAX79.11716
ResNet 18 A-A-Csegmentation_ffnet18_dAACclassification_ffnet18_AAX76.41512
ResNet 150 S B-B-Bsegmentation_ffnet150S_dBBBclassification_ffnet150S_BBX813134
ResNet 86 S B-B-Bsegmentation_ffnet86S_dBBBclassification_ffnet86S_BBX81.12326

Mobile Models

These are designed for on-device usage, but are also efficient on desktop GPUs. In that setting, better mileage can be obtained from these models by using bilinear or another upsampling in place of nearest neighbour upsampling. It is recommended to re-train the imagenet backbone if making such changes to the architecture. *= 3-stage FFNets

FFNet MobileModel Name In RepoImageNet Backbone ModelCityscapes AccuracyCityscapes Input SizeOutput Size
ResNet 86 S B-B-Bsegmentation_ffnet86S_dBBB_mobileclassification_ffnet86S_BBX_mobile81.51024x2048128x256
ResNet 78 S B-B-Bsegmentation_ffnet78S_dBBB_mobileclassification_ffnet78S_BBX_mobile81.31024x2048128x256
Resnet 54 S B-B-Bsegmentation_ffnet54S_dBBB_mobileclassification_ffnet54S_BBX_mobile80.81024x2048128x256
ResNet 40 S B-B-Bsegmentation_ffnet40S_dBBB_mobileclassification_ffnet40S_BBX_mobile79.21024x2048128x256
ResNet 150 S B-B-Bsegmentation_ffnet150S_BBB_mobile(_pre_down)classification_ffnet150S_BBX_mobile81.6512x1024128x256
ResNet 86 S B-B-Bsegmentation_ffnet86S_BBB_mobile(_pre_down)classification_ffnet86S_BBX_mobile80.9512x1024128x256
ResNet 78 S B-B-Bsegmentation_ffnet78S_BBB_mobile(_pre_down)classification_ffnet78S_BBX_mobile80.5512x1024128x256
Resnet 54 S B-B-Bsegmentation_ffnet54S_BBB_mobile(_pre_down)classification_ffnet54S_BBX_mobile80.2512x1024128x256
ResNet 40 S B-B-Bsegmentation_ffnet40S_BBB_mobile(_pre_down)classification_ffnet40S_BBX_mobile79.7512x1024128x256
ResNet 150 S B-C-Csegmentation_ffnet150S_BCC_mobile(_pre_down)classification_ffnet150S_BBX_mobile81.0512x1024128x256
ResNet 86 S B-C-Csegmentation_ffnet86S_BCC_mobile(_pre_down)classification_ffnet86S_BBX_mobile81.0512x1024128x256
ResNet 78 S B-C-Csegmentation_ffnet78S_BCC_mobile(_pre_down)classification_ffnet78S_BBX_mobile80.6512x1024128x256
Resnet 54 S B-C-Csegmentation_ffnet54S_BCC_mobile(_pre_down)classification_ffnet54S_BBX_mobile79.9512x1024128x256
ResNet 40 S B-C-Csegmentation_ffnet40S_BCC_mobile(_pre_down)classification_ffnet40S_BBX_mobile78.4512x1024128x256
FFNet 122 NS C-B-B*segmentation_ffnet122NS_CBB_mobile(_pre_down)classification_ffnet122NS_CBX_mobile79.3512x1024128x256
FFNet 74 NS C-B-B*segmentation_ffnet74NS_CBB_mobile(_pre_down)classification_ffnet74NS_CBX_mobile78.3512x1024128x256
FFNet 46 NS C-B-B*segmentation_ffnet46NS_CBB_mobile(_pre_down)classification_ffnet46NS_CBX_mobile77.5512x1024128x256
FFNet 122 NS C-C-C*segmentation_ffnet122NS_CCC_mobile(_pre_down)classification_ffnet122NS_CBX_mobile79.2512x1024128x256
FFNet 74 NS C-C-C*segmentation_ffnet74NS_CCC_mobile(_pre_down)classification_ffnet74NS_CBX_mobile77.8512x1024128x256
FFNet 46 NS C-C-C*segmentation_ffnet46NS_CCC_mobile(_pre_down)classification_ffnet46NS_CBX_mobile76.7512x1024128x256

Additional Notes

ImageNet training hyperparameters

The models are trained using timm LR (0.048 / (2*384)) * 128 * 8, batch size 128x8 or 192x6, epochs 150 Step LR scheduler, decay_epochs 2, using amp, decay_rate of 0.93, rmsproptf optimizer, opt_eps 1e-3 Warmup LR 1e-6, weight decay 4e-5, dropout rate 0.2, model ema, autoaugment rand-m9-mstd0.5, remode pixel, reprob 0.3 Some imagenet models can be made better initializers for Cityscapes by retraining them with a batch size of 192x6, starting from the first imagenet training run. FFNet150 is trained with 128x10, for 150 epochs.

Downstream training

Details of training on the cityscapes dataset are in the paper. The only aspect pertinent to other tasks / datasets may be initializing the up-head from scratch when finetuning from ImageNet weights. For Cityscapes we found it to consistently give better performance than when initialized with ImageNet weights.

Acknowledgements:

This repository adapts code from the following repositories:

which, in turn, borrows from Hierarchical Multi-Scale Attention(HMS): https://github.com/NVIDIA/semantic-segmentation

We would like to acknowledge the researchers who made these repositories open-source.

About

No description, website, or topics provided.

Resources

Stars

69 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages