# Load the raw CIFAR-10 data.
cifar10_dir = 'cs231n/datasets/cifar-10-batches-py
# Cleaning up variables to prevent loading data multiple times (which may cause memory issue)
try
del X_train, y_train
del X_test. y_test
print('Clear previously loaded data. ')
except:
pass
Xtrain, y_train, Xtest, y_test = load_CIFAR10(cifar 10_dir)
# As a sanity check, we print out the size of the training and test data.
print('Training data shape: ', X_train.shape)
print('Training labels shape: ', y_train.shape)
print('Test data shape: ', X_test.shape)
print('Test labels shape: ', y_test shape)
Clear previously loaded data.
Training data shape: (50000, 32, 32, 3)
Training labels shape: (50000, )
Test data shape: (10000, 32, 82, 3)
Test labels shape: (10000,)from _ future
ingort andor
DIBTOX as BIT
def, oad_C1FAA10(ROOT):
"Toad all of citar
for b in range(1.6).
f= os.path.join(ROOT, ‘deta batch.td' % (b. 1)
KV = load CiFAR batcntT]
7S apoeNT
ys-append(Y)
Xtr = np.concatenate(xs)
Yir = np.concatenate(ys)
del X,Y
Xte, Vig_= load C1FAn pat
return [tr vir, He, Vte
det, toad_clFAR batch Lenam):
lead single batch of cifar
rovarray(¥)
turn X,Y
\os.path. join(ROGT, ' test_batch’))
0 = Wf assionmentt J c8231n datasets / cifar-t0-batohee-py
o
1B Dosenes mata
2 Dest baen +
2 Dat pan 2
2 Down tan 9
2 Det baton «
2 Dat pan s
8 Dresime nent
2 Dies bach
from future. import print_tunction
From six.noves tnport ePlokle as pickle
Tapert many a5 np
Import os
tram scipy.nise inport inread
import plattorn
dot load_pickle()
version = platforn.python_version_tuple()
if version(o] = 2
return pickle. load(t)
elif version(0] == 's
return pickle. load(t. encoding-' at int!)
i Valvettror("implid python version: (1. format(version))# Visualize sone examples from the dataset.
# iio show a few examples of training images from each class.
classes = ['plane', ‘car’, ‘bird’, ‘cat’, ‘deer’, ‘doa’, ‘frog’
rnum_classes = len(classes)
sanples_per_class = 7
for y, cls in enuterate(classes):
ass.
{idk = i numclasses + y +1
plt-subplot(saroles_per_class, nun_classes. plt_idx)
pit. inshow(X_train{idx] astype( 'uint8'))
plt.axis(‘off')
if i = 0:
pit.title(cts)
pltshow()
‘numpy.random.choice
replace-Fe
horse’, ‘ship’, 'truck']
ert aunt adam cane arin rnensot 0
err anon anor undon samp romrp ane)
‘errs ensue prog of a 2 hn recone
erate arent aon sage tome aan ose niet escent
yen scan cept tray ay ala gr Fara