cv.dnn.readNet()

官方文档:
https://docs.opencv.org/3.4/d6/d0f/group__dnn.html#ga3b34fe7a29494a6a4295c169a7d32422

Python使用方法举例(Examples for Python):

如使用Darknet的预训练模型:

weights = "yolov2.weights"
config_file = "yolov2.cfg"
# read pre-trained model and config file
net = cv2.dnn.readNet(weights, config_file)

如使用Caffe的预训练模型:

path_to_prototxt = "deploy.prototxt"
path_to_caffemodel = "hed_pretrained_bsds.caffemodel"
net = cv.dnn.readNet(path_to_prototxt, path_to_caffemodel)

C++使用方法举例(Examples for C++):

samples/dnn/classification.cpp;
samples/dnn/object_detection.cpp;
samples/dnn/openpose.cpp;
samples/dnn/segmentation.cpp;
samples/dnn/text_detection.cpp.

可使用的模型(Available Model):

Caffe, TensorFlow, Torch, Darknet, DLDT, ONNX

模型权重文件支持的文件格式:

  • *.caffemodel (Caffe, http://caffe.berkeleyvision.org/)
  • *.pb (TensorFlow, https://www.tensorflow.org/)
  • *.t7 | *.net (Torch, http://torch.ch/)
  • *.weights (Darknet, https://pjreddie.com/darknet/)
  • *.bin (DLDT, https://software.intel.com/openvino-toolkit)
  • *.onnx (ONNX, https://onnx.ai/)

模型配置文件支持的文件格式:

*.prototxt (Caffe, http://caffe.berkeleyvision.org/)
*.pbtxt (TensorFlow, https://www.tensorflow.org/)
*.cfg (Darknet, https://pjreddie.com/darknet/)
*.xml (DLDT, https://software.intel.com/openvino-toolkit)

可见不支持pytorch的*.pth和keras等的*.h5
在这里插入图片描述

cv.dnn 的其它加载模型的方法有:

  • readNetFromCaffe()
  • readNetFromDarknet()
  • readNetFromModelOptimizer()
  • readNetFromONNX()
  • readNetFromTensorflow()
  • readNetFromTorch()

支持的文件格式同readNet()中相应的模型

GitHub 加速计划 / te / tensorflow
184.55 K
74.12 K
下载
一个面向所有人的开源机器学习框架
最近提交(Master分支:2 个月前 )
a49e66f2 PiperOrigin-RevId: 663726708 3 个月前
91dac11a This test overrides disabled_backends, dropping the default value in the process. PiperOrigin-RevId: 663711155 3 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐