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

Function run_model

thyroid/thyroid_train.py:99–135  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

97 return model
98
99def run_model():
100 ### Set train steps and validation steps
101 ### Open a strategy scope.
102 with strategy.scope():
103 # Everything that creates variables should be under the strategy scope.
104 # In general this is only model construction & `compile()`.
105 model = get_compiled_model()
106 train_steps = len(train_generator.labels)/ batch_size
107 val_steps = len(validation_generator.labels) / batch_size
108
109 #### set the path to save models having lowest validation loss during training
110 save_model_dir = './models/'
111 if not os.path.exists(save_model_dir):
112 os.mkdir(save_model_dir)
113 filepath= "models/thyroid-"+args.structure+"-fold" + str(i+1) + "-" + database + "-" + args.model_name + "-" + str(image_size) + "-" + str(batch_size) + "-"+str(args.lr)+ ".h5"
114
115
116 checkpoint = ModelCheckpoint(filepath, monitor='val_loss', verbose=1, save_best_only=True, mode='min')
117 history = model.fit_generator(
118 train_generator,
119 epochs=num_epoches,
120 steps_per_epoch=train_steps,
121 validation_data=validation_generator,
122 validation_steps=val_steps,
123 use_multiprocessing=True,
124 workers=10,
125 callbacks=[checkpoint])
126 ### Save training loss
127 train_auc = history.history['auc']
128 val_auc = history.history['val_auc']
129 train_loss = history.history['loss']
130 val_loss = history.history['val_loss']
131 d_loss = pd.DataFrame({'train_auc':train_auc, 'val_auc':val_auc, 'train_loss':train_loss, 'val_loss':val_loss})
132 save_loss_dir = './loss'
133 if not os.path.exists(save_loss_dir):
134 os.mkdir(save_loss_dir)
135 d_loss.to_csv("loss/thyroid-"+args.structure+"-fold" + str(i+1) + "-" + database + "-" + args.model_name + "-" + str(image_size) + "-" + str(batch_size) + "-"+str(args.lr)+ ".csv", index=False)
136
137
138

Callers 1

thyroid_train.pyFile · 0.70

Calls 1

get_compiled_modelFunction · 0.70

Tested by

no test coverage detected