一、問題描述
網上絕大多數作業參考都是在jupyter下運行的,數據集載入過程一般如下:
from cs231n.data_utils import load_CIFAR10
#導入數據集,並打印出數據集相關參數以確定是否加載成功
cifar10_dir = 'cs231n/datasets/cifar-10-batches-py' #數據集地址(獲取數據集的腳本)
#刪除以前可能導入的數據,若之前未導入數據,則直接pass
#try...except...為解決異常的語句,參見https://www.cnblogs.com/Lival/p/6203111.html
try:
del X_train, y_train
del X_test, y_test
print('Clear previously loaded data')
except:
pass
X_train, y_train, X_test, y_test = load_CIFAR10(cifar10_dir) #加載數據集
#打印出數據集相關參數以確定是否加載成功
print('Training data shapa:', X_train.shape)
print('Training labels shape:', y_train.shape)
print('Test data shape:', X_test.shape)
print('Test labels shape:', y_test.shape)
1)給出數據集的地址(獲取數據集的腳本)
cifar10_dir = 'cs231n/datasets/cifar-10-batches-py'
2)使用斯坦福布置作業時已提供的腳本讀取數據集
from cs231n.data_utils import load_CIFAR10
X_train, y_train, X_test, y_test = load_CIFAR10(cifar10_dir)
需要注意的是,獲取數據集的腳本和讀取數據集的腳本都在名為”cs231n“的文件夾里面,必須保證該文件夾與當前的.ipynb文件在同一文件夾下。
在jupyter下運行,報錯:
FileNotFoundError: [Errno 2] No such file or directory: 'cs231n/datasets/cifar-10-batches-py\\data_batch_1'
二、解決方法
將數據集下到本地,直接給出數據集在本地的絕對地址。
cifar10_dir = 'F:\Jupyter\CIFAR10'
其他照舊,可正確讀取出數據集:
Training data shapa: (50000, 32, 32, 3)
Training labels shape: (50000,)
Test data shape: (10000, 32, 32, 3)
Test labels shape: (10000,)
附:CIFAR10百度網盤下載鏈接:https://pan.baidu.com/s/1wfVcvZAvPgsvKyrdaEqGGg 提取碼:qd4v