示例#1
0
    def __init__(self, config, tracking_camera, scene_type="building", gpu_count=0):
        BaseEnv.__init__(self, config, scene_type, tracking_camera)

        self.camera_x = 0
        self.walk_target_x = 1e3  # kilometer away
        self.walk_target_y = 0
        self.k = 5
        self.robot_tracking_id = -1

        self.scale_up  = 4
        self.dataset  = ViewDataSet3D(
            transform = np.array,
            mist_transform = np.array,
            seqlen = 2,
            off_3d = False,
            train = False,
            overwrite_fofn=True, env = self)
        self.ground_ids = None
        if self.gui:
            assert(self.tracking_camera is not None)
        self.gpu_count = gpu_count
        self.nframe = 0
        self.eps_reward = 0

        self.reward = 0
        self.eps_count = 0

        self._robot_introduced = False
        self._scene_introduced = False
示例#2
0
    def __init__(self, config, scene_type="building", gpu_count=0):
        BaseEnv.__init__(self, config, scene_type)
        ## The following properties are already instantiated inside xxx_env.py:
        #   @self.timestep
        #   @self.frame_skip

        self.camera_x = 0
        self.walk_target_x = 1e3  # kilometer away
        self.walk_target_y = 0
        self.temp_target_x = 0  # added randomness
        self.temp_target_y = 0  # added randomness

        self.k = 5
        self.robot_tracking_id = -1

        self.scale_up = 4
        self.dataset = ViewDataSet3D(transform=np.array,
                                     mist_transform=np.array,
                                     seqlen=2,
                                     off_3d=False,
                                     train=False,
                                     overwrite_fofn=True,
                                     env=self)
        self.ground_ids = None
        if self.gui:
            assert (self.tracking_camera is not None)
        self.gpu_count = gpu_count
        self.nframe = 0
        self.eps_reward = 0

        self.reward = 0
        self.eps_count = 0

        self._robot_introduced = False
        self._scene_introduced = False
示例#3
0
    def setup_camera_pc(self):
        ## Camera specific
        assert(self._require_camera_input)
        if self.scene_type == "building":
            self.dataset = ViewDataSet3D(
                transform = np.array,
                mist_transform = np.array,
                seqlen = 2,
                off_3d = False,
                train = False,
                overwrite_fofn=True, env = self, only_load = self.config["model_id"])

        scene_dict = dict(zip(self.dataset.scenes, range(len(self.dataset.scenes))))
        ## Todo: (hzyjerry) more error handling
        if not self.model_id in scene_dict.keys():
             raise error.Error("Dataset not found: model {} cannot be loaded".format(self.model_id))
        else:
            scene_id = scene_dict[self.model_id]
        uuids, rts = self.dataset.get_scene_info(scene_id)

        targets, sources, source_depths, poses = [], [], [], []
        source_semantics = []

        if not self.multiprocessing or self.config["envname"] == "TestEnv":
            all_data = self.dataset.get_multi_index([v for k, v in uuids])
            for i, data in enumerate(all_data):
                target, target_depth = data[1], data[3]
                if not self._require_rgb:
                    continue
                ww = target.shape[0] // 8 + 2
                target[:ww, :, :] = target[ww, :, :]
                target[-ww:, :, :] = target[-ww, :, :]

                if self.scale_up !=1:
                    target = cv2.resize(
                        target,None,
                        fx=1.0/self.scale_up,
                        fy=1.0/self.scale_up,
                        interpolation = cv2.INTER_CUBIC)
                    target_depth =  cv2.resize(
                        target_depth, None,
                        fx=1.0/self.scale_up,
                        fy=1.0/self.scale_up,
                        interpolation = cv2.INTER_CUBIC)
                pose = data[-1][0].numpy()
                targets.append(target)
                poses.append(pose)
                sources.append(target)
                source_depths.append(target_depth)
        else:
            all_data = self.dataset.get_multi_index([v for k, v in uuids])
            for i, data in enumerate(all_data):
                target, target_depth = data[1], data[3]
                if not self._require_rgb:
                    continue
                ww = target.shape[0] // 8 + 2
                target[:ww, :, :] = target[ww, :, :]
                target[-ww:, :, :] = target[-ww, :, :]

                if self.scale_up !=1:

                    target = cv2.resize(
                        target,None,
                        fx=1.0/self.scale_up,
                        fy=1.0/self.scale_up,
                        interpolation = cv2.INTER_CUBIC)
                    target_depth =  cv2.resize(
                        target_depth, None,
                        fx=1.0/self.scale_up,
                        fy=1.0/self.scale_up,
                        interpolation = cv2.INTER_CUBIC)
                pose = data[-1][0].numpy()
                targets.append(target)
                poses.append(pose)
                sources.append(target)
                source_depths.append(target_depth) 
        
        self.r_camera_rgb = PCRenderer(self.port_rgb, sources, source_depths, target, rts, 
                                       scale_up=self.scale_up, 
                                       semantics=source_semantics,
                                       gui=self.gui, 
                                       use_filler=self._use_filler,  
                                       gpu_idx=self.gpu_idx,
                                       windowsz=self.windowsz, 
                                       env = self)
示例#4
0
        show, _ =  render(sources, source_depths, poses[0], poses, target_depth)
        print(show.shape)

        Image.fromarray(show).save('%s/show%d.png' % (outf, idx))
        Image.fromarray(target).save('%s/target%d.png' % (outf, idx))

        np.savez(file = filename, source = show, depth = target_depth, target = target)

    return


parser = argparse.ArgumentParser()
parser.add_argument('--debug'  , action='store_true', help='debug mode')
parser.add_argument('--dataroot'  , required = True, help='dataset path')
parser.add_argument('--outf'  , type = str, default = '', help='path of output folder')
opt = parser.parse_args()


d = ViewDataSet3D(root=opt.dataroot, transform = np.array, mist_transform = np.array, seqlen = 5, off_3d = False, train = False)
print(len(d))

p = Pool(10)
p.map(generate_data, [(idx, d, opt.outf) for idx in range(len(d))])

#for i in range(len(d)):
#    filename = "%s/data_%d.npz" % (opt.outf, i)
#    print(filename)
#    if not os.path.isfile(filename):
#        generate_data([i, d, opt.outf])

示例#5
0
if __name__ == '__main__':

    parser = argparse.ArgumentParser()
    parser.add_argument('--debug', action='store_true', help='debug mode')
    parser.add_argument('--datapath', required=True, help='dataset path')
    parser.add_argument('--model_id', type=str, default=0, help='models id')
    parser.add_argument('--models',
                        type=str,
                        default='',
                        help='path of models')

    opt = parser.parse_args()
    d = ViewDataSet3D(root=opt.datapath,
                      transform=np.array,
                      mist_transform=np.array,
                      seqlen=2,
                      off_3d=False,
                      train=True)

    scene_dict = dict(zip(d.scenes, range(len(d.scenes))))
    if not opt.model_id in scene_dict.keys():
        print("models not found")
    else:
        scene_id = scene_dict[opt.model_id]

    uuids, rts = d.get_scene_info(scene_id)
    print(uuids, rts)

    targets = []
    sources = []
    source_depths = []