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

Function run_model

meniscus/meniscus_train.py:101–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

meniscus_train.pyFile · 0.70

Calls 1

get_compiled_modelFunction · 0.70

Tested by

no test coverage detected