MCPcopy Index your code
hub / github.com/AIRMEC/HECTOR / run_train_eval_loop

Function run_train_eval_loop

train.py:149–263  ·  view source on GitHub ↗
(train_loader, val_loader, loss_fn, hparams, run_id, BS_data, checkpoint_model_molecular)

Source from the content-addressed store, hash-verified

147 writer.add_scalar("C_index/train", train_c_index, epoch)
148
149def run_train_eval_loop(train_loader, val_loader, loss_fn, hparams, run_id, BS_data, checkpoint_model_molecular):
150 writer = SummaryWriter(os.path.join("./runs", run_id))
151 device = torch.device("cuda")
152 n_bins = hparams["n_bins"]
153
154 model = HECTOR(
155 input_feature_size=hparams["input_feature_size"],
156 precompression_layer=hparams["precompression_layer"],
157 feature_size_comp=hparams["feature_size_comp"],
158 feature_size_attn=hparams["feature_size_attn"],
159 postcompression_layer=hparams["postcompression_layer"],
160 feature_size_comp_post=hparams["feature_size_comp_post"],
161 dropout=True,
162 p_dropout_fc=hparams["p_dropout_fc"],
163 p_dropout_atn=hparams["p_dropout_atn"],
164 n_classes=n_bins,
165
166 input_stage_size=hparams["input_stage_size"],
167 embedding_dim_stage=hparams["embedding_dim_stage"],
168 depth_dim_stage=hparams["depth_dim_stage"],
169 act_fct_stage=hparams["act_fct_stage"],
170 dropout_stage=hparams["dropout_stage"],
171 p_dropout_stage=hparams["p_dropout_stage"],
172
173 input_mol_size=4,
174 embedding_dim_mol=hparams["embedding_dim_mol"],
175 depth_dim_mol=hparams["depth_dim_mol"],
176 act_fct_mol=hparams["act_fct_mol"],
177 dropout_mol=hparams["dropout_mol"],
178 p_dropout_mol=hparams["p_dropout_mol"],
179
180 fusion_type=hparams["fusion_type"],
181 use_bilinear=hparams["use_bilinear"],
182 gate_hist=hparams["gate_hist"],
183 gate_stage=hparams["gate_stage"],
184 gate_mol=hparams["gate_mol"],
185 scale=hparams["scale"],
186 ).to(device)
187 print('model')
188 print_model(model)
189
190 # This model is instance with the trained weights towards molecular classification and will be used in inference mode only.
191 # NOTE: it is important that the molecular model, here im4MEC, has been trained on the same patients as training to avoid patient-level information leakage.
192 model_mol = Im4MEC(
193 input_feature_size=hparams["input_feature_size"],
194 precompression_layer=True,
195 feature_size_comp=hparams["feature_size_comp_molecular"],
196 feature_size_attn=hparams["feature_size_attn_molecular"],
197 n_classes=hparams["n_classes_molecular"],
198 dropout=True, # Not used in inference.
199 p_dropout_fc=0.25,
200 p_dropout_atn=0.25,
201 ).to(device)
202
203 msg = model_mol.load_state_dict(torch.load(checkpoint_model_molecular, map_location=device), strict=True)
204 print(msg)
205
206 for p in model_mol.parameters():

Callers 1

mainFunction · 0.85

Calls 6

HECTORClass · 0.90
Im4MECClass · 0.90
print_modelFunction · 0.85
train_one_epochFunction · 0.85
evaluate_modelFunction · 0.85

Tested by

no test coverage detected