Skip to content

Commit 4d1b76d

Browse files
authored
Merge pull request #18 from Ar-Ray-code/features/yolox_ros_0.3.0
Features/yolox ros 0.3.0
2 parents 4ad6d5e + 17ba9ff commit 4d1b76d

12 files changed

+363
-78
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Check [GitHub Wiki](https://github.com/Ar-Ray-code/YOLOX-ROS/wiki/YOLOX-ROS---Ra
3232
- OpenCV 4
3333
- Python 3.8 (Ubuntu 20.04 Default)
3434
- PyTorch >= v1.7
35-
- [YOLOX v0.2.0](https://github.com/Megvii-BaseDetection/YOLOX)
35+
- [YOLOX v0.3.0](https://github.com/Megvii-BaseDetection/YOLOX)
3636
- [bbox_ex_msgs](https://github.com/Ar-Ray-code/bbox_ex_msgs)
3737

3838
## Installation
@@ -50,15 +50,15 @@ git clone https://github.com/Ar-Ray-code/yolox_ros.git --recursive
5050
### STEP 2 : YOLOX Installation (yolox_rps_py)
5151

5252
```bash
53-
bash YOLOX-ROS/yolox_ros_py/install_yolox_py.bash
53+
pip3 install yolox
5454
```
5555

5656
### STEP 3 : Install YOLOX-ROS
5757

5858
```bash
5959
source /opt/ros/foxy/setup.bash
6060
sudo apt install ros-foxy-v4l2-camera
61-
colcon build --symlink-install # weights files will be installed automatically.
61+
colcon build --symlink-install # weights (YOLOX-Nano) files will be installed automatically.
6262
```
6363

6464
### (Step 3) Using CUDA
@@ -78,8 +78,13 @@ Connect your web camera.
7878
```bash
7979
source /opt/ros/foxy/setup.bash
8080
source ~/ros2_ws/install/local_setup.bash
81-
ros2 launch yolox_ros_py yolox_s_cpu.launch.py
82-
# ros2 launch yolox_ros_py yolox_s.launch.py # <- GPU
81+
ros2 launch yolox_ros_py yolox_nano_cpu.launch.py
82+
# ros2 launch yolox_ros_py yolox_nano.launch.py # <- GPU
83+
# ros2 launch yolox_ros_py yolox_nano_onnx.launch.py # <- ONNXRuntime
84+
85+
# OpenVINO ---
86+
# source /opt/intel/openvino_2021/bin/setupvars.sh
87+
# ros2 launch yolox_ros_py yolox_nano_openvino.launch.py # <- OpenVINO
8388
```
8489

8590
</details>

yolox_ros_py/exps/yolox_nano.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
# -*- coding:utf-8 -*-
3+
# Copyright (c) Megvii, Inc. and its affiliates.
4+
5+
import os
6+
7+
import torch.nn as nn
8+
9+
from yolox.exp import Exp as MyExp
10+
11+
12+
class Exp(MyExp):
13+
def __init__(self):
14+
super(Exp, self).__init__()
15+
self.depth = 0.33
16+
self.width = 0.25
17+
self.input_size = (416, 416)
18+
self.random_size = (10, 20)
19+
self.mosaic_scale = (0.5, 1.5)
20+
self.test_size = (416, 416)
21+
self.mosaic_prob = 0.5
22+
self.enable_mixup = False
23+
self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
24+
25+
def get_model(self, sublinear=False):
26+
27+
def init_yolo(M):
28+
for m in M.modules():
29+
if isinstance(m, nn.BatchNorm2d):
30+
m.eps = 1e-3
31+
m.momentum = 0.03
32+
if "model" not in self.__dict__:
33+
from yolox.models import YOLOX, YOLOPAFPN, YOLOXHead
34+
in_channels = [256, 512, 1024]
35+
# NANO model use depthwise = True, which is main difference.
36+
backbone = YOLOPAFPN(
37+
self.depth, self.width, in_channels=in_channels,
38+
act=self.act, depthwise=True,
39+
)
40+
head = YOLOXHead(
41+
self.num_classes, self.width, in_channels=in_channels,
42+
act=self.act, depthwise=True
43+
)
44+
self.model = YOLOX(backbone, head)
45+
46+
self.model.apply(init_yolo)
47+
self.model.head.initialize_biases(1e-2)
48+
return self.model

yolox_ros_py/install_yolox_py.bash

Lines changed: 0 additions & 11 deletions
This file was deleted.

yolox_ros_py/launch/yolox_s.launch.py renamed to yolox_ros_py/launch/yolox_nano.launch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ def generate_launch_description():
1919
parameters=[
2020
{"image_size/width": 640},
2121
{"image_size/height": 480},
22-
{"yolox_exp_py" : yolox_ros_share_dir+'/yolox_s.py'},
22+
{"yolox_exp_py" : yolox_ros_share_dir+'/yolox_nano.py'},
2323
{"device" : 'gpu'},
2424
{"fp16" : True},
2525
{"fuse" : False},
2626
{"legacy" : False},
2727
{"trt" : False},
28-
{"ckpt" : yolox_ros_share_dir+"/yolox_s.pth"},
28+
{"ckpt" : yolox_ros_share_dir+"/yolox_nano.pth"},
2929
{"conf" : 0.3},
3030
{"threshold" : 0.65},
3131
{"resize" : 640},

yolox_ros_py/launch/yolox_s_cpu.launch.py renamed to yolox_ros_py/launch/yolox_nano_cpu.launch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ def generate_launch_description():
1919
parameters=[
2020
{"image_size/width": 640},
2121
{"image_size/height": 480},
22-
{"yolox_exp_py" : yolox_ros_share_dir+'/yolox_s.py'},
22+
{"yolox_exp_py" : yolox_ros_share_dir+'/yolox_nano.py'},
2323
{"device" : 'cpu'},
2424
{"fp16" : True},
2525
{"fuse" : False},
2626
{"legacy" : False},
2727
{"trt" : False},
28-
{"ckpt" : yolox_ros_share_dir+"/yolox_s.pth"},
28+
{"ckpt" : yolox_ros_share_dir+"/yolox_nano.pth"},
2929
{"conf" : 0.3},
3030
{"threshold" : 0.65},
3131
{"resize" : 640},
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import launch
2+
import launch_ros.actions
3+
from launch.actions import IncludeLaunchDescription
4+
from ament_index_python.packages import get_package_share_directory
5+
from launch.launch_description_sources import PythonLaunchDescriptionSource
6+
7+
from urllib.request import urlretrieve
8+
import os
9+
10+
def generate_launch_description():
11+
yolox_ros_share_dir = get_package_share_directory('yolox_ros_py')
12+
13+
webcam = launch_ros.actions.Node(
14+
package="v4l2_camera", executable="v4l2_camera_node",
15+
parameters=[
16+
{"image_size": [640,480]},
17+
],
18+
)
19+
yolox_openvino = launch_ros.actions.Node(
20+
package="yolox_ros_py", executable="yolox_onnx",output="screen",
21+
parameters=[
22+
{"image_size/width": 640},
23+
{"image_size/height": 480},
24+
25+
{"input_shape/width": 416},
26+
{"input_shape/height": 416},
27+
28+
{"with_p6" : False},
29+
{"model_path" : yolox_ros_share_dir+"/yolox_nano.onnx"},
30+
{"conf" : 0.3},
31+
],
32+
)
33+
34+
rqt_graph = launch_ros.actions.Node(
35+
package="rqt_graph", executable="rqt_graph",
36+
)
37+
38+
return launch.LaunchDescription([
39+
webcam,
40+
yolox_openvino,
41+
# rqt_graph
42+
])

yolox_ros_py/launch/yolox_s_openvino.launch.py renamed to yolox_ros_py/launch/yolox_nano_openvino.launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def generate_launch_description():
2222
{"image_size/width": 640},
2323
{"image_size/height": 480},
2424
{"device" : 'CPU'},
25-
{"model_path" : yolox_ros_share_dir+"/yolox_s.xml"},
25+
{"model_path" : yolox_ros_share_dir+"/yolox_nano.onnx"},
2626
{"conf" : 0.3},
2727
],
2828
)

yolox_ros_py/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
33
<package format="3">
44
<name>yolox_ros_py</name>
5-
<version>0.2.1</version>
5+
<version>0.3.0</version>
66
<description>The yolox_ros_py package</description>
77
<maintainer email="[email protected]">Ar-Ray-code</maintainer>
88
<license>Apache License, Version 2.0</license>

yolox_ros_py/setup.py

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,67 @@
77
package_name = 'yolox_ros_py'
88

99

10-
YOLOX_S_WEIGHTS = 'yolox_s.pth'
11-
YOLOX_M_WEIGHTS = 'yolox_m.pth'
12-
YOLOX_L_WEIGHTS = 'yolox_l.pth'
13-
YOLOX_X_WEIGHTS = 'yolox_x.pth'
14-
YOLOX_DARKNET53_WEIGHTS = 'yolox_darknet53.pth'
15-
YOLOX_NANO_WEIGHTS = 'yolox_nano.pth'
16-
YOLOX_TINY_WEIGHTS = 'yolox_tiny.pth'
10+
YOLOX_S = 'yolox_s'
11+
YOLOX_M = 'yolox_m'
12+
YOLOX_L = 'yolox_l'
13+
YOLOX_X = 'yolox_x'
14+
YOLOX_DARKNET53 = 'yolox_darknet53'
15+
YOLOX_NANO = 'yolox_nano'
16+
YOLOX_TINY = 'yolox_tiny'
17+
18+
PTH = '.pth'
19+
ONNX = '.onnx'
1720

1821
YOLOX_VERSION = '0.1.1rc0'
1922

2023
BASE_LINK = 'https://github.com/Megvii-BaseDetection/YOLOX/releases/download/'+YOLOX_VERSION+'/'
21-
YOLOX_S_WEIGHTS_URL = BASE_LINK + YOLOX_S_WEIGHTS
22-
YOLOX_M_WEIGHTS_URL = BASE_LINK + YOLOX_M_WEIGHTS
23-
YOLOX_L_WEIGHTS_URL = BASE_LINK + YOLOX_L_WEIGHTS
24-
YOLOX_X_WEIGHTS_URL = BASE_LINK + YOLOX_X_WEIGHTS
25-
YOLOX_DARKNET53_WEIGHTS_URL = BASE_LINK + YOLOX_DARKNET53_WEIGHTS
26-
YOLOX_NANO_WEIGHTS_URL = BASE_LINK + YOLOX_NANO_WEIGHTS
27-
YOLOX_TINY_WEIGHTS_URL = BASE_LINK + YOLOX_TINY_WEIGHTS
24+
# .pth
25+
YOLOX_S_URL = BASE_LINK + YOLOX_S + PTH
26+
YOLOX_M_URL = BASE_LINK + YOLOX_M + PTH
27+
YOLOX_L_URL = BASE_LINK + YOLOX_L + PTH
28+
YOLOX_X_URL = BASE_LINK + YOLOX_X + PTH
29+
YOLOX_X_URL = BASE_LINK + YOLOX_DARKNET53 + PTH
30+
YOLOX_NANO_URL = BASE_LINK + YOLOX_NANO + PTH
31+
YOLOX_TINY_URL = BASE_LINK + YOLOX_TINY + PTH
32+
# .onnx
33+
YOLOX_S_ONNX_URL = BASE_LINK + YOLOX_S + ONNX
34+
YOLOX_M_ONNX_URL = BASE_LINK + YOLOX_M + ONNX
35+
YOLOX_L_ONNX_URL = BASE_LINK + YOLOX_L + ONNX
36+
YOLOX_X_ONNX_URL = BASE_LINK + YOLOX_X + ONNX
37+
YOLOX_X_ONNX_URL = BASE_LINK + YOLOX_DARKNET53 + ONNX
38+
YOLOX_NANO_ONNX_URL = BASE_LINK + YOLOX_NANO + ONNX
39+
YOLOX_TINY_ONNX_URL = BASE_LINK + YOLOX_TINY + ONNX
2840

2941
BASE_PATH = os.getcwd() + '/../weights/'
3042
os.makedirs(BASE_PATH, exist_ok=True)
31-
YOLOX_S_WEIGHTS_PATH = BASE_PATH + YOLOX_S_WEIGHTS
32-
YOLOX_M_WEIGHTS_PATH = BASE_PATH + YOLOX_M_WEIGHTS
33-
YOLOX_L_WEIGHTS_PATH = BASE_PATH + YOLOX_L_WEIGHTS
34-
YOLOX_X_WEIGHTS_PATH = BASE_PATH + YOLOX_X_WEIGHTS
35-
YOLOX_DARKNET53_WEIGHTS_PATH = BASE_PATH + YOLOX_DARKNET53_WEIGHTS
36-
YOLOX_NANO_WEIGHTS_PATH = BASE_PATH + YOLOX_NANO_WEIGHTS
37-
YOLOX_TINY_WEIGHTS_PATH = BASE_PATH + YOLOX_TINY_WEIGHTS
38-
39-
# Download YOLOX-S Weights
40-
if not os.path.exists(YOLOX_S_WEIGHTS_PATH):
41-
urlretrieve(YOLOX_S_WEIGHTS_URL, YOLOX_S_WEIGHTS_PATH)
43+
# .pth
44+
YOLOX_S_PATH = BASE_PATH + YOLOX_S + PTH
45+
YOLOX_M_PATH = BASE_PATH + YOLOX_M + PTH
46+
YOLOX_L_PATH = BASE_PATH + YOLOX_L + PTH
47+
YOLOX_X_PATH = BASE_PATH + YOLOX_X + PTH
48+
YOLOX_DARKNET53_PATH = BASE_PATH + YOLOX_DARKNET53 + PTH
49+
YOLOX_NANO_PATH = BASE_PATH + YOLOX_NANO + PTH
50+
YOLOX_TINY_PATH = BASE_PATH + YOLOX_TINY + PTH
51+
# .onnx
52+
YOLOX_S_ONNX_PATH = BASE_PATH + YOLOX_S + ONNX
53+
YOLOX_M_ONNX_PATH = BASE_PATH + YOLOX_M + ONNX
54+
YOLOX_L_ONNX_PATH = BASE_PATH + YOLOX_L + ONNX
55+
YOLOX_X_ONNX_PATH = BASE_PATH + YOLOX_X + ONNX
56+
YOLOX_DARKNET53_ONNX_PATH = BASE_PATH + YOLOX_DARKNET53 + ONNX
57+
YOLOX_NANO_ONNX_PATH = BASE_PATH + YOLOX_NANO + ONNX
58+
YOLOX_TINY_ONNX_PATH = BASE_PATH + YOLOX_TINY + ONNX
4259

43-
# Download examples
44-
# if not os.path.exists(YOLOX_TINY_WEIGHTS_PATH):
45-
# urlretrieve(YOLOX_TINY_WEIGHTS_URL, YOLOX_TINY_WEIGHTS_PATH)
60+
# Download YOLOX-NANO Weights
61+
if not os.path.exists(YOLOX_NANO_PATH):
62+
urlretrieve(YOLOX_NANO_URL, YOLOX_NANO_PATH)
63+
# Download YOLOX-NANO ONNX
64+
if not os.path.exists(YOLOX_NANO_ONNX_PATH):
65+
urlretrieve(YOLOX_NANO_ONNX_URL, YOLOX_NANO_ONNX_PATH)
4666

4767

4868
setup(
4969
name=package_name,
50-
version='0.2.0',
70+
version='0.3.0',
5171
packages=[package_name],
5272
data_files=[
5373
('share/ament_index/resource_index/packages',
@@ -56,7 +76,8 @@
5676
(os.path.join('share', package_name), glob('./launch/*.launch.py')),
5777
(os.path.join('share', package_name), glob('../weights/*.pth')),
5878
(os.path.join('share', package_name), glob('../weights/openvino/*')),
59-
(os.path.join('share', package_name), glob('./YOLOX/exps/default/*.py')),
79+
(os.path.join('share', package_name), glob('../weights/onnx/*')),
80+
(os.path.join('share', package_name), glob('./exps/*.py')),
6081
],
6182
install_requires=['setuptools'],
6283
zip_safe=True,
@@ -71,6 +92,7 @@
7192
'console_scripts': [
7293
'yolox_ros = '+package_name+'.yolox_ros:ros_main',
7394
'yolox_openvino = '+package_name+'.yolox_openvino:ros_main',
95+
'yolox_onnx = '+package_name+'.yolox_onnx:ros_main',
7496
],
7597
},
7698
)

0 commit comments

Comments
 (0)