-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrain_loader.py
37 lines (27 loc) · 1.1 KB
/
train_loader.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
# -*- coding: utf-8 -*-
"""Train_Loader.ipynb
**
* This file is part of Hybrid CNN-LSTM for COVID-19 Severity Score Prediction paper.
*
* Written by Ankan Ghosh Dastider and Farhan Sadik.
*
* Copyright (c) by the authors under Apache-2.0 License. Some rights reserved, see LICENSE.
*/
"""
IMAGE_SIZE =128
def read_image(filepath):
return cv2.imread(os.path.join(data_dir, filepath)) # Loading a color image is the default flag
# Resize image to target size
def resize_image(image, image_size):
return cv2.resize(image.copy(), image_size, interpolation=cv2.INTER_AREA)
X_train = np.zeros((train.shape[0], IMAGE_SIZE, IMAGE_SIZE, 3))
X_train_ft=np.zeros((train.shape[0], IMAGE_SIZE, IMAGE_SIZE, 3))
for i, file in tqdm(enumerate(train['File'].values)):
image = read_image(file)
if image is not None:
X_train[i] =resize_image(image, (IMAGE_SIZE, IMAGE_SIZE))
X_Train = X_train / 255.
print('Train Shape: {}'.format(X_Train.shape))
Y_train = train['DiseaseID'].values
print(len(Y_train))
Y_train = to_categorical(Y_train, num_classes=4)