-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-data.py
More file actions
36 lines (31 loc) · 795 Bytes
/
generate-data.py
File metadata and controls
36 lines (31 loc) · 795 Bytes
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 Mon Feb 11 18:08:05 2019
@author: Illusion
"""
import numpy as np
import h5py
import cv2
import scipy.io as sio
import os
from skimage import io
from skimage.transform import resize
target_path = "miml-image-data/miml data.mat" # target labels
image_path = "miml-image-data/original" # images
y = sio.loadmat(target_path)
y = y['targets']
y = y.transpose()
y = np.array([[elem if elem == 1 else 0 for elem in row]for row in y])
x = []
for i in range(1,2001):
print "reading image:"+str(i) + ".jpg"
img = image_path + "/" + str(i) + ".jpg"
img = cv2.imread(img)
img = cv2.resize(img,(100,100))
img = img.transpose((2,0,1))
x.append(img)
x = np.array(x)
f = h5py.File("dataset.h5")
f['x'] = x
f['y'] = y
f.close()