Python data.BaseTransform() Examples
The following are 4
code examples of data.BaseTransform().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
data
, or try the search function
.
Example #1
Source File: demo.py From HSD with MIT License | 4 votes |
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)
Example #2
Source File: eval.py From HSD with MIT License | 4 votes |
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)
Example #3
Source File: demo.py From SSD_Pytorch with MIT License | 4 votes |
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)
Example #4
Source File: eval.py From SSD_Pytorch with MIT License | 4 votes |
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)