-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
45 lines (33 loc) · 1.13 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import logging
import hydra
import matplotlib.pyplot as plt
import pytorch_lightning as pl
import spconv.pytorch as spconv
import torch
plt.switch_backend('agg')
import learnableearthparser
logger = logging.getLogger(__name__)
@hydra.main(config_path="configs", config_name="defaults")
def main(cfg) -> None:
# Fixing random seed
if cfg.seed != 0: pl.seed_everything(cfg.seed)
# Loading dataset
cfg.data._target_ = f"EarthParserDataset.{cfg.data._target_}"
datamodule = hydra.utils.instantiate(cfg.data)
datamodule.setup(cfg.mode)
# Instantiating model
model = hydra.utils.instantiate(
cfg.model,
_recursive_=False,
)
model.__initprotos__(datamodule)
# Loading weights
if cfg.model.load_weights != "":
logger.info("Loading weights from %s", cfg.model.load_weights)
model.load_state_dict(torch.load(cfg.model.load_weights)["state_dict"], strict=False)
# Instantiating trainer
trainer = learnableearthparser.trainers.get_trainer(cfg)
# Running training
getattr(trainer, cfg.mode)(model, datamodule=datamodule)
if __name__ == '__main__':
main()