darknettoonnx.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import sys
  2. import onnx
  3. import os
  4. import argparse
  5. import numpy as np
  6. import cv2
  7. import onnxruntime
  8. import multiprocessing
  9. from tool.utils import *
  10. from tool.darknet2onnx import *
  11. cfg_file = 'C:\\Users\\VINNO\\Desktop\\新建文件夹 (2)\\pytorch-YOLOv4-master\\yolov4-tiny-breast-anchors--3l---20210901.cfg'
  12. weight_file = 'C:\\Users\\VINNO\\Desktop\\新建文件夹 (2)\\pytorch-YOLOv4-master\\yolov4-tiny-breast-anchors--3l---20210901_last.weights'
  13. batch_size = 0
  14. if batch_size <= 0:
  15. onnx_path_demo = transform_to_onnx(cfg_file, weight_file, batch_size)
  16. else:
  17. # Transform to onnx as specified batch size
  18. transform_to_onnx(cfg_file, weight_file, batch_size)
  19. # Transform to onnx as demo
  20. onnx_path_demo = transform_to_onnx(cfg_file, weight_file, 1)
  21. session = onnxruntime.InferenceSession(onnx_path_demo)
  22. cpuCount = os.cpu_count()
  23. print("Number of CPUs in the system:", cpuCount)
  24. # file_name = 'C:\\Users\\VINNO\\Desktop\\新建文件夹 (2)\\新建文本文档.txt'
  25. # dest_name = 'C:\\Users\\VINNO\\Desktop\\新建文件夹 (2)\\1.txt'
  26. # # 以二进制打开和保存数据
  27. # with open(dest_name, "a", encoding="utf-8") as data:
  28. # with open(file_name, "a", encoding="utf-8") as s:
  29. # data.writelines(s.readlines())