# 是否加载之前保存的模型 if args.resume: print(' # Resuming from checkpoint # ') checkpoint = torch.load(opt.ckpt_path) net.load_state_dict(checkpoint['net']) best_loss = checkpoint['loss'] start_epoch = checkpoint['epoch'] # 加载预训练的模型 else: print(' # Loading pretrained model # ') net.load_state_dict(torch.load(opt.pretrained_model)) criterion = MultiBoxLoss() if use_cuda: net.cuda() criterion.cuda() cudnn.benchmark = True optimizer = optim.SGD(net.parameters(), lr=args.lr, momentum=0.9, weight_decay=1e-4) print('## SSD Build success ##') #for param in net.parameters(): # if param.requires_grad==True: # print('param autograd') # break def train(epoch):
#random_seed random.seed(opt.seed) np.random.seed(opt.seed) torch.manual_seed(opt.seed) torch.cuda.manual_seed_all(opt.seed) PRNG = RandomState(opt.seed) # model model = SSD(opt.n_classes) cfg = model.config model.init_parameters(opt.pretrainedvgg) criterion = MultiBoxLoss() model.cuda() criterion.cuda() cudnn.benchmark = True #print(cfg) #print('') #dataload dataset = data.loader(cfg, opt.augmentation, opt.data_path ,PRNG) print('size of dataset:', len(dataset)) # optimizer optimizer = optim.SGD(model.parameters(), lr=opt.lr, momentum=opt.momentum, weight_decay=opt.weight_decay) def train():