本文整理汇总了Python中config.cfg.lr方法的典型用法代码示例。如果您正苦于以下问题:Python cfg.lr方法的具体用法?Python cfg.lr怎么用?Python cfg.lr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类config.cfg
的用法示例。
在下文中一共展示了cfg.lr方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from config import cfg [as 别名]
# 或者: from config.cfg import lr [as 别名]
def __init__(self):
self.reader=Image_reader(mode='vedio')
self.model_dir=cfg.model_dir
self.vedio_dir=cfg.vedio_dir
self.vedio_name=cfg.vedio_name
self.anchor_op=Anchor(17,17)
self.anchors=self.anchor_op.anchors
self.anchors=self.anchor_op.corner_to_center(self.anchors)
self.penalty_k=cfg.penalty_k
self.window_influence=cfg.window_influence
self.lr=cfg.lr
#===================init-parameter==================
self.selectingObject = False
self.initTracking = False
self.onTracking = False
self.ix, self.iy, self.cx, self.cy = -1, -1, -1, -1
self.w, self.h = 0, 0
self.inteval = 1
self.duration = 0.01
self.select=True
#===================init-parameter==================
示例2: recover
# 需要导入模块: from config import cfg [as 别名]
# 或者: from config.cfg import lr [as 别名]
def recover(self,img,box,offset,ratio,pre_box,score):
#label=[c_x,c_y,w,h]
box[2]=box[2]*ratio
box[3]=box[3]*ratio
box[0]=box[0]*ratio+offset[0]
box[1]=box[1]*ratio+offset[1]
if score<0.9:
box[2] = pre_box[2]
box[3] = pre_box[3]
else:
box[2] = pre_box[2] * (1 - self.lr) + box[2] * self.lr
box[3] = pre_box[3] * (1 - self.lr) + box[3] * self.lr
note=np.zeros((5),dtype=np.float32)
note[0:4]=box
note[4]=score
self.note.append(note)
box[0]=int(box[0]-(box[2]-1)/2)
box[1]=int(box[1]-(box[3]-1)/2)
box[2]=round(box[0]+(box[2]))
box[3]=round(box[1]+(box[3]))
# #+++++++++++++++++++++debug++++++++++++++++++++++++++++++
# cv2.rectangle(img,(int(box[0]),int(box[1])),(int(box[2]),int(box[3])),(255,0,0),1)
# cv2.imshow('ori',img)
# cv2.waitKey(0)
# #+++++++++++++++++++++debug++++++++++++++++++++++++++++++
return box#[x1,y1,x2,y2]
示例3: __init__
# 需要导入模块: from config import cfg [as 别名]
# 或者: from config.cfg import lr [as 别名]
def __init__(self):
self.reader=Image_reader(img_path=cfg.img_path,label_path=cfg.label_path)
self.model_dir=cfg.model_dir
self.anchor_op=Anchor(17,17)
self.anchors=self.anchor_op.anchors
self.anchors=self.anchor_op.corner_to_center(self.anchors)
self.penalty_k=cfg.penalty_k
self.window_influence=cfg.window_influence
self.lr=cfg.lr
self.vedio_dir=cfg.vedio_dir
self.vedio_name=cfg.vedio_name
示例4: get_optimizer
# 需要导入模块: from config import cfg [as 别名]
# 或者: from config.cfg import lr [as 别名]
def get_optimizer(self, model):
optimizer = torch.optim.Adam(model.parameters(), lr=cfg.lr)
return optimizer
示例5: set_lr
# 需要导入模块: from config import cfg [as 别名]
# 或者: from config.cfg import lr [as 别名]
def set_lr(self, epoch):
for e in cfg.lr_dec_epoch:
if epoch < e:
break
if epoch < cfg.lr_dec_epoch[-1]:
idx = cfg.lr_dec_epoch.index(e)
for g in self.optimizer.param_groups:
g['lr'] = cfg.lr / (cfg.lr_dec_factor ** idx)
else:
for g in self.optimizer.param_groups:
g['lr'] = cfg.lr / (cfg.lr_dec_factor ** len(cfg.lr_dec_epoch))
示例6: get_lr
# 需要导入模块: from config import cfg [as 别名]
# 或者: from config.cfg import lr [as 别名]
def get_lr(self):
for g in self.optimizer.param_groups:
cur_lr = g['lr']
return cur_lr
示例7: get_optimizer
# 需要导入模块: from config import cfg [as 别名]
# 或者: from config.cfg import lr [as 别名]
def get_optimizer():
if cfg.optimizer == 'sgd':
opt = SGD(lr=cfg.lr, decay=1e-6, momentum=0.9, nesterov=True, clipnorm=5)
elif cfg.optimizer == 'adam':
opt = Adam(lr=cfg.lr)
else:
raise ValueError('Wrong optimizer name')
return opt
示例8: get_optimizer
# 需要导入模块: from config import cfg [as 别名]
# 或者: from config.cfg import lr [as 别名]
def get_optimizer(self, model):
optimizer = torch.optim.Adam(model.parameters(), lr=cfg.lr)
return optimizer
示例9: get_lr
# 需要导入模块: from config import cfg [as 别名]
# 或者: from config.cfg import lr [as 别名]
def get_lr(self):
for g in self.optimizer.param_groups:
cur_lr = g['lr']
return cur_lr
示例10: main
# 需要导入模块: from config import cfg [as 别名]
# 或者: from config.cfg import lr [as 别名]
def main(args):
# create checkpoint dir
if not isdir(args.checkpoint):
mkdir_p(args.checkpoint)
# create model
model = network.__dict__[cfg.model](cfg.output_shape, cfg.num_class, pretrained = True)
model = torch.nn.DataParallel(model).cuda()
# define loss function (criterion) and optimizer
criterion1 = torch.nn.MSELoss().cuda() # for Global loss
criterion2 = torch.nn.MSELoss(reduce=False).cuda() # for refine loss
optimizer = torch.optim.Adam(model.parameters(),
lr = cfg.lr,
weight_decay=cfg.weight_decay)
if args.resume:
if isfile(args.resume):
print("=> loading checkpoint '{}'".format(args.resume))
checkpoint = torch.load(args.resume)
pretrained_dict = checkpoint['state_dict']
model.load_state_dict(pretrained_dict)
args.start_epoch = checkpoint['epoch']
optimizer.load_state_dict(checkpoint['optimizer'])
print("=> loaded checkpoint '{}' (epoch {})"
.format(args.resume, checkpoint['epoch']))
logger = Logger(join(args.checkpoint, 'log.txt'), resume=True)
else:
print("=> no checkpoint found at '{}'".format(args.resume))
else:
logger = Logger(join(args.checkpoint, 'log.txt'))
logger.set_names(['Epoch', 'LR', 'Train Loss'])
cudnn.benchmark = True
print(' Total params: %.2fMB' % (sum(p.numel() for p in model.parameters())/(1024*1024)*4))
train_loader = torch.utils.data.DataLoader(
MscocoMulti(cfg),
batch_size=cfg.batch_size*args.num_gpus, shuffle=True,
num_workers=args.workers, pin_memory=True)
for epoch in range(args.start_epoch, args.epochs):
lr = adjust_learning_rate(optimizer, epoch, cfg.lr_dec_epoch, cfg.lr_gamma)
print('\nEpoch: %d | LR: %.8f' % (epoch + 1, lr))
# train for one epoch
train_loss = train(train_loader, model, [criterion1, criterion2], optimizer)
print('train_loss: ',train_loss)
# append logger file
logger.append([epoch + 1, lr, train_loss])
save_model({
'epoch': epoch + 1,
'state_dict': model.state_dict(),
'optimizer' : optimizer.state_dict(),
}, checkpoint=args.checkpoint)
logger.close()
示例11: nms
# 需要导入模块: from config import cfg [as 别名]
# 或者: from config.cfg import lr [as 别名]
def nms(self,img,scores,delta,gt_p):
img=(img*255).astype(np.uint8)
target_sz=gt_p[2:]
score=scores[:,1]
# #+++++++++++++++++++++debug++++++++++++++++++++++++++++++
# b=self.anchor_op.center_to_corner(gt_p.reshape((1,4)))
# cv2.rectangle(img,(int(b[0][0]),int(b[0][1])),(int(b[0][2]),int(b[0][3])),(0,255,0),1)
# #+++++++++++++++++++++debug++++++++++++++++++++++++++++++
bboxes=np.zeros_like(delta)
bboxes[:,0]=delta[:,0]*self.anchors[:,2]+self.anchors[:,0]
bboxes[:,1]=delta[:,1]*self.anchors[:,3]+self.anchors[:,1]
bboxes[:,2]=np.exp(delta[:,2])*self.anchors[:,2]
bboxes[:,3]=np.exp(delta[:,3])*self.anchors[:,3]#[x,y,w,h]
def change(r):
return np.maximum(r, 1./r)
def sz(w, h):
pad = (w + h) * 0.5
sz2 = (w + pad) * (h + pad)
return np.sqrt(sz2)
def sz_wh(wh):
pad = (wh[0] + wh[1]) * 0.5
sz2 = (wh[0] + pad) * (wh[1] + pad)
return np.sqrt(sz2)
# size penalty
s_c = change(sz(bboxes[:,2], bboxes[:,3]) / (sz_wh(target_sz))) # scale penalty
r_c = change((target_sz[0] / target_sz[1]) / (bboxes[:,2] / bboxes[:,3])) # ratio penalty
penalty = np.exp(-(r_c * s_c - 1.) * self.penalty_k)
pscore = penalty * score
# window float
pscore = pscore * (1 - self.window_influence) + self.window * self.window_influence
# #==================debug=====================
# pscore = score
# #==================debug=====================
best_pscore_id = np.argmax(pscore)
best_pscore = np.max(pscore)
print(best_pscore)
self.lr = penalty[best_pscore_id] * score[best_pscore_id] * self.lr
bbox=bboxes[best_pscore_id].reshape((1,4))#[x,y,w,h]
# #+++++++++++++++++++++debug++++++++++++++++++++++++++++++
# b=self.anchor_op.center_to_corner(bbox)
# cv2.rectangle(img,(int(b[0][0]),int(b[0][1])),(int(b[0][2]),int(b[0][3])),(255,0,0),1)
# cv2.imshow('resize',img)
# cv2.waitKey(0)
# #+++++++++++++++++++++debug++++++++++++++++++++++++++++++
return bbox[0],best_pscore
示例12: nms
# 需要导入模块: from config import cfg [as 别名]
# 或者: from config.cfg import lr [as 别名]
def nms(self,img,scores,delta,gt_p):
img=(img*255).astype(np.uint8)
target_sz=gt_p[2:]
score=scores[:,1]
bboxes=np.zeros_like(delta)
bboxes[:,0]=delta[:,0]*self.anchors[:,2]+self.anchors[:,0]
bboxes[:,1]=delta[:,1]*self.anchors[:,3]+self.anchors[:,1]
bboxes[:,2]=np.exp(delta[:,2])*self.anchors[:,2]
bboxes[:,3]=np.exp(delta[:,3])*self.anchors[:,3]#[x,y,w,h]
def change(r):
return np.maximum(r, 1./r)
def sz(w, h):
pad = (w + h) * 0.5
sz2 = (w + pad) * (h + pad)
return np.sqrt(sz2)
def sz_wh(wh):
pad = (wh[0] + wh[1]) * 0.5
sz2 = (wh[0] + pad) * (wh[1] + pad)
return np.sqrt(sz2)
# size penalty
s_c = change(sz(bboxes[:,2], bboxes[:,3]) / (sz_wh(target_sz))) # scale penalty
r_c = change((target_sz[0] / target_sz[1]) / (bboxes[:,2] / bboxes[:,3])) # ratio penalty
penalty = np.exp(-(r_c * s_c - 1.) * self.penalty_k)
pscore = penalty * score
# window float
pscore = pscore * (1 - self.window_influence) + self.window * self.window_influence
best_pscore_id = np.argmax(pscore)
self.lr = penalty[best_pscore_id] * score[best_pscore_id] * self.lr
bbox=bboxes[best_pscore_id].reshape((1,4))#[x,y,w,h]
#+++++++++++++++++++++debug++++++++++++++++++++++++++++++
# b=self.anchor_op.center_to_corner(bbox)
# cv2.rectangle(img,(int(b[0][0]),int(b[0][1])),(int(b[0][2]),int(b[0][3])),(255,0,0),1)
# cv2.imshow('resize',img)
# cv2.waitKey(0)
#+++++++++++++++++++++debug++++++++++++++++++++++++++++++
return bbox[0]