Example #1
0
def _deprecated_build_caffe2_model(runner, predict_net, init_net):
    if hasattr(runner, "_deprecated_build_caffe2_model"):
        return runner._deprecated_build_caffe2_model(predict_net, init_net)

    pb_model = ProtobufDetectionModel(predict_net, init_net)
    pb_model.validate_cfg = partial(update_cfg_from_pb_model, model=pb_model)
    return pb_model
Example #2
0
 def build_caffe2_model(self, predict_net, init_net):
     pb_model = ProtobufDetectionModel(predict_net, init_net)
     pb_model.validate_cfg = partial(update_cfg_from_pb_model,
                                     model=pb_model)
     return pb_model
Example #3
0
    img, img_tensor = load_img(IMAGE_LOCATION, transform_gen)

    device_opts = core.DeviceOption(caffe2_pb2.CPU)

    # Read the contents of the input protobufs into local variables
    init_net = caffe2_pb2.NetDef()
    with open(INIT_NET, 'rb') as f:
        init_net.ParseFromString(f.read())
        init_net.device_option.CopyFrom(device_opts)

    predict_net = caffe2_pb2.NetDef()
    with open(PREDICT_NET, "rb") as f:
        predict_net.ParseFromString(f.read())
        predict_net.device_option.CopyFrom(device_opts)

    c2det = ProtobufDetectionModel(predict_net, init_net)
    results = c2det([{
        "image": img_tensor,
        "height": img.shape[0],
        "width": img.shape[1]
    }])

    # Filtering by confidence

    # Indices -> N x 1 matrix
    indices = (results[0]['instances'].scores >
               args.confidence_threshold).nonzero()
    # Indices -> N dim vector
    indices = indices.squeeze()

    # Boxes