MCPcopy Create free account
hub / github.com/BMEII-AI/RadImageNet / run_model

Function run_model

covid19/covid19_train.py:163–189  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

161
162
163def run_model():
164 train_steps = len(train_generator.labels)/ batch_size
165 val_steps = len(validation_generator.labels) / batch_size
166
167 filepath= "models/covid19-"+args.structure+ "-" + database + "-" + args.model_name + "-" + str(image_size) + "-" + str(batch_size) + "-"+str(args.lr)+ ".h5" #### set the path to save models having lowest validation loss during training
168 checkpoint = ModelCheckpoint(filepath, monitor='val_loss', verbose=1, save_best_only=True, mode='min')
169 tensorboard = TensorBoard(log_dir="logs/{}".format(time()))
170
171
172 history = model.fit_generator(
173 train_generator,
174 epochs=num_epoches,
175 steps_per_epoch=train_steps,
176 validation_data=validation_generator,
177 validation_steps=val_steps,
178 use_multiprocessing=True,
179 workers=20,
180 callbacks=[checkpoint,tensorboard])
181
182
183 ### Save training loss
184 train_auc = history.history['auc']
185 val_auc = history.history['val_auc']
186 train_loss = history.history['loss']
187 val_loss = history.history['val_loss']
188 d_loss = pd.DataFrame({'train_auc':train_auc, 'val_auc':val_auc, 'train_loss':train_loss, 'val_loss':val_loss})
189 d_loss.to_excel("loss/covid19-" +args.structure+ "-" + database + "-" + args.model_name + "-" + str(image_size) + "-" + str(batch_size) + "-"+str(args.lr)+ ".csv", index=False)
190
191
192

Callers 1

covid19_train.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected