python使用opennsfw2鉴黄模型遇到ConnectionError: HTTPSConnectionPool(host=‘github.com‘, port=443)

python使用opennsfw2模型进行鉴黄的时候遇到ConnectionError: HTTPSConnectionPool(host='github.com', port=443)

代码:


if __name__ == '__main__':
    import numpy as np
    from PIL import Image
    from opennsfw2._model import make_open_nsfw_model
    from opennsfw2._image import preprocess_image, Preprocessing
    
    image_path = 'E:\\temp\\sex_video\\1.png'
    image = preprocess_image(Image.open(image_path), Preprocessing.YAHOO)
    model = make_open_nsfw_model()
    nsfw_probability = float(model.predict(np.expand_dims(image, 0), batch_size=1)[0][1])
    
    print("sex的概率:"+nsfw_probability)

部分报错日志:

To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Pre-trained weights will be downloaded.
Traceback (most recent call last):
  File "E:\software\web\Anaconda3_install\envs\simswap\lib\site-packages\urllib3\connection.py", line 175, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw
  File "E:\software\web\Anaconda3_install\envs\simswap\lib\site-packages\urllib3\util\connection.py", line 95, in create_connection
    raise err
  File "E:\software\web\Anaconda3_install\envs\simswap\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\software\web\Anaconda3_install\envs\simswap\lib\site-packages\urllib3\connectionpool.py", line 721, in urlopen
    chunked=chunked,
  File "E:\software\web\Anaconda3_install\envs\simswap\lib\site-packages\urllib3\connectionpool.py", line 403, in _make_request
    self._validate_conn(conn)
  File "E:\software\web\Anaconda3_install\envs\simswap\lib\site-packages\urllib3\connectionpool.py", line 1053, in _validate_conn
    conn.connect()
  File "E:\software\web\Anaconda3_install\envs\simswap\lib\site-packages\urllib3\connection.py", line 363, in connect
    self.sock = conn = self._new_conn()
  File "E:\software\web\Anaconda3_install\envs\simswap\lib\site-packages\urllib3\connection.py", line 187, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x0000021DCA5C51D0>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\software\web\Anaconda3_install\envs\simswap\lib\site-packages\requests\adapters.py", line 450, in send
    timeout=timeout
  File "E:\software\web\Anaconda3_install\envs\simswap\lib\site-packages\urllib3\connectionpool.py", line 799, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "E:\software\web\Anaconda3_install\envs\simswap\lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='github.com', port=443): Max retries exceeded with url: /bhky/opennsfw2/releases/download/v0.1.0/open_nsfw_weights.h5 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000021DCA5C51D0>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\software\web\Anaconda3_install\envs\simswap\lib\site-packages\requests\adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='github.com', port=443): Max retries exceeded with url: /bhky/opennsfw2/releases/download/v0.1.0/open_nsfw_weights.h5 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000021DCA5C51D0>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。',))

原因:python代码下载文件失败,可能是网络的问题,github访问不了。

解决方案:手动下载到本地。

原来的下载地址:http://github.com/bhky/opennsfw2/releases/download/v0.1.0/open_nsfw_weights.h5

国内码云下载地址(用浏览器打开):releases/download/v0.1.0/open_nsfw_weights.h5 · zdb1314/ opennsfw2-file - Gitee.com

windows电脑下载保存的位置:C:\Users\用户名\.opennsfw2\weights

如:      C:\Users\Administrator\.opennsfw2\weights\open_nsfw_weights.h5

然后就可以了,opennsfw2只要检测到本地有就不用重复下载了,解决!

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值