lr = opt.lr * (gamma ** (step)) print('change learning rate, now learning rate is :', lr) for param_group in optimizer.param_groups: param_group['lr'] = lr if __name__ == '__main__': print_config('config.py') print('now runing on device : ', device) if not os.path.exists(opt.save_folder): os.mkdir(opt.save_folder) model = SSD(opt.num_classes, opt.anchor_num) if opt.resume: print('loading checkpoint...') model.load_state_dict(torch.load(opt.resume)) else: vgg_weights = torch.load(opt.save_folder + opt.basenet) print('Loading base network...') model.vgg.load_state_dict(vgg_weights) model.to(device) model.train() mb = MultiBoxEncoder(opt) image_sets = [['2007', 'trainval'], ['2012', 'trainval']]
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu') voc_root = opt.VOC_ROOT annopath = os.path.join(voc_root, 'VOC2007', 'Annotations', "%s.xml") #真实的标签坐标所在的地方 imgpath = os.path.join(voc_root, 'VOC2007', 'JPEGImages', '%s.jpg') #图片所在的地方 imgsetpath = os.path.join(voc_root, 'VOC2007', 'ImageSets', 'Main', '{:s}.txt') #测试集的txt文件存在的地方 cachedir = os.path.join(os.getcwd(), 'annotations_cache') #暂存这些信息的地方 if __name__ == '__main__': print('using {} to eval, use cpu may take an hour to complete !!'.format( device)) model = SSD(opt.num_classes, opt.anchor_num) print('loading checkpoint from {}'.format(checkpoint)) state_dict = torch.load( checkpoint, map_location=None if torch.cuda.is_available() else 'cpu') model.load_state_dict(state_dict) model.to(device) print('model loaded') multibox_encoder = MultiBoxEncoder(opt) image_sets = [['2007', 'test']] test_dataset = VOCDetection(opt, image_sets=image_sets, is_train=False) os.makedirs(output_dir, exist_ok=True)
""" lr = opt.lr * (gamma**(step)) print('change learning rate, now learning rate is :', lr) for param_group in optimizer.param_groups: param_group['lr'] = lr if __name__ == '__main__': print_config('config.py') print('now runing on device : ', device) if not os.path.exists(opt.save_folder): os.mkdir(opt.save_folder) model = SSD(opt.num_classes, opt.anchor_num) if opt.resume: print('loading checkpoint...') model.load_state_dict(torch.load(opt.resume)) else: vgg_weights = torch.load(opt.save_folder + opt.basenet) print('Loading base network...') model.vgg.load_state_dict(vgg_weights) model.to(device) model.train() mb = MultiBoxEncoder(opt) image_sets = [['2007', 'trainval'], ['2012', 'trainval']] dataset = CustomDetection(