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

Function run_model

acl/acl_train.py:104–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

acl_train.pyFile · 0.70

Calls 1

get_compiled_modelFunction · 0.70

Tested by

no test coverage detected