-
Notifications
You must be signed in to change notification settings - Fork 0
/
disorder_images.py
36 lines (36 loc) · 1.19 KB
/
disorder_images.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 08 17:21:17 2016
this code disorders the input images and their corresponding labels
@author: David_Zhang
"""
import scipy.io as sio
import numpy as np
image_path = 'images.mat'
image_D = sio.loadmat(image_path)
label_path = 'labels.mat'
label_D = sio.loadmat(label_path)
images = image_D['images']
labels = label_D['labels']
test_image_path = 'test_images.mat'
test_image_D = sio.loadmat(test_image_path)
test_label_path = 'test_labels.mat'
test_label_D = sio.loadmat(test_label_path)
images = image_D['images']
labels = label_D['labels']
test_images = test_image_D['test_images']
test_labels = test_label_D['test_labels']
def disorder_images(images, labels):
assert images.shape[0] == labels.shape[0]
num_examples = images.shape[0]
perm = np.arange(num_examples)
np.random.shuffle(perm)
images = images[perm]
labels = labels[perm]
return images,labels
images,labels = disorder_images(images, labels)
test_images,test_labels = disorder_images(test_images, test_labels)
np.save("images.npy",images)
np.save("labels.npy",labels)
np.save("test_images.npy",test_images)
np.save("test_labels.npy",test_labels)