Home

Awesome

Few-shot X-ray Prohibited Item Detection: A Benchmark and Weak-feature Enhancement Network (ACMMM 2022)

Language grade: Python This repo contains the implementation of our state-of-the-art fewshot object detector for X-ray prohibited items, described in our ACMMM 2022 paper, Few-shot X-ray Prohibited Item Detection: A Benchmark and Weak-feature Enhancement Network. WEN is built upon the codebase FsDet v0.1, which released by an ICML 2020 paper Frustratingly Simple Few-Shot Object Detection.

Installation

FsDet is built on Detectron2. But you don't need to build detectron2 seperately as this codebase is self-contained. You can follow the instructions below to install the dependencies and build FsDet. WEN functionalities are implemented as classand .py scripts in FsDet which therefore requires no extra build efforts.

Dependencies

Build

python setup.py build develop  # you might need sudo

Note: you may need to rebuild FsDet after reinstalling a different build of PyTorch.

Data preparation

Our experiments are conducted on two datasets: PASCAL VOC and X-ray FSOD.

Code Structure

The code structure follows Detectron2 v0.1.* and fsdet.

Train & Inference

Training

We follow the exact training procedure of FsDet and we use random initialization for novel weights. For a full description of training procedure, see here.

1. Stage 1: Training base detector.

python tools/train_net.py --num-gpus 3 \
        --config-file configs/RFS/base-training/R101_FPN_base_training_split1.yml

2. Random initialize weights for novel classes.

python tools/ckpt_surgery.py \
        --src1 checkpoints/rfs/faster_rcnn/faster_rcnn_R_101_FPN_base1/model_final.pth \
        --method randinit \
        --save-dir checkpoints/rfs/faster_rcnn/faster_rcnn_R_101_FPN_all1

This step will create a model_surgery.pth from model_final.pth.

3. Stage 2: Fine-tune for novel data.

python tools/train_net.py --num-gpus 3 \
        --config-file configs/RFS/split1/10shot_GPB_PFB_proloss.yml \
        --opts MODEL.WEIGHTS WEIGHTS_PATH

Where WEIGHTS_PATH points to the model_surgery.pth generated from the previous step. Or you can specify it in the configuration yml. The model parameters and prototype features will dumped to OUTPUT_DIR.

Evaluation

To evaluate the trained models, run

python tools/test_net.py --num-gpus 3 \
        --config-file configs/RFS/split1/10shot_GPB_PFB_proloss.yml \
        --eval-only \
        --opts MODEL.WEIGHTS WEIGHTS_PATH \
               MODEL.MODEL.ROI_HEADS.NOVEL_MODULE.INIT_FEATURE_WEIGHT PROTOTYPES_PATH

Where WEIGHTS_PATH points to the model parameters generated from the training process, and PROTOTYPES_PATH points to the prototype features generated from the training process.

Or you can specify TEST.EVAL_PERIOD in the configuation yml to evaluate during training.

The whole procedure can be seen in run_rfs.sh and run_voc.sh