CS231n 第一次作業KNN中本地CIFAR10數據集的載入


一、問題描述

網上絕大多數作業參考都是在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 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM