in src/models.py [0:0]
def load_latest_weights(self, path, optimizer=None, device=0, config=None):
ckpts = [os.path.join(path, f) for f in sorted(os.listdir(os.path.join(path))) if
'.weights' in f and self.name in f and '_opt.weights' not in f]
if len(ckpts) == 0:
print("no Checkpoints found")
if config and config.preTrained and len(config.preTrained) > self.net_idx and config.preTrained[self.net_idx].lower() != "none":
wpath = os.path.join(config.preTrained[self.net_idx], f"{self.name}.weights")
if os.path.exists(wpath):
print("loading pretrained weights")
self.load_weights(wpath, device)
else:
print(f"WARNING pretrained weights not found: {wpath}")
opath = wpath = os.path.join(config.preTrained[self.net_idx], f"{self.name}.optimizer")
if optimizer is not None and os.path.exists(opath):
self.load_optimizer(opath, optimizer, device)
return 0
ckpt_path = ckpts[-1]
try:
epoch = int(ckpt_path.split('.weights')[0].split('_')[-1])
except ValueError:
epoch = 0
self.load_weights(ckpt_path, device)
if optimizer is not None:
optim_path = f"{ckpt_path.split('.weights')[0]}.optimizer"
self.load_optimizer(optim_path, optimizer, device)
return epoch