TensorFlow Keras使用get_file下载训练数据集时URL获取失败问题
我在为CNN模型导入包含30000张图像的训练数据集时,以下代码行导致程序运行出错:
data_dir = tf.keras.utils.get_file(origin=dataset_url, fname='functionidentifier', untar=True)
更多上下文的完整代码块如下:
dataset_url = "https://barisciencelab.tech/functionidentifier.tgz" data_dir = tf.keras.utils.get_file(origin = dataset_url, fname = "functionidentifier", untar = True) data_dir = pathlib.Path(data_dir)
该代码上周还可正常运行,近日突然报错。
我已尝试以下排查方案:
- 将训练集文件扩展名从
.tar.gz先后修改为.zip、.tar.tar、.tgz测试 - 单元测试验证其余代码逻辑正常,仅涉及数据集导入的部分报错
- 在全新的Google Colab Notebook和Jupyter Notebook中运行完全相同的代码,均无法正常执行
- 对照TensorFlow官方文档核对,代码完全符合规范,唯一差异为我使用的数据集URL
以上操作均未解决问题,且我无法手动下载完整训练集到本地操作,操作成本过高。
最小可复现示例
pip install tensorflow pip install numpy pip install matplotlib !git clone https://github.com/Refath/SinusoidalAnalyzer.git import tensorflow as tf from tensorflow import keras from keras.models import Sequential from keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, Dropout from tensorflow.keras import layers from tensorflow.keras.utils import to_categorical import numpy as np import matplotlib.pyplot as plt plt.style.use('fivethirtyeight') import pathlib dataset_url = "https://barisciencelab.tech/TrainingSet.tar.gz" data_dir = tf.keras.utils.get_file(origin = dataset_url, fname = "TrainingSet", untar = True) data_dir = pathlib.Path(data_dir)
Stack Overflow聊天室的用户也尝试协助排查该问题,但尚未找到解决方案,恳请各位帮忙定位问题原因,非常感谢。
内容的提问来源于stack exchange,提问作者rb3652
相关产品推荐
相关产品推荐

