|
a |
|
b/train_loader.py |
|
|
1 |
# -*- coding: utf-8 -*- |
|
|
2 |
"""Train_Loader.ipynb |
|
|
3 |
|
|
|
4 |
** |
|
|
5 |
* This file is part of Hybrid CNN-LSTM for COVID-19 Severity Score Prediction paper. |
|
|
6 |
* |
|
|
7 |
* Written by Ankan Ghosh Dastider and Farhan Sadik. |
|
|
8 |
* |
|
|
9 |
* Copyright (c) by the authors under Apache-2.0 License. Some rights reserved, see LICENSE. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
""" |
|
|
13 |
|
|
|
14 |
IMAGE_SIZE =128 |
|
|
15 |
|
|
|
16 |
def read_image(filepath): |
|
|
17 |
return cv2.imread(os.path.join(data_dir, filepath)) # Loading a color image is the default flag |
|
|
18 |
# Resize image to target size |
|
|
19 |
def resize_image(image, image_size): |
|
|
20 |
return cv2.resize(image.copy(), image_size, interpolation=cv2.INTER_AREA) |
|
|
21 |
|
|
|
22 |
X_train = np.zeros((train.shape[0], IMAGE_SIZE, IMAGE_SIZE, 3)) |
|
|
23 |
X_train_ft=np.zeros((train.shape[0], IMAGE_SIZE, IMAGE_SIZE, 3)) |
|
|
24 |
for i, file in tqdm(enumerate(train['File'].values)): |
|
|
25 |
image = read_image(file) |
|
|
26 |
if image is not None: |
|
|
27 |
|
|
|
28 |
X_train[i] =resize_image(image, (IMAGE_SIZE, IMAGE_SIZE)) |
|
|
29 |
|
|
|
30 |
|
|
|
31 |
X_Train = X_train / 255. |
|
|
32 |
print('Train Shape: {}'.format(X_Train.shape)) |
|
|
33 |
|
|
|
34 |
Y_train = train['DiseaseID'].values |
|
|
35 |
print(len(Y_train)) |
|
|
36 |
Y_train = to_categorical(Y_train, num_classes=4) |
|
|
37 |
|