File size: 4,222 Bytes
1cff332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
license: apache-2.0
tags:
- RyzenAI
- object-detection
- vision
- YOLO
- anchor-free
- pytorch
datasets:
- coco
metrics:
- mAP
---

# YOLOX-small model trained on COCO

YOLOX-small is the small version of YOLOX model trained on COCO object detection (118k annotated images) at resolution 640x640. It was introduced in the paper [YOLOX: Exceeding YOLO Series in 2021](https://arxiv.org/abs/2107.08430) by Zheng Ge et al. and first released in [this repository](https://github.com/Megvii-BaseDetection/YOLOX).

We develop a modified version that could be supported by [AMD Ryzen AI](https://ryzenai.docs.amd.com).


## Model description

Based on YOLO detector, the YOLOX model adopts anchor-free head and conducts other advanced detection techniques including decoupled head and the leading label assignment strategy SimOTA to achieve state-of-the-art results across a large scale range of models. The series of models were developed by Megvii Inc. and won the 1st Place on Streaming Perception Challenge (WAD at CVPR 2021).


## Intended uses & limitations

You can use the raw model for object detection. See the [model hub](https://huggingface.co/models?search=amd/yolox) to look for all available YOLOX models.


## How to use

### Installation

   Follow [Ryzen AI Installation](https://ryzenai.docs.amd.com/en/latest/inst.html) to prepare the environment for Ryzen AI.
   Run the following script to install pre-requisites for this model.
   ```sh
   pip install -r requirements.txt 
   ```


### Data Preparation (optional: for accuracy evaluation)

The dataset MSCOCO2017 contains 118287 images for training and 5000 images for validation.

Download the validation set of COCO dataset ([val2017.zip](http://images.cocodataset.org/zips/val2017.zip) and [annotations_trainval2017.zip](http://images.cocodataset.org/annotations/annotations_trainval2017.zip)). 
Then unzip the files and move them to the following directories (or create soft links):

  ```plain
  └── data
       └── COCO
             β”œβ”€β”€ annotations
             |   β”œβ”€β”€ instances_val2017.json
             |   └── ...
             └── val2017
                 β”œβ”€β”€ 000000000139.jpg
                 β”œβ”€β”€ 000000000285.jpg
                 └── ...
  ```


### Test & Evaluation

 - Code snippet from [`infer_onnx.py`](infer_onnx.py) on how to use
  ```python
  args = make_parser().parse_args()
  input_shape = tuple(map(int, args.input_shape.split(',')))
  origin_img = cv2.imread(args.image_path)
  img, ratio = preprocess(origin_img, input_shape)
  if args.ipu:
      providers = ["VitisAIExecutionProvider"]
      provider_options = [{"config_file": args.provider_config}]
  else:
      providers = ['CUDAExecutionProvider', 'CPUExecutionProvider']
      provider_options = None
  session = ort.InferenceSession(args.model, providers=providers, provider_options=provider_options)
  ort_inputs = {session.get_inputs()[0].name: img[None, :, :, :]}
  outputs = session.run(None, ort_inputs)
  dets = postprocess(outputs, input_shape, ratio)
  if dets is not None:
      final_boxes, final_scores, final_cls_inds = dets[:, :4], dets[:, 4], dets[:, 5]
      origin_img = vis(origin_img, final_boxes, final_scores, final_cls_inds,
                       conf=args.score_thr, class_names=COCO_CLASSES)
  mkdir(args.output_dir)
  output_path = os.path.join(args.output_dir, os.path.basename(args.image_path))
  cv2.imwrite(output_path, origin_img)
  ```

 - Run inference for a single image
  ```sh
  python infer_onnx.py -m yolox-s-int8.onnx -i Path\To\Your\Image --ipu --provider_config Path\To\vaip_config.json
  ```
  *Note: __vaip_config.json__ is located at the setup package of Ryzen AI (refer to [Installation](#installation))*

 - Test accuracy of the quantized model
  ```sh
  python eval_onnx.py -m yolox-s-int8.onnx --ipu --provider_config Path\To\vaip_config.json
  ```

### Performance

|Metric | Accuracy on IPU|
| :----:  | :----: |
|AP\@0.50:0.95|0.370|


```bibtex
 @article{yolox2021,
  title={YOLOX: Exceeding YOLO Series in 2021},
  author={Ge, Zheng and Liu, Songtao and Wang, Feng and Li, Zeming and Sun, Jian},
  journal={arXiv preprint arXiv:2107.08430},
  year={2021}
}
```