1, CIFAR-10, is a data set for the study of image classification.
- Made up of 60,000 images
- 60,000 of the pictures, 50,000 for training, 10,000 for testing
- Each picture is a 32x32 pixel
- All pictures can be divided into 10 categories
- Each picture has a label that marks which class it belongs to.
- One class in the test set corresponds to 1000 graphs
- Training focus divides 50,000 graphs into 5 parts
- The picture between classes is mutually exclusive and there is no category overlap
Show the specific classification,
2. Data Set Loading:
CIFAR-10 provides three versions of the data format: Python,matlab, Binary.
Here is an example of Python loading, refer to http://cs231n.github.io/assignments2018/assignment1/
from __future__ Importprint_function fromSix.movesImportCpickle as PickleImportNumPy as NPImportOS fromScipy.miscImportImreadImportPlatform#Read FiledefLoad_pickle (f): Version= Platform.python_version_tuple ()#take the python version number ifVersion[0] = ='2': returnPickle.load (f)#pickle.load, deserializing data type into Python elifVersion[0] = ='3': returnPickle.load (F, encoding='latin1') RaiseValueError ("Invalid Python version: {}". Format (version)defload_cifar_batch (filename):"""load single batch of Cifar"""with open (filename,'RB') as F:datadict= Load_pickle (f)#dict TypeX = datadict['Data']#X, Ndarray, pixel valueY = datadict['Labels']#Y, list, tags, categories #reshape, a one-dimensional array is converted to a matrix of 10000 rows and 3 columns. Each entries is a 32x32 #Transpose, Transpose #Astype, copying, specifying type at the same timeX = X.reshape (10000, 3, +, +). Transpose (0,2,3,1). Astype ("float") Y=Np.array (Y)returnX, YdefLoad_cifar10 (ROOT):"""load all of Cifar"""XS= []#ListYS = [] #Training Set Batch forBinchRange (1,6): F= Os.path.join (ROOT,'data_batch_%d'%(b,)) X, Y=Load_cifar_batch (f) xs.append (X)#Add object x to the list tail, x = [..., [x]]ys.append (Y) Xtr= Np.concatenate (XS)#[Ndarray, Ndarray] merged into a ndarrayYTR =np.concatenate (YS)delX, Y#Test SetXte, Yte = Load_cifar_batch (Os.path.join (ROOT,'Test_batch')) returnXTR, Ytr, Xte, Yte
The batch data is deserialized out of
{
' Data ': pixel data,
' Labels ': Category labels
}
The Python Foundation involved is:
1, from __future__ import print_function, __future__ is used in the old version of Python to use the new version features
2, from six.moves import cpickle as Pickle, is a serialized and deserialized library, pickle.load, deserialized into Python data type
3, List of the Append method, add objects at the end of the list, do not need to be consistent with the previous data type
4, NumPy of concatenate, merge array
Reference:
Http://www.cs.toronto.edu/~kriz/cifar.html
CIFAR-10 and Python read