|
a |
|
b/train.py |
|
|
1 |
# -*- coding: utf-8 -*- |
|
|
2 |
"""train.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 |
#EPOCHS=70 |
|
|
15 |
annealer = ReduceLROnPlateau(monitor='val_accuracy', factor=0.5, patience=5, verbose=1, min_lr=1e-3) |
|
|
16 |
checkpoint = ModelCheckpoint('Model.h5', verbose=1, save_best_only=True) |
|
|
17 |
# Generates batches of image data with data augmentationV |
|
|
18 |
datagen = ImageDataGenerator(rotation_range=360, # Degree range for random rotations |
|
|
19 |
width_shift_range=0.2, # Range for random horizontal shifts |
|
|
20 |
height_shift_range=0.2, # Range for random vertical shifts |
|
|
21 |
zoom_range=0.2, # Range for random zoom |
|
|
22 |
horizontal_flip=True, # Randomly flip inputs horizontally |
|
|
23 |
vertical_flip=True) # Randomly flip inputs vertically |
|
|
24 |
|
|
|
25 |
datagen.fit(X_train) |
|
|
26 |
# Fits the model on batches with real-time data augmentation |
|
|
27 |
hist = model.fit_generator(datagen.flow(X_train, Y_train, batch_size=BATCH_SIZE), |
|
|
28 |
steps_per_epoch=X_train.shape[0] //BATCH_SIZE, |
|
|
29 |
epochs=EPOCHS, |
|
|
30 |
verbose=2, |
|
|
31 |
callbacks=[annealer, checkpoint], |
|
|
32 |
validation_data=(X_val, Y_val)) |
|
|
33 |
|
|
|
34 |
#model.save("check.h5") |
|
|
35 |
#model.fit(X_train,Y_train,batch_size=BATCH_SIZE,steps_per_epoch=X_train.shape[0] // BATCH_SIZE, epochs=EPOCHS) |
|
|
36 |
|