-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgToPickle.py
44 lines (33 loc) · 1.04 KB
/
imgToPickle.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
import numpy as np
import os
import random
from PIL import Image
DATADIR = '/storage/cpperico/HackCovid'
CATEGORIES = ['covid','normal','outros']
training_data = []
IMG_SIZE = 300
def create_training_data():
for category in CATEGORIES:
path = os.path.join(DATADIR, category)
class_num = CATEGORIES.index(category)
for img in os.listdir(path):
try:
img_array = np.array(Image.open(os.path.join(path,img)).convert('L').resize((IMG_SIZE,IMG_SIZE)))
training_data.append([img_array, class_num])
except Exception as e:
pass
create_training_data()
random.shuffle(training_data)
X = []
y = []
for features,label in training_data:
X.append(features)
y.append(label)
X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)
import pickle
pickle_out = open('/storage/guilherme/xrays/X.pickle', 'wb')
pickle.dump(X, pickle_out)
pickle_out.close()
pickle_out = open('/storage/guilherme/xrays/y.pickle', 'wb')
pickle.dump(y, pickle_out)
pickle_out.close()