You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下Miniconda3加载TensorFlow Hub模型遇SSL证书验证失败

解决Windows Miniconda环境下TensorFlow Hub加载模型的SSL证书错误

以下是针对你的场景的具体解决方法:

方法1:手动指定certifi证书路径

在导入TensorFlow和TensorFlow Hub之前,先设置环境变量指向certifi的证书文件:

import os
import certifi

# 设置SSL证书路径为certifi提供的文件
os.environ['SSL_CERT_FILE'] = certifi.where()
os.environ['REQUESTS_CA_BUNDLE'] = certifi.where()

# 之后再导入相关库
import tensorflow as tf
import tensorflow_hub as hub

执行完这段代码后再运行你的模型创建逻辑。

方法2:本地加载TF Hub模型

跳过联网下载,手动把模型下载到本地后加载:

  1. 打开浏览器访问你的模型URL https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/5,找到页面中的"Download"选项,下载模型压缩包并解压到本地路径(比如C:/models/mobilenet_v2)。
  2. 修改代码中的模型路径为本地路径:
MODEL_URL = "C:/models/mobilenet_v2"  # 替换成你的实际解压路径

之后正常运行模型创建代码即可。

方法3:更新conda环境的证书

激活你的tfdml_plugin环境,更新certifi证书:

  1. 打开Anaconda Prompt,执行命令激活环境:
conda activate tfdml_plugin
  1. 更新certifi:
conda update certifi
  1. 重启Jupyter Notebook,重新运行代码。

方法4:临时禁用SSL验证(仅测试用)

如果只是临时测试,可跳过SSL证书验证(不推荐用于生产环境),在代码开头添加:

import ssl
# 禁用SSL证书验证
ssl._create_default_https_context = ssl._create_unverified_context

# 之后导入TensorFlow和hub
import tensorflow as tf
import tensorflow_hub as hub

内容的提问来源于stack exchange,提问作者DjoleDMonke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 17:40:21