cv2.dnn.readNetFromCaffe : Failed to parse NetParameter file

Getting this error while deploying the app to heroku :

net = cv.dnn.readNetFromCaffe("pose_iter_160000.caffemodel","pose_deploy_linevec_faster_4_stages.prototxt")
2021-04-07T06:50:28.290720+00:00 app[web.1]: cv2.error: OpenCV(3.4.13) /tmp/pip-req-build-j269xpzo/opencv/modules/dnn/src/caffe/caffe_io.cpp:1157: error: (-2:Unspecified error) FAILED: ReadProtoFromTextFile(param_file, param). Failed to parse NetParameter file: pose_iter_160000.caffemodel in function 'ReadNetParamsFromTextFileOrDie'
2021-04-07T06:50:28.290720+00:00 app[web.1]: 

Here is the code :

net = cv.dnn.readNetFromCaffe("pose_deploy_linevec_faster_4_stages.prototxt","pose_iter_160000.caffemodel")

Both these files exist.

It gives the same error for opencv 4 as well :

net = cv.dnn.readNetFromCaffe("./pose_deploy_linevec_faster_4_stages.prototxt", "./pose_iter_160000.caffemodel")
2021-04-07T06:15:06.532379+00:00 app[web.1]: cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-j6tkfxml/opencv/modules/dnn/src/caffe/caffe_io.cpp:1171: error: (-2:Unspecified error) FAILED: ReadProtoFromBinaryFile(param_file, param). Failed to parse NetParameter file: ./pose_iter_160000.caffemodel in function 'ReadNetParamsFromBinaryFileOrDie'
  • your 1st example has model/config files swapped (so you get an error about prototxt)
    (if your opencv version has it, better use readNet() instead of readNetFromXXX(), since it’s more robust against swapping args)

  • assuming, this is the mpi pose model, please check
    sha1sum pose_iter_160000.caffemodel and compare to here

  • make sure, those files are in the folder, where your app starts
    (/app on heroku, iirc)