本文整理汇总了Python中config.cfg方法的典型用法代码示例。如果您正苦于以下问题:Python config.cfg方法的具体用法?Python config.cfg怎么用?Python config.cfg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类config
的用法示例。
在下文中一共展示了config.cfg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evaluateimage
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def evaluateimage(file_path, mode, eval_model=None):
#from plot_helpers import eval_and_plot_faster_rcnn
if eval_model==None:
print("Loading existing model from %s" % model_path)
eval_model = load_model(model_path)
img_shape = (num_channels, image_height, image_width)
results_folder = globalvars['temppath']
results=eval_faster_rcnn(eval_model, file_path, img_shape,
results_folder, feature_node_name, globalvars['classes'], mode,
drawUnregressedRois=cfg["CNTK"].DRAW_UNREGRESSED_ROIS,
drawNegativeRois=cfg["CNTK"].DRAW_NEGATIVE_ROIS,
nmsThreshold=cfg["CNTK"].RESULTS_NMS_THRESHOLD,
nmsConfThreshold=cfg["CNTK"].RESULTS_NMS_CONF_THRESHOLD,
bgrPlotThreshold=cfg["CNTK"].RESULTS_BGR_PLOT_THRESHOLD)
return results
示例2: pre_process
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def pre_process(image, cfg=None, scale=1, meta=None):
height, width = image.shape[0:2]
new_height = int(height * scale)
new_width = int(width * scale)
mean = np.array(cfg.DATASET.MEAN, dtype=np.float32).reshape(1, 1, 3)
std = np.array(cfg.DATASET.STD, dtype=np.float32).reshape(1, 1, 3)
inp_height, inp_width = cfg.MODEL.INPUT_H, cfg.MODEL.INPUT_W
c = np.array([new_width / 2., new_height / 2.], dtype=np.float32)
s = max(height, width) * 1.0
trans_input = get_affine_transform(c, s, 0, [inp_width, inp_height])
resized_image = cv2.resize(image, (new_width, new_height))
inp_image = cv2.warpAffine(
resized_image, trans_input, (inp_width, inp_height),
flags=cv2.INTER_LINEAR)
inp_image = ((inp_image / 255. - mean) / std).astype(np.float32)
images = inp_image.transpose(2, 0, 1).reshape(1, 3, inp_height, inp_width)
images = torch.from_numpy(images)
meta = {'c': c, 's': s,
'out_height': inp_height // cfg.MODEL.DOWN_RATIO,
'out_width': inp_width // cfg.MODEL.DOWN_RATIO}
return images, meta
示例3: get_record_id
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def get_record_id(domain, sub_domain):
url = 'https://dnsapi.cn/Record.List'
params = parse.urlencode({
'login_token': cfg['login_token'],
'format': 'json',
'domain': domain
})
req = request.Request(url=url, data=params.encode('utf-8'), method='POST', headers=header())
try:
resp = request.urlopen(req).read().decode()
except (error.HTTPError, error.URLError, socket.timeout):
return None
records = json.loads(resp).get('records', {})
for item in records:
if item.get('name') == sub_domain:
return item.get('id')
return None
示例4: update_record
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def update_record():
url = 'https://dnsapi.cn/Record.Ddns'
params = parse.urlencode({
'login_token': cfg['login_token'],
'format': 'json',
'domain': cfg['domain'],
'sub_domain': cfg['sub_domain'],
'record_id': cfg['record_id'],
'record_line': '默认'
})
req = request.Request(url=url, data=params.encode('utf-8'), method='POST', headers=header())
resp = request.urlopen(req).read().decode()
records = json.loads(resp)
cfg['last_update_time'] = str(time.gmtime())
logging.info("record updated: %s" % records)
# async def main():
示例5: get_keypoints_from_bbox
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def get_keypoints_from_bbox(pose_model, image, bbox):
x1,y1,w,h = bbox
bbox_input = []
bbox_input.append([x1, y1, x1+w, y1+h])
inputs, origin_img, center, scale = pre_process(image, bbox_input, scores=1, cfg=cfg)
with torch.no_grad():
# compute output heatmap
inputs = inputs[:,[2,1,0]]
output = pose_model(inputs.cuda())
# compute coordinate
preds, maxvals = get_final_preds(
cfg, output.clone().cpu().numpy(), np.asarray(center), np.asarray(scale))
# (N, 17, 3)
result = np.concatenate((preds, maxvals), -1)
return result
示例6: get_keypoints
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def get_keypoints(human_model, pose_model, image, smooth=None):
bboxs, scores = yolo_infrence(image, human_model)
# bbox is coordinate location
inputs, origin_img, center, scale = pre_process(image, bboxs, scores, cfg)
with torch.no_grad():
# compute output heatmap
inputs = inputs[:,[2,1,0]]
output = pose_model(inputs.cuda())
# compute coordinate
preds, maxvals = get_final_preds(
cfg, output.clone().cpu().numpy(), np.asarray(center), np.asarray(scale))
# (N, 17, 3)
result = np.concatenate((preds, maxvals), -1)
return result
示例7: _compute_targets
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def _compute_targets(ex_rois, gt_rois, labels):
"""Compute bounding-box regression targets for an image."""
assert ex_rois.shape[0] == gt_rois.shape[0]
assert ex_rois.shape[1] == 4
assert gt_rois.shape[1] == 4
targets = bbox_transform(ex_rois, gt_rois)
if cfg.TRAIN.BBOX_NORMALIZE_TARGETS_PRECOMPUTED:
# Optionally normalize targets by a precomputed mean and stdev
targets = ((targets - np.array(cfg.TRAIN.BBOX_NORMALIZE_MEANS))
/ np.array(cfg.TRAIN.BBOX_NORMALIZE_STDS))
return np.hstack((labels[:, np.newaxis], targets)).astype(np.float32, copy=False)
示例8: merge_outputs
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def merge_outputs(detections, cfg):
results = {}
results[1] = np.concatenate(
[detection[1] for detection in detections], axis=0).astype(np.float32)
if cfg.TEST.NMS or len(cfg.TEST.TEST_SCALES) > 1:
soft_nms_39(results[1], Nt=0.5, method=2)
results[1] = results[1].tolist()
return results
示例9: show_results
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def show_results(debugger, image, results, cfg):
debugger.add_img(image, img_id='multi_pose')
for bbox in results[1]:
if bbox[4] > cfg.TEST.VIS_THRESH:
debugger.add_coco_bbox(bbox[:4], 0, bbox[4], img_id='multi_pose')
debugger.add_coco_hp(bbox[5:39], img_id='multi_pose')
debugger.show_all_imgs(pause=True)
示例10: main
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def main(cfg):
model = create_model('res_50', cfg.MODEL.HEAD_CONV, cfg).cuda()
weight_path = '/home/tensorboy/data/centerpose/trained_best_model/res_50_best_model.pth'
state_dict = torch.load(weight_path, map_location=lambda storage, loc: storage)['state_dict']
model.load_state_dict(state_dict)
onnx_file_path = "./model/resnet50.onnx"
#img = cv2.imread('test_image.jpg')
image = cv2.imread('../images/image1.jpg')
images, meta = pre_process(image, cfg, scale=1)
model.cuda()
model.eval()
model.float()
torch_input = images.cuda()
print(torch_input.shape)
torch.onnx.export(model, torch_input, onnx_file_path, verbose=False)
sess = nxrun.InferenceSession(onnx_file_path)
input_name = sess.get_inputs()[0].name
label_name = sess.get_outputs()[0].name
print(input_name)
print(sess.get_outputs()[0].name)
print(sess.get_outputs()[1].name)
print(sess.get_outputs()[2].name)
output_onnx = sess.run(None, {input_name: images.cpu().data.numpy()})
hm, wh, hps, reg, hm_hp, hp_offset = output_onnx
print(hm)
print(len(output_onnx))
示例11: __init__
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def __init__(self, config_file, weight_file):
update_config(cfg, config_file)
self.cfg = cfg
self.trtmodel = TRTModel(weight_file)
示例12: post_process
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def post_process(self, dets, meta, scale=1):
dets = dets.detach().cpu().numpy().reshape(1, -1, dets.shape[2])
dets = self.multi_pose_post_process(
dets.copy(), [meta['c']], [meta['s']],
meta['out_height'], meta['out_width'])
for j in range(1, self.cfg.MODEL.NUM_CLASSES + 1):
dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 56)
dets[0][j][:, :4] /= scale
dets[0][j][:, 5:] /= scale
return dets[0]
示例13: postprocess
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def postprocess(self, hm, wh, hps, reg, hm_hp, hp_offset, meta):
hm = hm.sigmoid_()
hm_hp = hm_hp.sigmoid_()
detections = self.multi_pose_decode(hm, wh, hps, reg=reg, hm_hp=hm_hp, hp_offset=hp_offset, K=self.cfg.TEST.TOPK)
dets = self.post_process(detections, meta, 1)
return dets
示例14: test_something
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def test_something(self):
net = nn.Linear(10, 10)
optimizer = make_optimizer(cfg, net)
lr_scheduler = WarmupMultiStepLR(optimizer, [20, 40], warmup_iters=10)
for i in range(50):
lr_scheduler.step()
for j in range(3):
print(i, lr_scheduler.get_lr()[0])
optimizer.step()
示例15: get_args_from_command_line
# 需要导入模块: import config [as 别名]
# 或者: from config import cfg [as 别名]
def get_args_from_command_line():
parser = ArgumentParser(description='Parser of Runner of Network')
parser.add_argument('--gpu', dest='gpu_id', help='GPU device id to use [cuda]', default=cfg.CONST.DEVICE, type=str)
parser.add_argument('--phase', dest='phase', help='phase of CNN', default=cfg.NETWORK.PHASE, type=str)
parser.add_argument('--weights', dest='weights', help='Initialize network from the weights file', default=cfg.CONST.WEIGHTS, type=str)
parser.add_argument('--data', dest='data_path', help='Set dataset root_path', default=cfg.DIR.DATASET_ROOT, type=str)
parser.add_argument('--out', dest='out_path', help='Set output path', default=cfg.DIR.OUT_PATH)
args = parser.parse_args()
return args