Created
June 30, 2021 10:13
-
-
Save sadimanna/a7b612a951c1b8417f6c39c5b1c8cd6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pickle | |
| def unpickle(file): | |
| with open(file, 'rb') as fo: | |
| dict = pickle.load(fo, encoding='bytes') | |
| return dict | |
| train_files = ['data_batch_1','data_batch_2','data_batch_3','data_batch_4','data_batch_5'] | |
| images = np.array([],dtype=np.uint8).reshape((0,3072)) | |
| labels = np.array([]) | |
| for tf in train_files: | |
| data_dict = unpickle('/content/cifar-10-batches-py/'+tf) | |
| data = data_dict[b'data'] | |
| images = np.append(images,data,axis=0) | |
| labels = np.append(labels,data_dict[b'labels']) | |
| #print(images.shape, labels.shape) | |
| testimages = np.array([],dtype=np.uint8).reshape((0,3072)) | |
| testlabels = np.array([]) | |
| data_dict = unpickle('/content/cifar-10-batches-py/test_batch') | |
| data = data_dict[b'data'] | |
| testimages = np.append(testimages,data,axis=0) | |
| testlabels = np.append(testlabels,data_dict[b'labels']) | |
| #print(testimages.shape, testlabels.shape) | |
| images = images.reshape((-1,3,32,32)).astype(np.float) | |
| testimages = testimages.reshape((-1,3,32,32)).astype(np.float) | |
| lab_dict = {0:'airplane',1:'automobile',2:'bird',3:'cat',4:'deer',5:'dog',6:'frog',7:'horse',8:'ship',9:'truck'} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment