-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreProcessing.py
More file actions
59 lines (39 loc) · 1.21 KB
/
Copy pathPreProcessing.py
File metadata and controls
59 lines (39 loc) · 1.21 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 27 09:32:14 2020
@author: Ivano Dibenedetto mat. 654678
"""
import numpy as np
import matplotlib.pyplot as plt
import os
import cv2
from tqdm import tqdm
import random
import pickle
DATADIR = "Covid19_dataset_global"
CATEGORIES = ["Covid", "Polmonite"]
IMG_SIZE = 250
training_data = []
def create_training_data():
for category in CATEGORIES:
path = os.path.join(DATADIR, category)
class_num = CATEGORIES.index(category)
for img in tqdm(os.listdir(path)):
img_array = cv2.imread(os.path.join(path, img), cv2.IMREAD_GRAYSCALE)
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
training_data.append([new_array, class_num])
create_training_data()
print(len(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)
pickle_out = open("X2.pickle", "wb")
pickle.dump(X, pickle_out)
pickle_out.close()
pickle_out = open("y2.pickle", "wb")
pickle.dump(y, pickle_out)
pickle_out.close()