ηŽ‹ζž«02-Base Detection commited on
Commit
961f022
Β·
1 Parent(s): 40bc4d5

feat(YOLOX): update README and requirements.txt

Browse files
README.md CHANGED
@@ -3,11 +3,18 @@
3
 
4
  ## Introduction
5
  YOLOX is an anchor-free version of YOLO, with a simpler design but better performance! It aims to bridge the gap between research and industrial communities.
 
6
 
7
  <img src="assets/git_fig.png" width="1000" >
8
 
9
  ## Updates!!
10
- * 【2020/07/19】 We have released our technical report on Arxiv.
 
 
 
 
 
 
11
 
12
  ## Benchmark
13
 
@@ -31,22 +38,29 @@ YOLOX is an anchor-free version of YOLO, with a simpler design but better perfor
31
  <details>
32
  <summary>Installation</summary>
33
 
34
- Step1. Install [apex](https://github.com/NVIDIA/apex).
 
 
 
 
 
 
35
 
36
  ```shell
37
  git clone https://github.com/NVIDIA/apex
38
  cd apex
39
  pip3 install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
40
  ```
41
- Step2. Install YOLOX.
42
- ```bash
43
- $ git clone [email protected]:Megvii-BaseDetection/YOLOX.git
44
- $ cd yolox
45
- $ pip3 install -v -e . # or "python3 setup.py develop
46
  ```
47
 
48
  </details>
49
 
 
 
50
  <details>
51
  <summary>Demo</summary>
52
 
 
3
 
4
  ## Introduction
5
  YOLOX is an anchor-free version of YOLO, with a simpler design but better performance! It aims to bridge the gap between research and industrial communities.
6
+ For more details, please refer to our [Arxiv report]().
7
 
8
  <img src="assets/git_fig.png" width="1000" >
9
 
10
  ## Updates!!
11
+ * 【2020/07/19】 We have released our technical report on [Arxiv]().
12
+
13
+ ## Comming soon
14
+ - [ ] YOLOX-P6 and larger model.
15
+ - [ ] Obj365 pretrain.
16
+ - [ ] Transformer modules.
17
+ - [ ] More features in need.
18
 
19
  ## Benchmark
20
 
 
38
  <details>
39
  <summary>Installation</summary>
40
 
41
+ Step1. Install YOLOX.
42
+ ```shell
43
+ git clone [email protected]:Megvii-BaseDetection/YOLOX.git
44
+ cd yolox
45
+ pip3 install -U pip && pip3 install -v -e . # or python3 setup.py develop
46
+ ```
47
+ Step2. Install [apex](https://github.com/NVIDIA/apex).
48
 
49
  ```shell
50
  git clone https://github.com/NVIDIA/apex
51
  cd apex
52
  pip3 install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
53
  ```
54
+ Step3. Install [pycocotools](https://github.com/cocodataset/cocoapi).
55
+
56
+ ```shell
57
+ pip3 install cython; pip3 install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
 
58
  ```
59
 
60
  </details>
61
 
62
+ </details>
63
+
64
  <details>
65
  <summary>Demo</summary>
66
 
demo/TensorRT/cpp/README.md CHANGED
@@ -8,6 +8,8 @@ our C++ demo will not include the model converting or constructing like other te
8
 
9
  Follow the trt [python demo README](../python/README.md) to convert and save the serialized engine file.
10
 
 
 
11
 
12
  ## Step 2: build the demo
13
 
@@ -24,20 +26,14 @@ cmake ..
24
  make
25
  ```
26
 
27
- Move the 'model_trt.engine' file generated from Step 1 (saved at the exp output dir) to the build dir:
28
-
29
- ```shell
30
- mv /path/to/your/exp/output/dir/model_trt.engine .
31
- ```
32
-
33
  Then run the demo:
34
 
35
  ```shell
36
- ./yolox -d /your/path/to/yolox/assets
37
  ```
38
 
39
  or
40
 
41
  ```shell
42
- ./yolox -d <img dir>
43
  ```
 
8
 
9
  Follow the trt [python demo README](../python/README.md) to convert and save the serialized engine file.
10
 
11
+ Check the 'model_trt.engine' file generated from Step 1, which will automatically saved at the current demo dir.
12
+
13
 
14
  ## Step 2: build the demo
15
 
 
26
  make
27
  ```
28
 
 
 
 
 
 
 
29
  Then run the demo:
30
 
31
  ```shell
32
+ ./yolox ../model_trt.engine -i ../../../../assets/dog.jpg
33
  ```
34
 
35
  or
36
 
37
  ```shell
38
+ ./yolox <path/to/your/engine_file> -i <path/to/image>
39
  ```
demo/TensorRT/cpp/yolox.cpp CHANGED
@@ -230,25 +230,6 @@ float* blobFromImage(cv::Mat& img){
230
  }
231
 
232
 
233
- int read_files_in_dir(const char *p_dir_name, std::vector<std::string> &file_names) {
234
- DIR *p_dir = opendir(p_dir_name);
235
- if (p_dir == nullptr) {
236
- return -1;
237
- }
238
-
239
- struct dirent* p_file = nullptr;
240
- while ((p_file = readdir(p_dir)) != nullptr) {
241
- if (strcmp(p_file->d_name, ".") != 0 &&
242
- strcmp(p_file->d_name, "..") != 0) {
243
- std::string cur_file_name(p_file->d_name);
244
- file_names.push_back(cur_file_name);
245
- }
246
- }
247
-
248
- closedir(p_dir);
249
- return 0;
250
- }
251
-
252
  static void decode_outputs(float* prob, std::vector<Object>& objects, float scale, const int img_w, const int img_h) {
253
  std::vector<Object> proposals;
254
  std::vector<int> strides = {8, 16, 32};
@@ -432,7 +413,7 @@ static void draw_objects(const cv::Mat& bgr, const std::vector<Object>& objects,
432
  cv::FONT_HERSHEY_COMPLEX, 0.4, txt_color, 1);
433
  }
434
 
435
- cv::imwrite("_" + f, image);
436
  fprintf(stderr, "save vis file\n");
437
  /* cv::imshow("image", image); */
438
  /* cv::waitKey(0); */
@@ -482,8 +463,9 @@ int main(int argc, char** argv) {
482
  char *trtModelStream{nullptr};
483
  size_t size{0};
484
 
485
- if (argc == 3 && std::string(argv[1]) == "-d") {
486
- std::ifstream file("model_trt.engine", std::ios::binary);
 
487
  if (file.good()) {
488
  file.seekg(0, file.end);
489
  size = file.tellg();
@@ -496,15 +478,17 @@ int main(int argc, char** argv) {
496
  } else {
497
  std::cerr << "arguments not right!" << std::endl;
498
  std::cerr << "run 'python3 yolox/deploy/trt.py -n yolox-{tiny, s, m, l, x}' to serialize model first!" << std::endl;
499
- std::cerr << "./yolox -d ../samples // deserialize file and run inference" << std::endl;
 
500
  return -1;
501
  }
 
502
 
503
- std::vector<std::string> file_names;
504
- if (read_files_in_dir(argv[2], file_names) < 0) {
505
- std::cout << "read_files_in_dir failed." << std::endl;
506
- return -1;
507
- }
508
 
509
  IRuntime* runtime = createInferRuntime(gLogger);
510
  assert(runtime != nullptr);
@@ -520,33 +504,27 @@ int main(int argc, char** argv) {
520
  }
521
  static float* prob = new float[output_size];
522
 
523
- int fcount = 0;
524
- for (auto f: file_names) {
525
- fcount++;
526
- std::cout << fcount << " " << f << std::endl;
527
- cv::Mat img = cv::imread(std::string(argv[2]) + "/" + f);
528
- if (img.empty()) continue;
529
- int img_w = img.cols;
530
- int img_h = img.rows;
531
- cv::Mat pr_img = static_resize(img);
532
- std::cout << "blob image" << std::endl;
533
-
534
- float* blob;
535
- blob = blobFromImage(pr_img);
536
- float scale = std::min(INPUT_W / (img.cols*1.0), INPUT_H / (img.rows*1.0));
537
-
538
- // Run inference
539
- auto start = std::chrono::system_clock::now();
540
- doInference(*context, blob, prob, output_size, pr_img.size());
541
- auto end = std::chrono::system_clock::now();
542
- std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
543
-
544
- std::vector<Object> objects;
545
- decode_outputs(prob, objects, scale, img_w, img_h);
546
- draw_objects(img, objects, f);
547
- }
548
 
549
- // Destroy the engine
550
  context->destroy();
551
  engine->destroy();
552
  runtime->destroy();
 
230
  }
231
 
232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  static void decode_outputs(float* prob, std::vector<Object>& objects, float scale, const int img_w, const int img_h) {
234
  std::vector<Object> proposals;
235
  std::vector<int> strides = {8, 16, 32};
 
413
  cv::FONT_HERSHEY_COMPLEX, 0.4, txt_color, 1);
414
  }
415
 
416
+ cv::imwrite("det_res.jpg", image);
417
  fprintf(stderr, "save vis file\n");
418
  /* cv::imshow("image", image); */
419
  /* cv::waitKey(0); */
 
463
  char *trtModelStream{nullptr};
464
  size_t size{0};
465
 
466
+ if (argc == 4 && std::string(argv[2]) == "-i") {
467
+ const std::string engine_file_path {argv[1]};
468
+ std::ifstream file(engine_file_path, std::ios::binary);
469
  if (file.good()) {
470
  file.seekg(0, file.end);
471
  size = file.tellg();
 
478
  } else {
479
  std::cerr << "arguments not right!" << std::endl;
480
  std::cerr << "run 'python3 yolox/deploy/trt.py -n yolox-{tiny, s, m, l, x}' to serialize model first!" << std::endl;
481
+ std::cerr << "Then use the following command:" << std::endl;
482
+ std::cerr << "./yolox ../model_trt.engine -i ../../../assets/dog.jpg // deserialize file and run inference" << std::endl;
483
  return -1;
484
  }
485
+ const std::string input_image_path {argv[3]};
486
 
487
+ //std::vector<std::string> file_names;
488
+ //if (read_files_in_dir(argv[2], file_names) < 0) {
489
+ //std::cout << "read_files_in_dir failed." << std::endl;
490
+ //return -1;
491
+ //}
492
 
493
  IRuntime* runtime = createInferRuntime(gLogger);
494
  assert(runtime != nullptr);
 
504
  }
505
  static float* prob = new float[output_size];
506
 
507
+ cv::Mat img = cv::imread(input_image_path);
508
+ int img_w = img.cols;
509
+ int img_h = img.rows;
510
+ cv::Mat pr_img = static_resize(img);
511
+ std::cout << "blob image" << std::endl;
512
+
513
+ float* blob;
514
+ blob = blobFromImage(pr_img);
515
+ float scale = std::min(INPUT_W / (img.cols*1.0), INPUT_H / (img.rows*1.0));
516
+
517
+ // run inference
518
+ auto start = std::chrono::system_clock::now();
519
+ doInference(*context, blob, prob, output_size, pr_img.size());
520
+ auto end = std::chrono::system_clock::now();
521
+ std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
522
+
523
+ std::vector<Object> objects;
524
+ decode_outputs(prob, objects, scale, img_w, img_h);
525
+ draw_objects(img, objects, input_image_path);
 
 
 
 
 
 
526
 
527
+ // destroy the engine
528
  context->destroy();
529
  engine->destroy();
530
  runtime->destroy();
demo/TensorRT/python/README.md CHANGED
@@ -37,10 +37,10 @@ The converted model and the serialized engine file (for C++ demo) will be saved
37
  The TensorRT python demo is merged on our pytorch demo file, so you can run the pytorch demo command with ```--trt```.
38
 
39
  ```shell
40
- python tools/demo.py -n yolox-s --trt --conf 0.3 --nms 0.65 --tsize 640
41
  ```
42
  or
43
  ```shell
44
- python tools/demo.py -f exps/base/yolox_s.py --trt --conf 0.3 --nms 0.65 --tsize 640
45
  ```
46
 
 
37
  The TensorRT python demo is merged on our pytorch demo file, so you can run the pytorch demo command with ```--trt```.
38
 
39
  ```shell
40
+ python tools/demo.py image -n yolox-s --trt --save_result
41
  ```
42
  or
43
  ```shell
44
+ python tools/demo.py image -f exps/base/yolox_s.py --trt --save_result
45
  ```
46
 
requirements.txt CHANGED
@@ -4,14 +4,11 @@ opencv_python
4
  loguru
5
  scikit_image
6
  tqdm
7
- apex
8
  torchvision
9
- pycocotools
10
- apex
11
  Pillow
12
  skimage
13
  thop
14
  ninja
15
  tabulate
16
  tensorboard
17
- onnxruntime
 
4
  loguru
5
  scikit_image
6
  tqdm
 
7
  torchvision
 
 
8
  Pillow
9
  skimage
10
  thop
11
  ninja
12
  tabulate
13
  tensorboard
14
+ onnxruntime
setup.py CHANGED
@@ -47,6 +47,10 @@ with open("yolox/__init__.py", "r") as f:
47
  ).group(1)
48
 
49
 
 
 
 
 
50
  with open("README.md", "r") as f:
51
  long_description = f.read()
52
 
@@ -59,6 +63,7 @@ setuptools.setup(
59
  long_description=long_description,
60
  ext_modules=get_extensions(),
61
  classifiers=["Programming Language :: Python :: 3", "Operating System :: OS Independent"],
 
62
  cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension},
63
  packages=setuptools.find_packages(),
64
  )
 
47
  ).group(1)
48
 
49
 
50
+ with open("requirements.txt", "r") as f:
51
+ reqs = [x.strip() for x in f.readlines()]
52
+
53
+
54
  with open("README.md", "r") as f:
55
  long_description = f.read()
56
 
 
63
  long_description=long_description,
64
  ext_modules=get_extensions(),
65
  classifiers=["Programming Language :: Python :: 3", "Operating System :: OS Independent"],
66
+ install_requires=reqs,
67
  cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension},
68
  packages=setuptools.find_packages(),
69
  )
tools/demo.py CHANGED
@@ -15,7 +15,7 @@ import torch.backends.cudnn as cudnn
15
  from yolox.data.data_augment import preproc
16
  from yolox.data.datasets import COCO_CLASSES
17
  from yolox.exp import get_exp
18
- from yolox.utils import fuse_model, get_model_info, postprocess, setup_logger, vis, xyxy2xywh
19
 
20
  IMAGE_EXT = ['.jpg', '.jpeg', '.webp', '.bmp', '.png']
21
 
@@ -26,7 +26,7 @@ def make_parser():
26
  parser.add_argument("-expn", "--experiment-name", type=str, default=None)
27
  parser.add_argument("-n", "--name", type=str, default=None, help="model name")
28
 
29
- parser.add_argument('--path', default='./demo', help='path to images or video')
30
  parser.add_argument('--camid', type=int, default=0, help='webcam demo camera id')
31
  parser.add_argument(
32
  '--save_result', action='store_true',
 
15
  from yolox.data.data_augment import preproc
16
  from yolox.data.datasets import COCO_CLASSES
17
  from yolox.exp import get_exp
18
+ from yolox.utils import fuse_model, get_model_info, postprocess, setup_logger, vis
19
 
20
  IMAGE_EXT = ['.jpg', '.jpeg', '.webp', '.bmp', '.png']
21
 
 
26
  parser.add_argument("-expn", "--experiment-name", type=str, default=None)
27
  parser.add_argument("-n", "--name", type=str, default=None, help="model name")
28
 
29
+ parser.add_argument('--path', default='./assets/dog.jpg', help='path to images or video')
30
  parser.add_argument('--camid', type=int, default=0, help='webcam demo camera id')
31
  parser.add_argument(
32
  '--save_result', action='store_true',
tools/trt.py CHANGED
@@ -64,7 +64,7 @@ def main():
64
  torch.save(model_trt.state_dict(), os.path.join(file_name, 'model_trt.pth'))
65
  logger.info("Converted TensorRT model done.")
66
  engine_file = os.path.join(file_name, 'model_trt.engine')
67
- engine_file_demo = os.path.join('yolox', 'deploy', 'demo_trt_c++', 'model_trt.engine')
68
  with open(engine_file, 'wb') as f:
69
  f.write(model_trt.engine.serialize())
70
 
 
64
  torch.save(model_trt.state_dict(), os.path.join(file_name, 'model_trt.pth'))
65
  logger.info("Converted TensorRT model done.")
66
  engine_file = os.path.join(file_name, 'model_trt.engine')
67
+ engine_file_demo = os.path.join('demo', 'TensorRT', 'cpp', 'model_trt.engine')
68
  with open(engine_file, 'wb') as f:
69
  f.write(model_trt.engine.serialize())
70