openCV caffe model loading error

The code is as below:

def load_model():
    modelFile = 'res10_300x300_ssd_iter_140000_fp16.caffemodel'
    configFile = 'deploy.prototxt.txt'
    #modelFile = " C:/Users/roys21/streamlit-face-detect/res10_300x300_ssd_iter_140000_fp16.caffemodel"
    #configFile = " C:/Users/roys21/streamlit-face-detect/deploy.prototxt.txt"
    net = cv2.dnn.readNetFromCaffe(configFile, modelFile)
    return net

and it throws the below error:

error: OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-_8k9tw8n\opencv\modules\dnn\src\caffe\caffe_io.cpp:1121: error: (-2:Unspecified error) FAILED: fs.is_open(). Can't open " C:/Users/roys21/streamlit-face-detect/deploy.prototxt.txt" in function 'cv::dnn::ReadProtoFromTextFile'

I have checked the path exists:

import os
assert os.path.exists("C:/Users/roys21/streamlit-face-detect/deploy.prototxt.txt")
assert os.path.exists("deploy.prototxt.txt")

Any help would be appreciated. Thanks.

you’re checking an absolute path, but use a relative one to load your model

please make sure, your program starts in the same folder as the data
(C:/Users/roys21/streamlit-face-detect)

related: How to parse caffe model in opencv using cv2.dnn.readNetfromCaffe? OpenCV 4.4.0

by the way, there’s a SPACE in your path strings, right at the start.

remove the space.