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

Function run_model

breast/breast_train.py:100–136  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98
99
100def run_model():
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 ### Set train steps and validation steps
107 train_steps = len(train_generator.labels)/ batch_size
108 val_steps = len(validation_generator.labels) / batch_size
109
110 #### set the path to save models having lowest validation loss during training
111 save_model_dir = './models/'
112 if not os.path.exists(save_model_dir):
113 os.mkdir(save_model_dir)
114 filepath= "models/breast-"+args.structure+"-fold" + str(i+1) + "-" + database + "-" + args.model_name + "-" + str(image_size) + "-" + str(batch_size) + "-"+str(args.lr)+ ".h5"
115
116
117 checkpoint = ModelCheckpoint(filepath, monitor='val_loss', verbose=1, save_best_only=True, mode='min')
118 history = model.fit_generator(
119 train_generator,
120 epochs=num_epoches,
121 steps_per_epoch=train_steps,
122 validation_data=validation_generator,
123 validation_steps=val_steps,
124 use_multiprocessing=True,
125 workers=10,
126 callbacks=[checkpoint])
127 ### Save training loss
128 train_auc = history.history['auc']
129 val_auc = history.history['val_auc']
130 train_loss = history.history['loss']
131 val_loss = history.history['val_loss']
132 d_loss = pd.DataFrame({'train_auc':train_auc, 'val_auc':val_auc, 'train_loss':train_loss, 'val_loss':val_loss})
133 save_loss_dir = './loss'
134 if not os.path.exists(save_loss_dir):
135 os.mkdir(save_loss_dir)
136 d_loss.to_csv("loss/breast-"+args.structure+"-fold" + str(i+1) + "-" + database + "-" + args.model_name + "-" + str(image_size) + "-" + str(batch_size) + "-"+str(args.lr)+ ".csv", index=False)
137
138
139

Callers 1

breast_train.pyFile · 0.70

Calls 1

get_compiled_modelFunction · 0.70

Tested by

no test coverage detected