本文整理汇总了Python中data.BaseTransform方法的典型用法代码示例。如果您正苦于以下问题:Python data.BaseTransform方法的具体用法?Python data.BaseTransform怎么用?Python data.BaseTransform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类data
的用法示例。
在下文中一共展示了data.BaseTransform方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import data [as 别名]
# 或者: from data import BaseTransform [as 别名]
def main():
global args
args = arg_parse()
cfg_from_file(args.cfg_file)
bgr_means = cfg.TRAIN.BGR_MEAN
dataset_name = cfg.DATASETS.DATA_TYPE
batch_size = cfg.TEST.BATCH_SIZE
num_workers = args.num_workers
if cfg.DATASETS.DATA_TYPE == 'VOC':
trainvalDataset = VOCDetection
classes = VOC_CLASSES
top_k = 200
else:
trainvalDataset = COCODetection
classes = COCO_CLASSES
top_k = 300
valSet = cfg.DATASETS.VAL_TYPE
num_classes = cfg.MODEL.NUM_CLASSES
save_folder = args.save_folder
if not os.path.exists(save_folder):
os.mkdir(save_folder)
torch.set_default_tensor_type('torch.cuda.FloatTensor')
cfg.TRAIN.TRAIN_ON = False
net = SSD(cfg)
checkpoint = torch.load(args.weights)
state_dict = checkpoint['model']
from collections import OrderedDict
new_state_dict = OrderedDict()
for k, v in state_dict.items():
head = k[:7]
if head == 'module.':
name = k[7:] # remove `module.`
else:
name = k
new_state_dict[name] = v
net.load_state_dict(new_state_dict)
detector = Detect(cfg)
img_wh = cfg.TEST.INPUT_WH
ValTransform = BaseTransform(img_wh, bgr_means, (2, 0, 1))
input_folder = args.images
thresh = cfg.TEST.CONFIDENCE_THRESH
for item in os.listdir(input_folder):
img_path = os.path.join(input_folder, item)
print(img_path)
img = cv2.imread(img_path)
dets = im_detect(img, net, detector, ValTransform, thresh)
draw_img = draw_rects(img, dets, classes)
out_img_name = "output_" + item[:-4] + '_hsd'+item[-4:]
save_path = os.path.join(save_folder, out_img_name)
cv2.imwrite(save_path, img)
示例2: main
# 需要导入模块: import data [as 别名]
# 或者: from data import BaseTransform [as 别名]
def main():
global args
args = arg_parse()
cfg_from_file(args.cfg_file)
bgr_means = cfg.TRAIN.BGR_MEAN
dataset_name = cfg.DATASETS.DATA_TYPE
batch_size = cfg.TEST.BATCH_SIZE
num_workers = args.num_workers
if cfg.DATASETS.DATA_TYPE == 'VOC':
trainvalDataset = VOCDetection
top_k = 200
else:
trainvalDataset = COCODetection
top_k = 300
dataroot = cfg.DATASETS.DATAROOT
if cfg.MODEL.SIZE == '300':
size_cfg = cfg.SMALL
else:
size_cfg = cfg.BIG
valSet = cfg.DATASETS.VAL_TYPE
num_classes = cfg.MODEL.NUM_CLASSES
save_folder = args.save_folder
if not os.path.exists(save_folder):
os.mkdir(save_folder)
torch.set_default_tensor_type('torch.cuda.FloatTensor')
cfg.TRAIN.TRAIN_ON = False
net = SSD(cfg)
checkpoint = torch.load(args.weights)
state_dict = checkpoint['model']
from collections import OrderedDict
new_state_dict = OrderedDict()
for k, v in state_dict.items():
head = k[:7]
if head == 'module.':
name = k[7:] # remove `module.`
else:
name = k
new_state_dict[name] = v
net.load_state_dict(new_state_dict)
detector = Detect(cfg)
ValTransform = BaseTransform(size_cfg.IMG_WH, bgr_means, (2, 0, 1))
val_dataset = trainvalDataset(dataroot, valSet, ValTransform, "val")
val_loader = data.DataLoader(
val_dataset,
batch_size,
shuffle=False,
num_workers=num_workers,
collate_fn=detection_collate)
top_k = 300
thresh = cfg.TEST.CONFIDENCE_THRESH
eval_net(
val_dataset,
val_loader,
net,
detector,
cfg,
ValTransform,
top_k,
thresh=thresh,
batch_size=batch_size)
示例3: main
# 需要导入模块: import data [as 别名]
# 或者: from data import BaseTransform [as 别名]
def main():
global args
args = arg_parse()
cfg_from_file(args.cfg_file)
bgr_means = cfg.TRAIN.BGR_MEAN
dataset_name = cfg.DATASETS.DATA_TYPE
batch_size = cfg.TEST.BATCH_SIZE
num_workers = args.num_workers
if cfg.DATASETS.DATA_TYPE == 'VOC':
trainvalDataset = VOCDetection
classes = VOC_CLASSES
top_k = 200
else:
trainvalDataset = COCODetection
classes = COCO_CLASSES
top_k = 300
valSet = cfg.DATASETS.VAL_TYPE
num_classes = cfg.MODEL.NUM_CLASSES
save_folder = args.save_folder
if not os.path.exists(save_folder):
os.mkdir(save_folder)
torch.set_default_tensor_type('torch.cuda.FloatTensor')
cfg.TRAIN.TRAIN_ON = False
net = SSD(cfg)
checkpoint = torch.load(args.weights)
state_dict = checkpoint['model']
from collections import OrderedDict
new_state_dict = OrderedDict()
for k, v in state_dict.items():
head = k[:7]
if head == 'module.':
name = k[7:] # remove `module.`
else:
name = k
new_state_dict[name] = v
net.load_state_dict(new_state_dict)
detector = Detect(cfg)
img_wh = cfg.TEST.INPUT_WH
ValTransform = BaseTransform(img_wh, bgr_means, (2, 0, 1))
input_folder = args.images
thresh = cfg.TEST.CONFIDENCE_THRESH
for item in os.listdir(input_folder)[2:3]:
img_path = os.path.join(input_folder, item)
print(img_path)
img = cv2.imread(img_path)
dets = im_detect(img, net, detector, ValTransform, thresh)
draw_img = draw_rects(img, dets, classes)
out_img_name = "output_" + item
save_path = os.path.join(save_folder, out_img_name)
cv2.imwrite(save_path, img)