Exemplo n.º 1
0
    def __init__(self, ):
        data_path = 'data/LOV'
        model_checkpoint = 'data/demo_models/vgg16_fcn_color_single_frame_2d_pose_add_lov_iter_160000.ckpt'
        cfg_from_file('experiments/cfgs/lov_color_2d.yml')
        cfg.GPU_ID = 1
        device_name = '/gpu:{:d}'.format(1)

        cfg.TRAIN.NUM_STEPS = 1
        cfg.TRAIN.GRID_SIZE = cfg.TEST.GRID_SIZE
        if cfg.NETWORK == 'FCN8VGG':
            raise ValueError(cfg.NETWOK)
            #path = osp.abspath(osp.join(cfg.ROOT_DIR, args.pretrained_model))
            #cfg.TRAIN.MODEL_PATH = path
        cfg.TRAIN.TRAINABLE = False
        cfg.TRAIN.VOTING_THRESHOLD = cfg.TEST.VOTING_THRESHOLD

        cfg.RIG = 'data/LOV/camera.json'
        cfg.CAD = 'data/LOV/models.txt'
        cfg.POSE = 'data/LOV/poses.txt'
        cfg.BACKGROUND = 'data/cache/backgrounds.pkl'
        cfg.IS_TRAIN = False

        from networks.factory import get_network
        self.network = get_network('vgg16_convs')
        saver = tf.train.Saver()
        gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.6)
        self.sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True,
                                                     gpu_options=gpu_options))
        saver.restore(self.sess, model_checkpoint)
        self.points_all = getYCBPoints(data_path)[1]
        self.extents = getYCBExtents(data_path)
        self.voxelizer = Voxelizer(cfg.TEST.GRID_SIZE, ycb_num_classes)
        self.voxelizer.setup(-3, -3, -3, 3, 3, 4)
Exemplo n.º 2
0
def setup():
    cfg_from_file("experiments/cfgs/lov_color_box.yml")
    cfg.GPU_ID = 0
    device_name = '/gpu:{:d}'.format(0)
    print(device_name)

    cfg.TRAIN.NUM_STEPS = 1
    cfg.TRAIN.GRID_SIZE = cfg.TEST.GRID_SIZE
    cfg.TRAIN.TRAINABLE = False

    cfg.RIG = "data/LOV/camera.json"
    cfg.CAD = "data/LOV/models.txt"
    cfg.POSE = "data/LOV/poses.txt"
    cfg.BACKGROUND = "data/cache/backgrounds.pkl"
    cfg.IS_TRAIN = False
    print('Using config:')
    pprint.pprint(cfg)
    set_seed()

    imdb = get_imdb("lov_single_000_box_train")
    output_dir = get_output_dir(imdb, None)

    # This can not be imported at the top like it should be, but has to be imported after the default config has been merged with the file config
    from networks.factory import get_network
    network = get_network("vgg16_convs")

    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.8)
    sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=False,
                                            gpu_options=gpu_options))

    with open("generate_dataset/config.yaml", "r") as config:
        config_dict = yaml.load(config)

    model = config_dict["model"]
    print('Loading model weights from {:s}').format(model)
    saver = tf.train.Saver()
    saver.restore(sess, model)

    return config_dict, sess, network, imdb, output_dir
Exemplo n.º 3
0
    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)

    args = parser.parse_args()
    return args


if __name__ == '__main__':
    args = parse_args()

    print('Called with args:')
    print(args)

    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)

    print('Using config:')
    pprint.pprint(cfg)

    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)

    # prepare dataset
    cfg.MODE = 'TRAIN'
    dataset = get_dataset(args.dataset_name)
    worker_init_fn = dataset.worker_init_fn if hasattr(dataset, 'worker_init_fn') else None
    num_workers = 4
    dataloader = torch.utils.data.DataLoader(dataset, batch_size=cfg.TRAIN.IMS_PER_BATCH, shuffle=True, 
        num_workers=num_workers, worker_init_fn=worker_init_fn)
Exemplo n.º 4
0
def init_particle(images, meta_data=None, bag_file=None):
    """ Provides a trace particle initialization from image data.

    Parameters
    ----------
    images : [(str, str)] or [(np.ndarray, np.ndarray)]
        Set of image paths or images to run through the network.
    meta_deta : dict(str => any)
        Optional. Must contain camera intrinsics in 'intrinsic_matrix',
        and depth camera factor in 'factor_depth'.
    bag_file : str
        Optional. Specifies location of bag with appropriate camera metadata
        (typically the recorded bag from which the images were taken).

    Returns
    -------
    [[(str, np.ndarray)]]
        List of detections from each scene, where detections are a pair
        of the object name to its detected 6D pose.
    """

    # Check if we've got image paths instead of images.
    if isinstance(images[0][0], str):
        loaded_images = []
        for (rgb_filename, depth_filename) in images:
            rgb_im = cv2.imread(rgb_filename, cv2.IMREAD_UNCHANGED)
            depth_im = cv2.imread(depth_filename, cv2.IMREAD_UNCHANGED)
            loaded_images.append((rgb_im, depth_im))
        images = loaded_images

    root = os.path.join(osp.dirname(__file__), "..")
    cfg_file = os.path.join(root, "experiments/cfgs/obsd.yml")
    if bag_file is None:
        bag_file = "/om2/user/agarret7/projects/online-bayesian-scene-derendering/data/mvd0/record.bag"
    imdb_name = "lov_keyframe"
    gpu_id = 0
    # rig_name        = os.path.join(root, "data/LOV/camera.json")
    cad_name = os.path.join(root, "data/LOV/models.txt")
    pose_name = os.path.join(root, "data/LOV/poses.txt")
    background_name = os.path.join(root, "data/cache/backgrounds.pkl")
    network_name = "vgg16_convs"
    model = os.path.join(
        root,
        "data/demo_models/vgg16_fcn_color_single_frame_2d_pose_add_lov_iter_160000.ckpt"
    )

    # Create a pipeline
    pipeline = rs.pipeline()

    #Create a config and configure the pipeline to stream
    #  different resolutions of color and depth streams
    config = rs.config()
    rs.config.enable_device_from_file(config, bag_file)

    ctx = rs.context()
    d = ctx.load_device(bag_file)
    depth_sensor, color_sensor = d.query_sensors()
    color_prof, depth_prof = color_sensor.get_stream_profiles(
    )[0], depth_sensor.get_stream_profiles()[0]

    config.enable_stream(rs.stream.color, color_prof.format(),
                         color_prof.fps())
    config.enable_stream(rs.stream.depth, depth_prof.format(),
                         depth_prof.fps())

    # Start streaming
    profile = pipeline.start(config)

    rgb_profile = profile.get_stream(rs.stream.color)
    intr = rgb_profile.as_video_stream_profile().get_intrinsics()

    depth_sensor = profile.get_device().first_depth_sensor()
    factor_depth = int(1. / depth_sensor.get_depth_scale())

    pipeline.stop()

    if cfg_file is not None:
        cfg_from_file(cfg_file)

    # print('Using config:')
    # pprint.pprint(cfg)

    imdb = get_imdb(imdb_name)

    # construct meta data
    if meta_data is None:
        # fx = 1066.778
        # fy = 1067.487
        # px = 312.9869
        # py = 241.3109
        # factor_depth = 10000.0

        fx = intr.fx
        fy = intr.fy
        px = intr.ppx
        py = intr.ppy

        K = np.array([[fx, 0, px], [0, fy, py], [0, 0, 1]])

        meta_data = dict({'intrinsic_matrix': K, 'factor_depth': factor_depth})

    cfg.GPU_ID = gpu_id
    device_name = '/gpu:{:d}'.format(gpu_id)
    # print(device_name)

    cfg.TRAIN.NUM_STEPS = 1
    cfg.TRAIN.GRID_SIZE = cfg.TEST.GRID_SIZE
    cfg.TRAIN.TRAINABLE = False

    # cfg.RIG = rig_name
    cfg.CAD = cad_name
    cfg.POSE = pose_name
    cfg.BACKGROUND = background_name
    cfg.IS_TRAIN = False

    from networks.factory import get_network
    network = get_network(network_name)
    print('Use network `{:s}` in training'.format(network_name))

    # start a session
    saver = tf.train.Saver()
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.6)
    sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True,
                                            gpu_options=gpu_options))
    saver.restore(sess, model)
    print(('Loading model weights from {:s}').format(model))

    return run_network(sess, network, imdb, images, meta_data)
        for split in ['train', 'keyframe']:
            name = 'lov_{}'.format(split)
            print name
            self.__sets[name] = (lambda split=split: datasets.lov(split))

    def get_imdb(self, name):
        """Get an imdb (image database) by name."""
        if not self.__sets.has_key(name):
            raise KeyError('Unknown dataset: {}'.format(name))
        return self.__sets[name]()


# **** get configs
args = input_args()

cfg_from_file(args.config_file)
cfg.IS_TRAIN = args.is_train

print cfg
print '** current run mode'
print 'cfg.TRAIN.SINGLE_FRAME = ' + str(cfg.TRAIN.SINGLE_FRAME)
print 'cfg.TRAIN.VERTEX_REG_2D = ' + str(cfg.TRAIN.VERTEX_REG_2D)
print 'cfg.TRAIN.VERTEX_REG_3D = ' + str(cfg.TRAIN.VERTEX_REG_3D)
print 'cfg.TRAIN.POSE_REG = ' + str(cfg.TRAIN.POSE_REG)
print 'cfg.TRAIN.ADAPT = ' + str(cfg.TRAIN.ADAPT)
print 'cfg.INPUT = ' + str(cfg.INPUT)
print 'cfg.TEST.SINGLE_FRAME = ' + str(cfg.TEST.SINGLE_FRAME)
print 'cfg.TEST.SEGMENTATION = ' + str(cfg.TEST.SEGMENTATION)

assert cfg.TRAIN.SINGLE_FRAME == True
assert cfg.TRAIN.VERTEX_REG_2D == True
Exemplo n.º 6
0
    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)

    args = parser.parse_args()
    return args

if __name__ == '__main__':
    args = parse_args()

    print('Called with args:')
    print(args)

    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)

    print('Using config:')
    pprint.pprint(cfg)

    while not os.path.exists(args.model) and args.wait:
        print('Waiting for {} to exist...'.format(args.model))
        time.sleep(10)

    weights_filename = os.path.splitext(os.path.basename(args.model))[0]

    imdb = get_imdb(args.imdb_name)
    imdb.competition_mode(args.comp_mode)

    cfg.GPU_ID = args.gpu_id
    device_name = '/gpu:{:d}'.format(args.gpu_id)
Exemplo n.º 7
0
                key = cv2.waitKey(0)

                if key == 27:
                    exit(0)
        except:
            print(f'pred {quaternion_delta} {translation}')
            print(
                f'true {poses_tgt[0, 2:6]} {poses_tgt[0, 6:] - poses_src[0, 6:]}'
            )
            error_rot = np.nan
            error_trans = np.nan


if __name__ == '__main__':

    cfg_from_file('experiments/cfgs/swisscube.yml')

    cfg.renderer = Renderer(synthetic=True)
    network_path = 'data/checkpoints/swisscube/latest.pth'
    network = load_network(network_path)

    fine_tune = [param for name, param in network.module.named_parameters()]
    optimizer = torch.optim.SGD(fine_tune,
                                cfg.TRAIN.LEARNING_RATE,
                                momentum=cfg.TRAIN.MOMENTUM)

    pose_losses, flow_losses = [], []
    epochs = 25
    start_epoch = 2
    cfg.epochs = epochs
    for epoch in range(start_epoch, epochs):