Exemple #1
0
num_classes = valid_set.num_classes

# build the Faster-RCNN network
(model, proposalLayer) = faster_rcnn.build_model(valid_set,
                                                 frcn_rois_per_img,
                                                 inference=True)

# load parameters and initialize model
model.load_params(args.model_file, load_states=False)
model.initialize(dataset=valid_set)

# normalize the model by the bbtarget mean and std if needed
# if a full training run was completed using train.py, then normalization
# was already performed prior to saving the model.
if args.normalize:
    model = util.scale_bbreg_weights(model, [0.0, 0.0, 0.0, 0.0],
                                     [0.1, 0.1, 0.2, 0.2], num_classes)

# run inference

# detection parameters
num_images = valid_set.ndata
max_per_image = 100  # maximum detections per image
thresh = 0.001  # minimum threshold on score
nms_thresh = 0.3  # threshold used for non-maximum supression

# all detections are collected into:
#    all_boxes[cls][image] = N x 5 array of detections in
#    (x1, y1, x2, y2, score)
all_boxes = [[[] for _ in range(num_classes)] for _ in range(num_images)]
all_gt_boxes = [[] for _ in range(num_images)]
Exemple #2
0
                        frcn_tree_cost,
                        ],
                 weights=[1, 1, 1])

# setup optimizer
schedule_w = StepSchedule(step_config=[10], change=[0.001 / 10])
schedule_b = StepSchedule(step_config=[10], change=[0.002 / 10])

opt_w = GradientDescentMomentum(0.001, 0.9, wdecay=0.0005, schedule=schedule_w)
opt_b = GradientDescentMomentum(0.002, 0.9, wdecay=0.0005, schedule=schedule_b)
opt_skip = GradientDescentMomentum(0.0, 0.0)

optimizer = MultiOptimizer({'default': opt_w, 'Bias': opt_b,
                            'skip': opt_skip, 'skip_bias': opt_skip})

# 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:
    util.load_vgg_all_weights(model, cache_dir)

callbacks = Callbacks(model, eval_set=train_set, **args.callback_args)

model.fit(train_set, optimizer=optimizer, cost=cost, num_epochs=args.epochs, callbacks=callbacks)

# Scale the bbox regression branch linear layer weights before saving the model
model = util.scale_bbreg_weights(model, [0.0, 0.0, 0.0, 0.0],
                                 [0.1, 0.1, 0.2, 0.2], train_set.num_classes)

if args.save_path is not None:
    save_obj(model.serialize(keep_states=True), args.save_path)
Exemple #3
0
# 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())],
                 weights=[1, 1])

callbacks = Callbacks(model, eval_set=test_set, **args.callback_args)

model.fit(train_set, optimizer=optimizer,
          num_epochs=num_epochs, cost=cost, callbacks=callbacks)

# Fast R-CNN model requires scale the bbox regression branch linear layer weights
# before saving the model
model = scale_bbreg_weights(
    model, train_set.bbtarget_means, train_set.bbtarget_stds)

save_obj(model.serialize(keep_states=True), args.save_path)

neon_logger.display('running eval...')

metric_train = model.eval(train_set, metric=ObjectDetection())
neon_logger.display(
    'Train: label accuracy - {}%, object detection logloss - {}'.format(metric_train[0] * 100,
                                                                        metric_train[1]))

metric_test = model.eval(test_set, metric=ObjectDetection())
neon_logger.display(
    'Test: label accuracy - {}%, object detection logloss - {}'.format(metric_test[0] * 100,
                                                                       metric_test[1]))