Code Monkey home page Code Monkey logo

ma-ssd's Introduction

The pytorch implement of MA-SSD

This repository implements MA-SSD (Multi Attention SSD for Fast Detection of Small Objects). The implementation is based on the projects lufficc/SSD.

MA-SSD SSD
massd1 ssd1
massd2 ssd2

Experiment result

SSD table

New Features in This Implementation

  • Fast Small Object Detection MA-SSD outperforms SSD on detection especially in small object detection task. MA-SSD runs over 100 FPS on single RTX 2080 Ti GPU. In Quadro P2000 GPU, it also runs over 23 FPS(SSD is 28 FPS).
  • Neck Structure In ssd/modeling/neck/, you can add or modifiy neck module. Neck module always be employed between backbone and head.
  • Inference Speed Calculation While you running demo.py, it is not only detect objects in specify image folder but also calculate FPS for each image and avgerage FPS for all image.
  • Multi Attention Module
  • Feature Fusion Module

Installation

Requirements

  1. Python3
  2. PyTorch 1.0 or higher
  3. yacs
  4. Vizer
  5. GCC >= 4.9
  6. OpenCV

Installation Steps

git clone https://github.com/kevinchan04/MA-SSD.git
cd MA-SSD
# Required packages: torch torchvision yacs tqdm opencv-python vizer
pip install -r requirements.txt

# It's recommended to install the latest release of torch and torchvision.

Setting Up Datasets

Pascal VOC

For Pascal VOC dataset, make the folder structure like this:

VOC_ROOT
|__ VOC2007
    |_ JPEGImages
    |_ Annotations
    |_ ImageSets
    |_ SegmentationClass
|__ VOC2012
    |_ JPEGImages
    |_ Annotations
    |_ ImageSets
    |_ SegmentationClass
|__ ...

Where VOC_ROOT default is datasets folder in current project, you can create symlinks to datasets or export VOC_ROOT="/path/to/voc_root".

COCO

For COCO dataset, make the folder structure like this:

COCO_ROOT
|__ annotations
    |_ instances_valminusminival2014.json
    |_ instances_minival2014.json
    |_ instances_train2014.json
    |_ instances_val2014.json
    |_ ...
|__ train2014
    |_ <im-1-name>.jpg
    |_ ...
    |_ <im-N-name>.jpg
|__ val2014
    |_ <im-1-name>.jpg
    |_ ...
    |_ <im-N-name>.jpg
|__ ...

Where COCO_ROOT default is datasets folder in current project, you can create symlinks to datasets or export COCO_ROOT="/path/to/coco_root".

Evaluate

Single GPU evaluating

# for example, evaluate SSD300:
python test.py --config-file configs/vgg_att_ssd300_neckthreemed_voc0712.yaml --ckpt https://github.com/kevinchan04/MA-SSD/releases/download/1.0/vgg_att_ssd300_voc0712_neckthreemed.pth

Multi-GPU evaluating

# for example, evaluate SSD300 with 4 GPUs:
export NGPUS=4
python -m torch.distributed.launch --nproc_per_node=$NGPUS test.py --config-file configs/vgg_ssd300_voc0712.yaml --ckpt https://github.com/kevinchan04/MA-SSD/releases/download/1.0/vgg_att_ssd300_voc0712_neckthreemed.pth

Demo

Predicting image in a folder is simple, it will calculate avgerage speed of inference(FPS):

python demo.py --config-file configs/vgg_ssd300_voc0712.yaml --images_dir demo --ckpt https://github.com/kevinchan04/MA-SSD/releases/download/1.0/vgg_att_ssd300_voc0712_neckthreemed.pth

Then it will download and cache vgg_att_ssd300_voc0712_neckthreemed.pth automatically and predicted images with boxes, scores and label names will saved to demo/result folder by default.

Train

Single GPU training

# for example, train SSD300:
python train.py --config-file configs/vgg_att_ssd300_neckthreemed_voc0712.yaml

Multi-GPU training

# for example, train SSD300 with 4 GPUs:
export NGPUS=4
python -m torch.distributed.launch --nproc_per_node=$NGPUS train.py --config-file configs/vgg_att_ssd300_neckthreemed_voc0712.yaml 

The configuration files that I provide assume that we are running on single GPU. When changing number of GPUs, hyper-parameter (lr, max_iter, ...) will also changed. The learning rate is the sum of all GPUs, which means if you are training on 4 GPUs, lr should be set as 1e-3. According to our experiments, larger lr always requires more warm-up iterations. The max_iter also is the sum on all GPUs.

MODEL ZOO

Origin Paper:

VOC2007 test coco test-dev2015
SSD300* 77.2 25.1
SSD512* 79.8 28.8

COCO:

Backbone Neck Input Size box AP Model Size Download
VGG16 neckthreemed 300 26.5 372MB model

PASCAL VOC:

Backbone Neck Input Size mAP Model Size Download
VGG16 neckthreemed 300 79.9 307MB model

neckthreemed is multi attention with feature fusion neck. Please refer to paper with more details about comparsion with other methods.

ma-ssd's People

Contributors

anonymousaccv501 avatar kevinchan04 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sestars666

ma-ssd's Issues

Paper Reference

Hello,
Could you please share me the papers that you use for this implementation?
Thanks

demo.py

你好,感谢你的开源,不过我在运行demo的时候遇到了一个问题,Traceback (most recent call last):
File "demo.py", line 130, in
main()
File "demo.py", line 126, in main
is_save=True)
File "/opt/conda/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 15, in decorate_context
return func(*args, **kwargs)
File "demo.py", line 34, in run_demo
checkpointer.load(ckpt, use_latest=ckpt is None)
File "/app/MA-SSD/ssd/utils/checkpoint.py", line 68, in load
model.load_state_dict(checkpoint.pop("model"))
File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 847, in load_state_dict
self.class.name, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for SSDDetector:
Unexpected key(s) in state_dict: "neck.my_sp_attention.0.0.weight", "neck.my_sp_attention.0.1.weight", "neck.my_sp_attention.0.1.bias", "neck.my_sp_attention.0.1.running_mean", "neck.my_sp_attention.0.1.running_var", "neck.my_sp_attention.0.1.num_batches_tracked", "neck.my_sp_attention.0.3.weight", "neck.my_sp_attention.0.3.bias", "neck.my_sp_attention.0.4.weight", "neck.my_sp_attention.0.4.bias", "neck.my_sp_attention.0.4.running_mean", "neck.my_sp_attention.0.4.running_var", "neck.my_sp_attention.0.4.num_batches_tracked", "neck.my_sp_attention.0.6.weight", "neck.my_sp_attention.0.6.bias", "neck.my_sp_attention.0.7.weight", "neck.my_sp_attention.0.7.bias", "neck.my_sp_attention.0.7.running_mean", "neck.my_sp_attention.0.7.running_var", "neck.my_sp_attention.0.7.num_batches_tracked", "neck.my_sp_attention.0.9.weight", "neck.my_sp_attention.1.0.weight", "neck.my_sp_attention.1.1.weight", "neck.my_sp_attention.1.1.bias", "neck.my_sp_attention.1.1.running_mean", "neck.my_sp_attention.1.1.running_var", "neck.my_sp_attention.1.1.num_batches_tracked", "neck.my_sp_attention.1.3.weight", "neck.my_sp_attention.1.3.bias", "neck.my_sp_attention.1.4.weight", "neck.my_sp_attention.1.4.bias", "neck.my_sp_attention.1.4.running_mean", "neck.my_sp_attention.1.4.running_var", "neck.my_sp_attention.1.4.num_batches_tracked", "neck.my_sp_attention.1.6.weight", "neck.my_sp_attention.1.6.bias", "neck.my_sp_attention.1.7.weight", "neck.my_sp_attention.1.7.bias", "neck.my_sp_attention.1.7.running_mean", "neck.my_sp_attention.1.7.running_var", "neck.my_sp_attention.1.7.num_batches_tracked", "neck.my_sp_attention.1.9.weight", "neck.conv1x1_ch.0.weight", "neck.conv1x1_ch.0.bias", "neck.my_ch_attention.0.0.weight", "neck.my_ch_attention.0.2.weight", "neck.my_deconv.0.0.weight", "neck.my_deconv.0.0.bias", "neck.my_deconv.0.1.weight", "neck.my_deconv.0.1.bias", "neck.my_deconv.0.1.running_mean", "neck.my_deconv.0.1.running_var", "neck.my_deconv.0.1.num_batches_tracked", "neck.my_deconv.1.0.weight", "neck.my_deconv.1.0.bias", "neck.my_deconv.1.1.weight", "neck.my_deconv.1.1.bias", "neck.my_deconv.1.1.running_mean", "neck.my_deconv.1.1.running_var", "neck.my_deconv.1.1.num_batches_tracked".
size mismatch for box_head.predictor.cls_headers.0.weight: copying a param with shape torch.Size([126, 512, 3, 3]) from checkpoint, the shape in current model is torch.Size([84, 512, 3, 3]).
size mismatch for box_head.predictor.cls_headers.0.bias: copying a param with shape torch.Size([126]) from checkpoint, the shape in current model is torch.Size([84]).
我不知道是不是因为torch版本的原因导致加载模型错误,还麻烦你看看哈,我的torch版本是1.5

Request add new backbone

Hello,
Could you please add lightweight backbone such as mobilenet_v2 to work with neckthreemed
Thanks

About reference paper

Hello, I just saw your code today. Where can I find its reference paper?

Look forward to your reply, thanks!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.