MCPcopy Index your code
hub / github.com/CandleLabAI/PCBSegClassNet / main

Function main

src/train_classification.py:42–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40
41
42def main():
43 opt = parse_config()
44 init_log(opt)
45
46 # get dataloaders
47 trainDS, valDS = get_data(opt)
48 logger = logging.getLogger(__name__)
49 logger.info(f"Found {len(trainDS)} batches for training")
50 logger.info(f"Found {len(valDS)} batches for validation")
51
52 # get model
53 model = get_model(opt)
54 logger.info(model.summary())
55
56 callbacks = []
57 if "modelcheckpoint" in opt["train"]["callbacks"]:
58 logger.info("Using modelcheckpoint callback")
59 callbacks.append(
60 getattr(
61 tf.keras.callbacks, opt["train"]["callbacks"]["modelcheckpoint"]["type"]
62 )(
63 filepath=opt["path"]["checkpoint_network"],
64 monitor=opt["train"]["callbacks"]["modelcheckpoint"]["monitor"],
65 mode=opt["train"]["callbacks"]["modelcheckpoint"]["mode"],
66 verbose=opt["train"]["callbacks"]["modelcheckpoint"]["verbose"],
67 save_best_only=opt["train"]["callbacks"]["modelcheckpoint"][
68 "save_best_only"
69 ],
70 save_weights_only=opt["train"]["callbacks"]["modelcheckpoint"][
71 "save_weights_only"
72 ],
73 )
74 )
75
76 if "reducelronplateau" in opt["train"]["callbacks"]:
77 logger.info("Using reducelronplateau callback")
78 callbacks.append(
79 getattr(
80 tf.keras.callbacks,
81 opt["train"]["callbacks"]["reducelronplateau"]["type"],
82 )(
83 monitor=opt["train"]["callbacks"]["reducelronplateau"]["monitor"],
84 mode=opt["train"]["callbacks"]["reducelronplateau"]["mode"],
85 verbose=opt["train"]["callbacks"]["reducelronplateau"]["verbose"],
86 factor=opt["train"]["callbacks"]["reducelronplateau"]["factor"],
87 patience=opt["train"]["callbacks"]["reducelronplateau"]["patience"],
88 min_lr=opt["train"]["callbacks"]["reducelronplateau"]["min_lr"],
89 )
90 )
91
92 # training model
93 if opt["train"]["total_epochs"] > 0:
94 logger.info(f"Training for {opt['train']['total_epochs']} epochs")
95 model.fit(
96 trainDS,
97 validation_data=valDS,
98 epochs=opt["train"]["total_epochs"],
99 verbose=1,

Callers 1

Calls 4

get_dataFunction · 0.90
get_modelFunction · 0.90
parse_configFunction · 0.70
init_logFunction · 0.70

Tested by

no test coverage detected