def create(self):
        project_dir = self._config['project_dir']
        ref_motion_db = self._config['character'].get('ref_motion_db')
        ref_motion_scale = self._config['character'].get('ref_motion_scale')
        ref_motion_file = []

        for i, mdb in enumerate(ref_motion_db):
            motions = []
            if mdb.get('cluster_info'):
                ''' Read reference motions based on the cluster labels '''
                assert mdb.get('data') is None, \
                    'This should not be specified when cluster_info is used'
                dir = mdb['cluster_info'].get('dir')
                label_file = mdb['cluster_info'].get('label_file')
                sample_id = mdb['cluster_info'].get('sample_id')
                labels = {}
                assert label_file
                if project_dir:
                    label_file = os.path.join(project_dir, label_file)
                with open(label_file, 'r') as file:
                    for line in file:
                        l = re.split('[\t|\n|,|:| ]+', line)
                        id, rank, score, filename = int(l[0]), int(
                            l[1]), float(l[2]), str(l[3])
                        if id not in labels.keys(): labels[id] = []
                        labels[id].append({
                            'rank': rank,
                            'socre': score,
                            'filename': filename
                        })
                num_cluster = len(labels.keys())
                for j in range(num_cluster):
                    if sample_id and j != sample_id:
                        continue
                    for label in labels[j]:
                        if project_dir:
                            file = os.path.join(project_dir, dir,
                                                label['filename'])
                        motions.append(file)
            else:
                ''' Read reference motions from the specified list of files and dirs '''
                ref_motion_data = mdb.get('data')
                motions = []
                if ref_motion_data.get('file'):
                    motions += ref_motion_data.get('file')
                if ref_motion_data.get('dir'):
                    for d in ref_motion_data.get('dir'):
                        if project_dir:
                            d = os.path.join(project_dir, d)
                        motions += utils.files_in_dir(d, ext=".bvh", sort=True)
                if project_dir:
                    for j in range(len(motions)):
                        motions[j] = os.path.join(project_dir, motions[j])
            ''' 
            If num_sample is specified, we use only num_sample motions 
            from the entire reference motions. 
            'random' chooses randomly, 'top' chooses the first num_sample
            '''
            num_sample = mdb.get('num_sample')
            if num_sample:
                sample_method = mdb.get('sample_method')
                if sample_method == 'random':
                    motions = random.choices(motions, k=num_sample)
                elif sample_method == 'top':
                    motions = motions[:num_sample]
                else:
                    raise NotImplementedError
            ref_motion_file.append(motions)
        ''' Load Reference Motion '''

        self._ref_motion_all = []
        self._ref_motion_file_names = []
        for i in range(self._num_agent):
            ref_motion_all, ref_motion_file_names = \
                load_motions(ref_motion_file[i],
                             self._base_motion[i].skel,
                             self._sim_agent[i]._char_info,
                             self._verbose)
            self._ref_motion_all.append(ref_motion_all)
            self._ref_motion_file_names.append(ref_motion_file_names)
        ''' Should call reset after all setups are done '''

        self.reset({'add_noise': False})

        self._initialized = True

        if self._verbose:
            print('----- Humanoid Imitation Environment Created -----')
            for i in range(self._num_agent):
                print('[Agent%d]: state(%d) and action(%d)' \
                      %(i, len(self.state(i)), self._action_space[i].dim))
            print('-------------------------------')
Beispiel #2
0
        help="Window stride for test and validation, in frames. This is also"
        " used as training window size",
    )

    args = parser.parse_args()

    train_files = read_content(
        os.path.join(args.split_dir, "training_fnames.txt"))
    validation_files = read_content(
        os.path.join(args.split_dir, "validation_fnames.txt"))
    test_files = read_content(os.path.join(args.split_dir, "test_fnames.txt"))

    train_ftuples = []
    test_ftuples = []
    validation_ftuples = []
    for filepath in fairmotion_utils.files_in_dir(args.input_dir, ext="pkl"):
        db_name = os.path.split(os.path.dirname(filepath))[1]
        db_name = ("_".join(db_name.split("_")[1:])
                   if "AMASS" in db_name else db_name.split("_")[0])
        f = os.path.basename(filepath)
        file_id = "{}/{}".format(db_name, f)

        if file_id in train_files:
            train_ftuples.append((filepath, file_id))
        elif file_id in validation_files:
            validation_ftuples.append((filepath, file_id))
        elif file_id in test_files:
            test_ftuples.append((filepath, file_id))
        else:
            pass
Beispiel #3
0
    parser.add_argument("--diff-threshold", type=float, default=5.0)
    parser.add_argument("--w-joint-pos", type=float, default=8.0)
    parser.add_argument("--w-joint-vel", type=float, default=2.0)
    parser.add_argument("--w-root-pos", type=float, default=0.5)
    parser.add_argument("--w-root-vel", type=float, default=1.5)
    parser.add_argument("--w-ee-pos", type=float, default=3.0)
    parser.add_argument("--w-ee-vel", type=float, default=1.0)
    parser.add_argument("--w-trajectory", type=float, default=1.0)
    parser.add_argument("--num-workers", type=int, default=10)

    args = parser.parse_args()

    # Load motions
    motion_files = args.motion_files if args.motion_files else []
    motion_files = (motion_files +
                    utils.files_in_dir(args.motion_folder, ext="bvh")
                    if args.motion_folder else motion_files)

    motions = bvh.load_parallel(
        motion_files,
        scale=args.scale,
        v_up_skel=utils.str_to_axis(args.v_up_skel),
        v_face_skel=utils.str_to_axis(args.v_face_skel),
        v_up_env=utils.str_to_axis(args.v_up_env),
    )

    skel = motions[0].skel
    motions_with_velocity = []
    for motion in motions:
        motion.set_skeleton(skel)
        motions_with_velocity.append(