OpenCV cv2.dnn.readNetFromCaffe gives Failed to parse NetParameter error

Im trying to follow a project using a pretrained caffe model to detect faces but get an error.


import numpy as np
import os.path

modelFile = “C:/Users/danie/PycharmProjects/FaceTrack/models/res10_300x300_ssd_iter_140000.caffemodel”
configFile = “C:/Users/danie/PycharmProjects/FaceTrack/models/deploy.prototxt”

assert os.path.exists(modelFile)
assert os.path.exists(configFile)


net = cv2.dnn.readNetFromCaffe(configFile, modelFile)


C:\Users\danie\PycharmProjects\FaceTrack\venv\Scripts\python.exe C:/Users/danie/PycharmProjects/FaceTrack/
[libprotobuf ERROR C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-c2l3r8zm\opencv\3rdparty\protobuf\src\google\protobuf\] Error parsing text-format opencv_caffe.NetParameter: 7:1: Expected identifier, got: <
Traceback (most recent call last):
File “C:/Users/danie/PycharmProjects/FaceTrack/”, line 18, in
net = cv2.dnn.readNetFromCaffe(configFile, modelFile)
cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-c2l3r8zm\opencv\modules\dnn\src\caffe\caffe_io.cpp:1157: error: (-2:Unspecified error) FAILED: ReadProtoFromTextFile(param_file, param). Failed to parse NetParameter file: C:/Users/danie/PycharmProjects/FaceTrack/models/deploy.prototxt in function ‘cv::dnn::ReadNetParamsFromTextFileOrDie’

I would massivly appreciate any help. i have looked at loads of threads and cant see what im doing wrong

most likely you downloaded some html file instead of the “raw” prototxt
look at it with some txt editor, or

type models/deploy.prototxt

on the console

1 Like

Thanks mate. That was super super helpful.

I was using “Save link as” to get ptototxt, tried instead just coping into a text file and that solved my problem.

1 Like