You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cd ~/Desktop/workspace/yolov5
mkdir weight
cd weight
wget https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5n.pt
cd ~/Desktop/workspace/yolov5/data
gedit custom_dataset.yaml
1.7 custom_dataset.yaml content and change your configuration such as number of class and class names
train: /home/laitathei/Desktop/workspace/dataset/train.txt
val: /home/laitathei/Desktop/workspace/dataset/val.txt
test: /home/laitathei/Desktop/workspace/dataset/test.txt
test_xml: /home/laitathei/Desktop/workspace/dataset/annotations
# Classes
nc: 3 # number of classes
names: ['obstacle','human', 'injury'] # class names
1.9 Train result, best.pt and last.pt are FP32 format
100 epochs completed in 0.091 hours.
Optimizer stripped from runs/train/exp/weights/last.pt, 3.9MB
Optimizer stripped from runs/train/exp/weights/best.pt, 3.9MB
Validating runs/train/exp/weights/best.pt...
Fusing layers...
Model Summary: 213 layers, 1763224 parameters, 0 gradients, 4.2 GFLOPs
Class Images Labels P R mAP@.5 mAP@.5:.95: 100%|██████████| 2/2 [00:00<00:00, 3.06it/s]
all 55 215 0.986 0.977 0.994 0.916
obstacle 55 215 0.986 0.977 0.994 0.916
Results saved to runs/train/exp
2 TensorRT conversion
2.1 Convert best.pt->best.wts->best.engine in TensorRTx
2.2 Put the gen_wts.py into yolov5 folder
2.3 Convert best.wts->best.engine by gen_wts.py
cd ~/Desktop/workspace/yolov5
python3 gen_wts.py -w ./runs/train/exp/weights/best.pt -o ./runs/train/exp/weights/best.wts
## Below content will show if program success
YOLOv5 🚀 v6.1-11-g63ddb6f torch 1.10.2+cu113 CPU
2.4 Convert best.wts->best.engine by TensorRTx cmake and best.engine is FP16 format
cd ~/Desktop/workspace/tensorrtx/yolov5
mkdir build
cd build
## Place the best.wts into build folder
## update CLASS_NUM in yololayer.h if your model is trained on custom dataset
## before
static constexpr int CLASS_NUM = 80; // line 20
static constexpr int INPUT_H = 640; // line 21 yolov5's input height and width must be divisible by 32.
static constexpr int INPUT_W = 640; // line 22
## after
static constexpr int CLASS_NUM = 3; // line 20
static constexpr int INPUT_H = 640; // line 21 yolov5's input height and width must be divisible by 32.
static constexpr int INPUT_W = 640; // line 22
cmake ..
make
## Below content will show if program success
[100%] Linking CXX executable yolov5
[100%] Built target yolov5
sudo ./yolov5 -s best.wts best.engine n
## Below content will show if program success
Loading weights: best.wts
Building engine, please wait for a while...
Build engine successfully!
2.5 Inference the engine with ROS and realsensen D455 camera
2.6 Put inference_ros_trt_v2.py into tensorrtx/yolov5 folder
cd ~/Desktop/workspace/tensorrtx/yolov5
python3 inference_ros_trt_v2.py
## change the realsense camera topic, PLUGIN_LIBRARY, and engine_file_path if required
About
YOLOv5 in Pytorch and TensorRT with ROS system implementation