jetson nx跑yolov3_NX 跑 int8 yolov341630ms

  最近研究tensorrt 跑 yolov3-416简单记录。下载yolov3的cfg和weights

修改cfg

vim yolov3.cfgbatch = 1width = 416height = 416

并且每一段只有一个空格。

1dee3ff74f0f0cac44fa29f44070e36d.png

修改yolov3_to_onnx.py  因为我们是416

output_tensor_dims['082_convolutional'] = [255, 13, 13]    [255, 19, 19]output_tensor_dims['094_convolutional'] = [255, 26, 26]    [255, 38, 38]output_tensor_dims['106_convolutional'] = [255, 52, 52]    [255, 76, 76]

其中 255 =(80 + 5)* 3  80为类别,5为输出 x, y, h, w, score

修改 weights_file_path = './yolov3.weights'

修改 output_file_path = './yolov3-416.onnx'

修改 cfg_file_path = './yolov3-416.cfg'

在NX盒子上把onnx转换成 in8 trt格式模型。

cd /usr/src/tensorrt/samles/python/yolov3_onnx/tensorrt_demos-master/yolo
sudo vim onnx_to_tensorrt.py修改 engine_path = './%s.trt'%args.model修改 onnx_path = './%s.onnx'%model_name修改 network.get_input(0).shape = [1, 3, 416, 416]  # [1, 3, 608, 608]
修改 EXPLICIT_BATCH = [] if trt.__version__[0] < '7' else \        [1 << (int)(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)] 注释掉改为:EXPLICIT_BATCH = 1 << (int)(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)修改 builder.create_network(*EXPLICIT_BATCH) as network改为 builder.create_network(EXPLICIT_BATCH) as network
修改 builder.int8_calibrator = YOLOEntropyCalibrator(                    'calib_images', (net_h, net_w), 'calib_%s.bin' % model_name)改为 calib_images 为量化图片地址。

创建一个量化图片文件夹

mkdir calib_imagessudo ln -s yolov3-416.cfg yolov3-int8-416.cfgsudo ln -s yolov3-416.onnx yolov3-int8-416.onnx

NX盒子转换 onnx 转换 int8

sudo python3 onnx_to_tensorrt.py -v --int8 -m yolov3-int8-416  # -c 为检测类别数 默认80 --dla_core 设置dla卡
cd /usr/src/tensorrt/samles/python/yolov3_onnx/tensorrt_demos-mastersudo vim trt_yolo_video_on_line.py

修改 def loop_and_detect 全部内容 测试本地视屏fps

def loop_and_detect(cam, trt_yolo, conf_th, vis):          output_path = './tensorrt_yolov3_int8_car.mp4'          full_scrn = False          writeVideo_flag = True          if writeVideo_flag:                vid = cv2.VideoCapture(cam)                if not vid.isOpened():                     raise IOError("Couldn't open webcam or video")                video_FourCC = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')                video_fps       = vid.get(cv2.CAP_PROP_FPS)                video_size      = (int(vid.get(cv2.CAP_PROP_FRAME_WIDTH)),int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT)))                isOutput = True if output_path != "" else False                if isOutput:                    #print("!!! TYPE:", type(output_path), type(video_FourCC), type(video_fps), type(video_size))                    out = cv2.VideoWriter(output_path, video_FourCC, video_fps, video_size)                    #list_file = open('detection.txt', 'w')                    frame_index = -1          while True:              return_value, frame = vid.read()              if return_value != True:                  break              if return_value:                  # frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)                  image = Image.fromarray(frame)              else:                   raise ValueError("No image!")              tic = time.time()              boxes, confs, clss = trt_yolo.detect(img, conf_th)              img = vis.draw_bboxes(img, boxes, confs, clss)              toc = time.time()              curr_fps = 1.0 / (toc - tic)              info = "time:" + str(round( (toc - tic), 2)) + " ms, FPS: " + str(curr_fps)              cv2.putText(result, text=info, org=(50, 70), fontFace=cv2.FONT_HERSHEY_SIMPLEX,fontScale=1, color=(255, 0, 0), thickness=2)              #cv2.namedWindow("result", cv2.WINDOW_AUTOSIZE)              if writeVideo_flag:                  # save a frame                  out.write(result)              #cv2.imshow("result", result)              if cv2.waitKey(1) & 0xFF == ord('q'): break
修改  cam = Camera(args)      if not cam.isOpened():          raise SystemExit('ERROR: failed to open camera!') 注释掉
修改 open_window(           WINDOW_NAME, 'Camera TensorRT YOLO Demo',           cam.img_width, cam.img_height) 注释掉
修改 cam.release()        cv2.destroyAllWindows()注释掉
添加 arser.add_argument(        '-video', '--video_path', type=str, default='',        help='video_path') 添加在线视屏路径

测试yolov3-int8-416 在tensorrt上运行时间

 sudo python3 trt_yolo_video_on_line.py  -m /usr/src/tensorrt/samples/python/yolov3_onnx/tensorrt_demos-master/yolo/yolov3-int8nx-416 -video ./car.mp4 # -c 检测类别数目,默认为80

NX量化C++引擎 engine 直接把onnx转化成engine格式

 sudo ./trtexec --onnx=./yolov3-416-1.onnx  --int8 --batch=1 --device=0 --saveEngine=./yolov3-416-gpu-int8.engine --verbose=True --allowGPUFallback --calib=/usr/src/tensorrt/samples/python/yolov3_onnx/tensorrt_demos-master/yolo/calib_images/*

可能报错:

/bin/sh: 1: nvcc: not foundMakefile:48: recipe for target 'yolo_layer.o' failedmake: *** [yolo_layer.o] Error 127

解决 找到nvcc 可执行文件路径

 cd /tensorrt_demo-master/plugins vim Makefile NVCC = /usr/local/cuda-10.2/bin/nvcc

78475b507f970912af11c42366c79e4c.png

遇见一个ubuntu16.04网络错误

d3d6458ebca9a8b7ce1daac4a268a5f5.png

解决方案

vim /etc/network/interfaces

e4678d0dd154b18fe08ba3136e2cc80d.png

ubuntu16.04 插入U盘报错:

f5f62e3327e79cd748eff9b84d4cef1a.png

解决方案:

sudo apt-get install exfat-fuse exfat-utils
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
As an AI language model, I do not have the ability to provide specific coding instructions for Jetson NX PWM C programming. However, here are some general steps to get started with PWM programming on Jetson NX using C language: 1. Include the necessary headers: You will need to include the following headers in your C program to use PWM on Jetson NX: ``` #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/mman.h> ``` 2. Open the PWM controller device: You will need to open the PWM controller device "/dev/pwm" using the open() function. This will give you a file descriptor to the device. ``` int fd = open("/dev/pwm", O_RDWR); if (fd < 0) { printf("Error opening PWM device\n"); exit(1); } ``` 3. Map the PWM controller memory: Use the mmap() function to map the PWM controller memory into your program's address space. This will allow you to access the PWM controller's registers directly from your program. ``` #define PWM_BASE_ADDRESS 0x7000a000 #define PWM_MAP_SIZE 0xfff void *pwm_map = mmap(NULL, PWM_MAP_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, PWM_BASE_ADDRESS); if (pwm_map == MAP_FAILED) { printf("Error mapping PWM memory\n"); exit(1); } ``` 4. Configure the PWM channel: You can configure the PWM channel by setting the appropriate values in the PWM controller's registers. For example, to set the PWM frequency to 100Hz and the duty cycle to 50%, you can use the following code: ``` #define PWM_PERIOD 1000000 // 100Hz frequency #define PWM_DUTY_CYCLE (PWM_PERIOD/2) // 50% duty cycle *(unsigned int *)(pwm_map + 0x00) = PWM_PERIOD; *(unsigned int *)(pwm_map + 0x04) = PWM_DUTY_CYCLE; *(unsigned int *)(pwm_map + 0x08) = 0x01; // enable PWM channel 0 ``` 5. Close the PWM controller device: When you are done using the PWM controller, you should close the device using the close() function. ``` close(fd); ``` Note: The above code is just an example and may not work for your specific use case. You will need to consult the Jetson NX documentation and reference manual for detailed information on using PWM in your application.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值