[英]SSL: CERTIFICATE_VERIFY_FAILED when using pretrained detectron2 model
I am trying to just use the pretrained mask_rcnn_R_50_FPN_3x
model in detectron2
on an image.我试图在图像上的detectron2中使用预训练的mask_rcnn_R_50_FPN_3x
detectron2
。 I get the error ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)
.我收到错误ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)
。
I am using Windows Subsystem for Linux.我正在使用 Linux 的 Windows 子系统。 The following code produces the error.以下代码会产生错误。
from detectron2.config import get_cfg
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
cfg.MODEL.DEVICE='cpu'
predictor = DefaultPredictor(cfg)
I've tried updating the certifi
package.我已经尝试更新certifi
。
I've tried我试过了
sudo apt install ca-certificates
sudo update-ca-certificates --fresh
export SSL_CERT_DIR=/etc/ssl/certs
based on one of the answers here: https://stackoverflow.com/questions/52805115/certificate-verify-failed-unable-to-get-local-issuer-certificate.\ I've tried downloading the certificates for https://dl.fbaipublicfiles.com (by, in Google Chrome, clicking the padlock symbol -> 'Connection is secure' -> 'Certificate is valid' -> 'Details' -> 'Copy to file', and then doing the same thing for the different certificates under the 'Certification Path' tab) and copying their contents into the cacert.pem
file.基于此处的答案之一: https://stackoverflow.com/questions/52805115/certificate-verify-failed-unable-to-get-local-issuer-certificate。\我尝试下载Z5E056C500A1C4B6A7110B50D807BADEZ5 的证书: /dl.fbaipublicfiles.com (在谷歌浏览器中,单击挂锁符号 -> '连接安全' -> '证书有效' -> '详细信息' -> '复制到文件',然后做同样的事情对于“证书路径”选项卡下的不同证书)并将其内容复制到cacert.pem
文件中。
UPDATE:更新:
It seems to have something to do with the urllib.request
module (altough I might be misunderstanding things).它似乎与urllib.request
模块有关(尽管我可能会误解一些事情)。 I have found that我发现
from urllib import request
request.urlretrieve('https://dl.fbaipublicfiles.com')
(the urlretrive
function is called by detectron2
) results in the same error, whereas ( urlretrive
function 由detectron2
调用)导致相同的错误,而
import requests
requests.get('https://dl.fbaipublicfiles.com')
works fine.工作正常。
Try to put this after your import
statements:尝试将其放在您的import
语句之后:
import certifi
import ssl
def create_context():
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.load_verify_locations(certifi.where())
return context
ssl._create_default_https_context = create_context
This tells urllib
to use certifi
's certificates.这告诉urllib
使用certifi
的证书。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.