TEST
print(‘Loading model…’)
#-net = RetinaNet()
net = RetinaNet(backbone=cfg.backbone, num_classes=len(cfg.classes),pretrained=False)
map_location = lambda storage, loc: storage
ipdb.set_trace()
#net.load_state_dict(torch.load(’.store\ckpt6.pth’)[‘net’])
net.load_state_dict(torch.load(’.store/ckpt6.pth’,map_location=‘cpu’)[‘net’],strict=False)
print(torch.load(’.store/ckpt6.pth’,map_location=map_location)[‘lr’])
print(torch.load(’.store/ckpt6.pth’,map_location=map_location)[‘epoch’])
#z=net.named_modules()
#for x,xx in subnet4.named_parameters():
print(x,xx)
ipdb.set_trace()
subnet1=net.resnet
print(net.resnet.training)
subnet2=net.feature_pyramid
print(net.feature_pyramid.training)
subnet3=net.subnet_boxes
print(net.subnet_boxes.training)
subnet4=net.subnet_classes
print(net.subnet_classes.training)
subnet1.eval()
print(net.resnet.training)
for x in subnet1._modules:
print(subnet1._modules[x].training)
for x in subnet2._modules:
subnet2._modules[x].eval()
for x in subnet3._modules:
subnet3._modules[x].eval()
for x in subnet4._modules:
subnet4._modules[x].eval()
subnet2.eval()
print(net.feature_pyramid.training)
subnet3.eval()
print(net.subnet_boxes.training)
subnet4.eval()
print(net.subnet_classes.training)
TRAIN
net = RetinaNet(backbone=cfg.backbone, num_classes=len(cfg.classes))
net = torch.nn.DataParallel(net, device_ids=range(torch.cuda.device_count()))
net.cuda()
def save_checkpoint(loss, net, n):
global best_loss
loss /= n
if loss < best_loss:
print(‘Saving…’)
state = {
‘net’: net.state_dict(),
‘loss’: loss,
‘epoch’: epoch,
‘lr’: lr
}
# ckpt_path = os.path.join(‘ckpts’, args.exp)
ckpt_path = ‘.store’
if not os.path.isdir(ckpt_path):
os.makedirs(ckpt_path)
torch.save(state, os.path.join(ckpt_path, ‘ckpt.pth’))
best_loss = loss