be.enable_winograd = 4 if be.gpu_memory_size < 11 * 1024 * 1024 * 1024: exit("ERROR: This model requires at least 11GB GPU memory to be run.") # setup training dataset train_set = PASCALVOCTrain('trainval', '2007', path=args.data_dir, n_mb=n_mb, img_per_batch=img_per_batch, rois_per_img=rois_per_img, rois_random_sample=True, add_flipped=False, subset_pct=args.subset_pct) test_set = PASCALVOCTrain('test', '2007', path=args.data_dir, n_mb=n_mb, img_per_batch=img_per_batch, rois_per_img=rois_per_img, rois_random_sample=True, add_flipped=False) # setup model model = create_frcn_model(frcn_fine_tune) # setup optimizer opt_w = GradientDescentMomentum( 0.001 * learning_rate_scale, 0.9, wdecay=0.0005) opt_b = GradientDescentMomentum(0.002 * learning_rate_scale, 0.9) optimizer = MultiOptimizer({'default': opt_w, 'Bias': opt_b}) # if training a new model, seed the image model conv layers with pre-trained weights # otherwise, just load the model file if args.model_file is None: load_vgg_weights(model, args.data_dir) cost = Multicost(costs=[GeneralizedCostMask(costfunc=CrossEntropyMulti()), GeneralizedCostMask(costfunc=SmoothL1Loss())],
# hyperparameters args.batch_size = 1 n_mb = 40 img_per_batch = args.batch_size rois_per_img = 5403 # setup dataset image_set = 'test' image_year = '2007' valid_set = PASCALVOCInference(image_set, image_year, path=args.data_dir, n_mb=n_mb, rois_per_img=rois_per_img, shuffle=False) # setup model model = create_frcn_model() model.load_params(args.model_file) model.initialize(dataset=valid_set) CONF_THRESH = 0.8 NMS_THRESH = 0.3 # iterate through minibatches of the dataset for mb_idx, (x, db) in enumerate(valid_set): im = np.array(Image.open(db['img_file'])) # This is RGB order neon_logger.display(db['img_id']) outputs = model.fprop(x, inference=True) scores, boxes = valid_set.post_processing(outputs, db)
args.batch_size = 1 n_mb = None img_per_batch = args.batch_size rois_per_img = 5403 # setup dataset image_set = 'test' year = '2007' valid_set = PASCALVOCInference(image_set, year, path=args.data_dir, n_mb=n_mb, rois_per_img=rois_per_img) # setup models model = create_frcn_model() model.load_params(args.model_file) model.initialize(dataset=valid_set) # set up the detection params num_images = valid_set.num_images if n_mb is None else n_mb num_classes = valid_set.num_classes image_index = valid_set.image_index # heuristic: keep an average of 40 detections per class per images prior # to NMS max_per_set = 40 * num_images # heuristic: keep at most 100 detection per class per image prior to NMS max_per_image = 100 # detection thresold for each class (this is adaptively set based on the # max_per_set constraint) thresh = -np.inf * np.ones(num_classes)