網頁

2022年2月16日 星期三

yolo v4 to TensorRt

參考: tensorrt_demos

$ cd TensorRT
$ git clone https://github.com/jkjung-avt/tensorrt_demos.git
$ cd tensorrt_demos

安裝環境
$ cd yolo
$ ./install_pycuda.sh
$ pip3 install onnx==1.4.1
$ cd ../plugins
$ make

下載 yolo 的 weights 和 cfg
$ cd ../yolo
$ ./download_yolo.sh
轉換 weights 到 trt
$ python3 yolo_to_onnx.py -m yolov4-tiny-416
$ python3 onnx_to_tensorrt.py -m yolov4-tiny-416
測試
$ cd ..
$ python trt_yolo.py --image doc/dog_trt_yolov4_416.jpg -m yolov4-tiny-416

使用 int8
$ cd yolo
$ ln -s yolov4-tiny-416.cfg yolov4-tiny-int8-416.cfg
$ ln -s yolov4-tiny-416.onnx yolov4-tiny-int8-416.onnx
$ mkdir calib_images
# and copy our image to calib_images
$ python3 onnx_to_tensorrt.py -v --int8 -m yolov4-tiny-int8-416
會產生如下錯誤
[03/02/2022-15:22:07] [TRT] [V] 001_convolutional + 001_convolutional_bn Set Tactic Name: sm70_xmma_fprop_implicit_gemm_f16f16_f16f16_f16_nhwckrsc_nhwc_tilesize128x256x32_stage1_warpsize2x4x1_g1_tensor8x8x4_t1r3s3 Tactic: 46202665595848747
[03/02/2022-15:22:07] [TRT] [V] Deleting timing cache: 2020 entries, 504 hits
[03/02/2022-15:22:07] [TRT] [E] 1: Unexpected exception
ERROR: failed to build the TensorRT engine!
$ vi onnx_to_tensorrt.py
將 from calibrator import YOLOEntropyCalibrator 移到程式開頭

2022年2月9日 星期三

Yolo tiny v4 to tensorflow and tflite

參考 tensorflow-yolov4-tflite

只能使用 tensorflow==2.3.0rc0
不要使用別的版本,也不要用 GPU

視情況修改 core/config.py
__C.YOLO.CLASSES
__C.YOLO.ANCHORS_TINY

for tensorflow format load by tf.saved_model.load()
$ python save_model.py --weights /your_path_to/weights/yolov4-tiny-vehicle-r_final.weights \
--output ./checkpoints/yolov4-tiny-416 \
--input_size 416 --model yolov4 --tiny
$ python convert_tflite.py --weights ./checkpoints/yolov4-tiny-416-tflite \
--output ./checkpoints/yolov4-tiny-416.tflite

for tensorflow tflite load  by tf.lite.Interpreter()
$ python save_model.py --weights /your_path_to/weights/yolov4-tiny-vehicle-r_final.weights \
--output ./checkpoints/yolov4-tiny-416-tflite \
--input_size 416 --model yolov4 --tiny --framework tflite
$ python convert_tflite.py --weights ./checkpoints/yolov4-tiny-416-tflite \
--output ./checkpoints/yolov4-tiny-416-fp16.tflite \
--quantize_mode float16