forked from BoyuanJiang/matching-networks-pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_datatset.py
47 lines (42 loc) · 1.78 KB
/
gen_datatset.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
37
38
39
40
41
42
43
44
45
46
47
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Created by: BoyuanJiang
# College of Information Science & Electronic Engineering,ZheJiang University
# Email: [email protected]
# Copyright (c) 2017
# @Time :17-8-27 10:18
# @FILE :gen_datatset.py
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
import numpy as np
from scipy import misc
import os
dataset = []
examples = []
# images_background
data_root = "./data/"
alphabets = os.listdir(data_root + "images_background")
for alphabet in alphabets:
characters = os.listdir(os.path.join(data_root, "images_background", alphabet))
for character in characters:
files = os.listdir(os.path.join(data_root, "images_background", alphabet, character))
examples = []
for img_file in files:
img = misc.imresize(
misc.imread(os.path.join(data_root, "images_background", alphabet, character, img_file)), [28, 28])
# img = (np.float32(img) / 255.).flatten()
examples.append(img)
dataset.append(examples)
# images_evaluation
data_root = "./data/"
alphabets = os.listdir(data_root + "images_evaluation")
for alphabet in alphabets:
characters = os.listdir(os.path.join(data_root, "images_evaluation", alphabet))
for character in characters:
files = os.listdir(os.path.join(data_root, "images_evaluation", alphabet, character))
examples = []
for img_file in files:
img = misc.imresize(
misc.imread(os.path.join(data_root, "images_evaluation", alphabet, character, img_file)), [28, 28])
# img = (np.float32(img) / 255.).flatten()
examples.append(img)
dataset.append(examples)
np.save(data_root + "dataset.npy", np.asarray(dataset))