Git Product home page Git Product logo

lightray's Introduction

LightRay:Lightweight Network for Prohibited Items Detection in X-ray Images during Security Inspection

The code for the paper "LightRay:Lightweight Network for Prohibited Items Detection in X-ray Images during Security Inspection".

Requirements

python 3.9
pytorch 1.11.10
cuda 11.2

Dataset Preparation

1.This article uses the .xml format for training, and the SIXray https://github.com/MeioJane/SIXray dataset needs to be downloaded before training.
Subfiles (Annotations: label files, JPEGImages: SIXray images) after decompression are placed in the Xraydevkit/Xray2021 directory).
2.When training your own data set, you can create a cls_classes.txt by yourself, and write the classes you need to distinguish in it.
The content of the model_data/xray_classes.txt file is:

Gun
Knife
Wrench
Pliers
Scissors
...
(Note: Here you can change to the classes you need)

3.Modify the parameters in Xray_annotation.py # annotation_mode=0 # , # classes_path = 'model_data/xray_classes.txt' #

annotation_mode     = 0

classes_path        = 'model_data/xray_classes.txt'

trainval_percent    = 0.9
train_percent       = 0.9
(Note: The proportion of dataset divided according to needs.)

4.Run Xray_annotation.py to generate 2021_train.txt and 2021_val.txt in the root directory.

Train

1.The Pretrained weights required for training can be downloaded from Google Cloud Drive.
After downloading the library, unzip it, download LightRay.pth or yolov4_mobilenet_v3_voc.pth in Google Cloud Drive, and put it into model_data.
Link: https://drive.google.com/drive/folders/1kvPGOsXfVgRblXxB4sjB-wKBE42po3ya?usp=sharing
2.The default parameters of train.py are used to train the VOC dataset, and the training can be started directly by running train.py.
Before training classes_path, make it correspond to its own dataset path as the target class.
3.Modify parameters of train.py:

classes_path = 'model_data/xray_classes.txt'
anchors_path = 'model_data/yolo_anchors.txt'
......
model_path = 'model_data/LightRay.pth' 
(Note: LightRay.pth is the Pretrained weights of the SIXray dataset. yolov4_mobilenet_v3_voc.pth is the Pretrained weights of the voc dataset.)

4.train.py. After modifying the classes_path, you can run train.py to start training. After training multiple epochs, the weights will be generated in the logs folder.

Evaluate (mAP)

1.Modify model_path and classes_path in yolo.py:

"model_path"        : 'model_data/ ',  

"classes_path"      : 'model_data/xray_classes.txt',
(Note: This can be modified as needed.)

2.model_path points to the trained weights file in the logs folder(Select a trained weight you want under the logs file and put it in model_data/ ).
3.Run mAP.py. The evaluation results are saved in the map_out folder.

Prediction

1.Training result prediction requires two files, yolo.py and predict.py. Modify model_path and classes_path in yolo.py.
2.model_path points to the trained weights file in the logs folder(Select a trained weight you want under the logs file and put it in model_data/ ). classes_path points to the txt corresponding to the detection classes in yolo.py:

"model_path"        : 'model_data/ ',  

"classes_path"      : 'model_data/xray_classes.txt',
(Note: Other parameters can be modified as required.)

3.Run predict.py. After completing the modification, you can run predict.py for detection. After running, enter the image path to detect.

Citation

If this work helps your research, please cite the following paper.

@article{ren2022lightray,
title={LightRay: Lightweight network for prohibited items detection in X-ray images during security inspection},
author={Ren, Yu and Zhang, Haigang and Sun, Hongxing and Ma, Guanglin and Ren, Jin and Yang, Jinfeng},
journal={Computers and Electrical Engineering},
volume={103},
pages={108283},
year={2022},
publisher={Elsevier}
}

Acknowledgement

lightray's People

Contributors

abcdea avatar zhg-szpt avatar

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.