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

从TensorFlow导入MNIST数据集遇SSL证书错误(Anaconda环境)求助

Fixing SSL Certificate Error When Importing MNIST Dataset in TensorFlow

Hey there, let's work through this SSL certificate issue and get your MNIST dataset loaded properly. First, let's address a couple of key points that might be causing your trouble:

1. You might have installed the wrong package (not certified but certifi)

You mentioned uninstalling/reinstalling certified, but the correct Python package for managing SSL certificates is certifi. That's likely a typo that's been holding you back. Run these commands to fix it:

pip uninstall certified
pip install --upgrade certifi

2. The tensorflow.examples.tutorials.mnist module is deprecated

This module is no longer maintained in newer TensorFlow versions (especially TF 2.x), which can lead to unexpected errors including SSL issues. The recommended approach is to use the built-in Keras dataset loader instead—it's more reliable and avoids these legacy problems:

import tensorflow as tf

# Load MNIST directly via Keras
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()

# If you need the same structure as input_data (like one-hot labels), you can convert it:
y_train = tf.keras.utils.to_categorical(y_train, 10)
y_test = tf.keras.utils.to_categorical(y_test, 10)

3. If you must use the legacy input_data module (TF 1.x only)

If you're stuck using TensorFlow 1.x and the old module, here are two ways to bypass the SSL error:

Option A: Disable SSL verification (temporary fix)

This skips certificate checks for the download. Note: This isn't secure for production, but works for testing:

import ssl
# Disable SSL verification
ssl._create_default_https_context = ssl._create_unverified_context

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("tmp/data/", one_hot=True)

Option B: Manually download the dataset

Download the MNIST files directly and place them in your tmp/data/ folder. The required files are:

  • train-images-idx3-ubyte.gz
  • train-labels-idx1-ubyte.gz
  • t10k-images-idx3-ubyte.gz
  • t10k-labels-idx1-ubyte.gz

When you run read_data_sets, it will detect the local files and skip the download, avoiding the SSL error entirely.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:07:37