Home

Awesome

HCGNets: Gated Convolutional Networks with Hybrid Connectivity for Image Classification

This project provides source code for our AAAI-2020 paper HCGNet.

Installation

Requirements

Ubuntu 16.04 LTS

Python 3 (Anaconda is recommended)

CUDA 9 or newer

PyTorch 0.4 or newer

NVIDIA NCCL

Foolbox

MMDection

Clone the repo

$ git clone https://github.com/winycg/HCGNet.git
$ cd HCGNet

Some tweaks

USE pillow-simd to speed up pytorch image loader (assume Anaconda is used)

$ pip uninstall pillow
$ conda uninstall --force jpeg libtiff -y
$ conda install -c conda-forge libjpeg-turbo
$ CC="cc -mavx2" pip install --no-cache-dir -U --force-reinstall --no-binary :all: --compile pillow-simd

Perform training on CIFAR dataset

Training

python main_cifar.py --dataset cifar10 --arch HCGNet_A1

Results

ModelParamsFLOPSCIFAR-10CIFAR-100
HCGNet-A11.1M0.16G3.1518.13
HCGNet-A23.1M0.50G2.2916.54
HCGNet-A311.4M1.99G2.1415.96

Perform training and evaluation on ImageNet dataset

Dataset preparation

$ cd HCGNet
$ mkdir data
$ ln -s PATH_TO_YOUR_IMAGENET ./data/

Training

python -m torch.distributed.launch --nproc_per_node=2 main_imagenet.py --arch HCGNet_B --gpu-id 0,1

Need NCCL library:

Evaluation

When the training finishes, the best model file HCGNet_B_best.pth.tar is saved in ./checkpoint/.

python -m torch.distributed.launch --nproc_per_node=2 main_imagenet.py --arch HCGNet_B --gpu-id 0,1 --resume --checkpoint ./checkpoint/HCGNet_B_best.pth.tar --evaluate 

Results

ModelParamsFLOPSTop-1Top-5Pretrained model
HCGNet-B12.9M2.0G21.55.9HCGNet_B_best.pth.tar
HCGNet-C42.2M7.0G19.364.93HCGNet_C_best.pth.tar

Interpretability by network dissection

Reference

Network dissection method is proposed by Network Dissection: Quantifying Interpretability of Deep Visual Representations paper. Our experiemnts refer the official implementation: https://github.com/CSAILVision/NetDissect-Lite

Evaluation

Evaluation on interpretability based on the ImageNet pretrained model HCGNet-B:

cd network_dissection/
python main.py

You may only modify the settings.py and loader/model_loader.py to implement your requirements.

Results

Generated result files of HCGNet_B can be downloaded Here. We compare the unique detectors of HCGNet-B against other popular SOTA models as follows:

interpretability

Adversarial robustness by FGSM attack

Reference

FGSM (Fast gradient sign mthod) is proposed by Explaining and harnessing adversarial examples paper. Our experiemnts refer the implementation by foolbox .

Evaluation

Evaluation on adversarial robustness based on ImageNet pretrained models: HCGNet-B and other popular networks:

cd FGSM_attack/
python attack.py

Results

Attack models with different perturbation energies:0.001~0.005. We report top-1 accuracy on ImageNet validation set after attacking.

Model0.0000.0010.0020.0030.0040.005
ResNet-500.7620.3840.2280.1580.1210.102
DenseNet-1690.7600.3530.1940.1250.0940.077
ResNeXt-500.7760.3820.2390.1770.1480.131
Wide ResNet-500.7850.4390.2790.2020.1620.139
HCGNet-B0.7850.4800.4150.3860.3700.360

Object detection and segmentation

We experiment HCGNet-B pretrained on ImageNet as a backbone on the Mask-RCNN system to implement object detection and instance segmentation tasks.

Prerequisites:

You need to install MMDection at first and obtain a mmdetection folder. Then you need to move the detection/hcgnet.py and detection/__init__.py to mmdetection/mmdet/models/backbones/ , as well as detection/hcgnet_config.py to mmdetection/configs/ in your folder.

Training

./tools/dist_train.sh configs/hcgnet_config.py 2 --validate

Evaluation

You can download our pretrained detection and segmentation model file from HCGNet_detection.pth. You need to configure the path of HCGNet-B pretrained model by pretrained key in hcgnet_config.py .

./tools/dist_test.sh configs/hcgnet_config.py \ checkpoints/HCGNet_detection.pth \
2 --out results.pkl --eval bbox segm

Results

ModelParamsFLOPsbox APbox AP_50box AP_75seg APseg AP_50seg AP_75
ResNet-50-FPN44.2M275.6G37.359.940.234.255.936.2
HCGNet-B-FPN32.1M230.4G38.360.641.335.257.537.1

Citation

@inproceedings{yang2020gated,
  title={Gated Convolutional Networks with Hybrid Connectivity for Image Classification},
  author={Yang, Chuanguang and An, Zhulin and Zhu, Hui and Hu, Xiaolong and Zhang, Kun and Xu, Kaiqiang and Li, Chao and Xu, Yongjun},
  booktitle={Thirty-Fourth AAAI Conference on Artificial Intelligence},
  pages = {12581--12588},
  year={2020}
}

Contact

Please feel free to report issues and any related problems to Chuanguang Yang (yangchuanguang@ict.ac.cn).

License

HCGNets related codes are under RESEARCH ONLY LICENSE.