Skip to content

Commit

Permalink
Merge pull request #16 from Ar-Ray-code/feature/v0.2.1
Browse files Browse the repository at this point in the history
Feature/v0.2.1
  • Loading branch information
Ar-Ray-code authored Mar 26, 2022
2 parents 64ae29e + 37f819f commit 6772f05
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 152 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ YOLOX_outputs/
*.onnx
*.trt
*.engine
YOLOX/
YOLOX_outputs/
65 changes: 14 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
| CUDA | ||
| CUDA (FP16) | ||
| TensorRT (CUDA) || |
| OpenVINO || |
| OpenVINO || |

### Raspberry Pi4 🍓 + NCS2 + YOLOX-ROS

Expand All @@ -39,27 +39,29 @@ Check [GitHub Wiki](https://github.com/Ar-Ray-code/YOLOX-ROS/wiki/YOLOX-ROS---Ra

Install the dependent packages based on all tutorials.

### STEP 1 : YOLOX Installation
### STEP 1 : Download from GitHub

[YOLOX Installation (Python)](https://github.com/Megvii-BaseDetection/YOLOX#quick-start)
```bash
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
git clone https://github.com/Ar-Ray-code/yolox_ros.git --recursive
```

### STEP 2 : YOLOX Installation (yolox_rps_py)

```bash
git clone https://github.com/Megvii-BaseDetection/YOLOX.git
cd YOLOX
pip3 install -v -e .
bash YOLOX-ROS/yolox_ros_py/install_yolox_py.bash
```

### STEP 2 : Install YOLOX-ROS
### STEP 3 : Install YOLOX-ROS

```bash
source /opt/ros/foxy/setup.bash
sudo apt install ros-foxy-v4l2-camera
git clone --recursive https://github.com/Ar-Ray-code/yolox_ros.git ~/ros2_ws/src/yolox_ros/
cd ~/ros2_ws
colcon build --symlink-install # weights files will be installed automatically.
```

### (Step 2) Using CUDA
### (Step 3) Using CUDA

If you have NVIDIA Graphics, you can run YOLOX-ROS on GPU.

Expand All @@ -82,48 +84,9 @@ ros2 launch yolox_ros_py yolox_s_cpu.launch.py

</details>

<details>
<summary>C++ (OpenVINO)</summary>

- Docker Images is [Released](https://github.com/Ar-Ray-code/YOLOX-ROS/tree/main/yolox_ros_cpp).

## Requirements

- ROS2 Foxy
- OpenCV 4
- OpenVINO
- [bbox_ex_msgs](https://github.com/Ar-Ray-code/bbox_ex_msgs)

### Step1 : Installation

```bash
source /opt/ros/foxy/setup.bash
sudo apt install ros-foxy-v4l2-camera
## C++

source /opt/intel/openvino_2021/bin/setupvars.sh
cd ~/ros2_ws/src
git clone --recursive https://github.com/Ar-Ray-code/YOLOX-ROS.git
# Download onnx file and Convert to IR format.
./YOLOX-ROS/weights/openvino/install.bash yolox_nano
```

### Step2 : Demo

Connect your web camera.

```bash
source /opt/ros/foxy/setup.bash
source ~/ros2_ws/install/local_setup.bash
ros2 launch yolox_ros_cpp yolox_openvino.launch.py
```
</details>

<details>
<summary>C++ (TensorRT)</summary>

Docker Images is [Released](https://github.com/Ar-Ray-code/YOLOX-ROS/tree/main/yolox_ros_cpp).

</details>
Check [this URL](https://github.com/Ar-Ray-code/YOLOX-ROS/tree/main/yolox_ros_cpp).


## Topic
Expand Down
13 changes: 13 additions & 0 deletions weights/openvino/download_openvino_s.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SCRIPT_DIR=$(cd $(dirname $0); pwd)
cd $SCRIPT_DIR
YOLOX_S_OPENVINO_TAR="yolox_s_openvino.tar.gz"
# $SCRIPT_DIR/../weights/openvino/yolox_s.xml is exists
if [ -f "$SCRIPT_DIR/yolox_s.xml" ]; then
echo "yolox_s.xml is exists"
exit 0
else
wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/$YOLOX_S_OPENVINO_TAR -O $SCRIPT_DIR/$YOLOX_S_OPENVINO_TAR
tar -xvf $SCRIPT_DIR/$YOLOX_S_OPENVINO_TAR -C $SCRIPT_DIR/
rm $YOLOX_S_OPENVINO_TAR
fi
echo "Done. Please run `colcon build` to install."
11 changes: 11 additions & 0 deletions yolox_ros_py/install_yolox_py.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SCRIPT_DIR=$(cd $(dirname $0); pwd)
cd $SCRIPT_DIR
if [ -e "$SCRIPT_DIR/YOLOX/" ]; then
echo "YOLOX is exists"
exit 0
fi
git clone https://github.com/Megvii-BaseDetection/YOLOX.git
cd YOLOX
pip3 install -v -e .
mv setup.py _setup.py
mv setup.cfg _setup.cfg
41 changes: 0 additions & 41 deletions yolox_ros_py/launch/yolox_l.launch.py

This file was deleted.

2 changes: 1 addition & 1 deletion yolox_ros_py/launch/yolox_s.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def generate_launch_description():
parameters=[
{"image_size/width": 640},
{"image_size/height": 480},
{"yolo_type" : 'yolox-s'},
{"yolox_exp_py" : yolox_ros_share_dir+'/yolox_s.py'},
{"device" : 'gpu'},
{"fp16" : True},
{"fuse" : False},
Expand Down
2 changes: 1 addition & 1 deletion yolox_ros_py/launch/yolox_s_cpu.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def generate_launch_description():
parameters=[
{"image_size/width": 640},
{"image_size/height": 480},
{"yolo_type" : 'yolox-s'},
{"yolox_exp_py" : yolox_ros_share_dir+'/yolox_s.py'},
{"device" : 'cpu'},
{"fp16" : True},
{"fuse" : False},
Expand Down
30 changes: 0 additions & 30 deletions yolox_ros_py/launch/yolox_s_gpu_simple.launch.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from ament_index_python.packages import get_package_share_directory
from launch.launch_description_sources import PythonLaunchDescriptionSource

from urllib.request import urlretrieve
import os

def generate_launch_description():
yolox_ros_share_dir = get_package_share_directory('yolox_ros_py')

Expand Down Expand Up @@ -31,5 +34,5 @@ def generate_launch_description():
return launch.LaunchDescription([
webcam,
yolox_openvino,
rqt_graph
# rqt_graph
])
21 changes: 5 additions & 16 deletions yolox_ros_py/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
YOLOX_NANO_WEIGHTS = 'yolox_nano.pth'
YOLOX_TINY_WEIGHTS = 'yolox_tiny.pth'

BASE_LINK = 'https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/'
YOLOX_VERSION = '0.1.1rc0'

BASE_LINK = 'https://github.com/Megvii-BaseDetection/YOLOX/releases/download/'+YOLOX_VERSION+'/'
YOLOX_S_WEIGHTS_URL = BASE_LINK + YOLOX_S_WEIGHTS
YOLOX_M_WEIGHTS_URL = BASE_LINK + YOLOX_M_WEIGHTS
YOLOX_L_WEIGHTS_URL = BASE_LINK + YOLOX_L_WEIGHTS
Expand All @@ -38,21 +40,7 @@
if not os.path.exists(YOLOX_S_WEIGHTS_PATH):
urlretrieve(YOLOX_S_WEIGHTS_URL, YOLOX_S_WEIGHTS_PATH)

# if not os.path.exists(YOLOX_M_WEIGHTS_PATH):
# urlretrieve(YOLOX_M_WEIGHTS_URL, YOLOX_M_WEIGHTS_PATH)

# if not os.path.exists(YOLOX_L_WEIGHTS_PATH):
# urlretrieve(YOLOX_L_WEIGHTS_URL, YOLOX_L_WEIGHTS_PATH)

# if not os.path.exists(YOLOX_X_WEIGHTS_PATH):
# urlretrieve(YOLOX_X_WEIGHTS_URL, YOLOX_X_WEIGHTS_PATH)

# if not os.path.exists(YOLOX_DARKNET53_WEIGHTS_PATH):
# urlretrieve(YOLOX_DARKNET53_WEIGHTS_URL, YOLOX_DARKNET53_WEIGHTS_PATH)

# if not os.path.exists(YOLOX_NANO_WEIGHTS_PATH):
# urlretrieve(YOLOX_NANO_WEIGHTS_URL, YOLOX_NANO_WEIGHTS_PATH)

# Download examples
# if not os.path.exists(YOLOX_TINY_WEIGHTS_PATH):
# urlretrieve(YOLOX_TINY_WEIGHTS_URL, YOLOX_TINY_WEIGHTS_PATH)

Expand All @@ -68,6 +56,7 @@
(os.path.join('share', package_name), glob('./launch/*.launch.py')),
(os.path.join('share', package_name), glob('../weights/*.pth')),
(os.path.join('share', package_name), glob('../weights/openvino/*')),
(os.path.join('share', package_name), glob('./YOLOX/exps/default/*.py')),
],
install_requires=['setuptools'],
zip_safe=True,
Expand Down
14 changes: 6 additions & 8 deletions yolox_ros_py/yolox_ros_py/yolox_openvino.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import argparse
import logging as log
import os
import sys

import cv2
import numpy as np
Expand Down Expand Up @@ -126,7 +124,7 @@ def imageflow_callback(self,msg:Image) -> None:
_, _, h, w = self.net.input_info[self.input_blob].input_data.shape
mean = (0.485, 0.456, 0.406)
std = (0.229, 0.224, 0.225)
image, ratio = preprocess(origin_img, (h, w), mean, std)
image, ratio = preprocess(origin_img, (h, w))#, mean, std)

res = self.exec_net.infer(inputs={self.input_blob: image})
res = res[self.out_blob]
Expand All @@ -136,17 +134,17 @@ def imageflow_callback(self,msg:Image) -> None:

boxes = predictions[:, :4]
scores = predictions[:, 4, None] * predictions[:, 5:]
print(scores)
# print(scores)

boxes_xyxy = np.ones_like(boxes)
boxes_xyxy[:, 0] = boxes[:, 0] - boxes[:, 2]/2.
boxes_xyxy[:, 1] = boxes[:, 1] - boxes[:, 3]/2.
boxes_xyxy[:, 2] = boxes[:, 0] + boxes[:, 2]/2.
boxes_xyxy[:, 3] = boxes[:, 1] + boxes[:, 3]/2.
boxes_xyxy /= ratio
# boxes_xyxy /= ratio
dets = multiclass_nms(boxes_xyxy, scores, nms_thr=0.45, score_thr=0.1)

print(dets)
# print(dets)
if dets is not None:
final_boxes = dets[:, :4]
final_scores, final_cls_inds = dets[:, 4], dets[:, 5]
Expand All @@ -162,13 +160,13 @@ def imageflow_callback(self,msg:Image) -> None:

try:
bboxes = self.yolox2bboxes_msgs(dets[:, :4], final_scores, final_cls_inds, COCO_CLASSES, msg.header)
self.get_logger().info(f'bboxes: {bboxes}')
# self.get_logger().info(f'bboxes: {bboxes}')
if (self.imshow_isshow):
cv2.imshow("YOLOX",origin_img)
cv2.waitKey(1)

except:
self.get_logger().info('No object detected')
# self.get_logger().info('No object detected')
if (self.imshow_isshow):
cv2.imshow("YOLOX",origin_img)
cv2.waitKey(1)
Expand Down
13 changes: 10 additions & 3 deletions yolox_ros_py/yolox_ros_py/yolox_ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def setting_yolox_exp(self) -> None:

self.declare_parameter('imshow_isshow',True)

self.declare_parameter('yolo_type','yolox-s')
# self.declare_parameter('yolo_type','yolox-s')
self.declare_parameter('yolox_exp_py', '')

self.declare_parameter('fuse',False)
self.declare_parameter('trt', False)
self.declare_parameter('fp16', False)
Expand All @@ -152,11 +154,14 @@ def setting_yolox_exp(self) -> None:
self.declare_parameter('resize', 640)
self.declare_parameter('image_size/width', 640)
self.declare_parameter('image_size/height', 480)


# =============================================================
self.imshow_isshow = self.get_parameter('imshow_isshow').value

yolo_type = self.get_parameter('yolo_type').value
# yolo_type = self.get_parameter('yolo_type').value
exp_py = self.get_parameter('yolox_exp_py').value

fuse = self.get_parameter('fuse').value
trt = self.get_parameter('trt').value
fp16 = self.get_parameter('fp16').value
Expand All @@ -175,7 +180,9 @@ def setting_yolox_exp(self) -> None:

cudnn.benchmark = True

exp = get_exp(None, yolo_type)
# exp = get_exp(None, "yolox-s")
exp = get_exp(exp_py, None)


BASE_PATH = os.getcwd()
file_name = os.path.join(BASE_PATH, "YOLOX_PATH/")
Expand Down

0 comments on commit 6772f05

Please sign in to comment.