Пример #1
0
    def load_results(training_dir):
        if not os.path.exists(training_dir):
            logger.error('Training directory %s not found', training_dir)
            return

        manifests = detect_training_manifests(training_dir)
        if not manifests:
            logger.error('No manifests found in training directory %s',
                         training_dir)
            return

        logger.debug('Uploading data from manifest %s', ', '.join(manifests))

        # Load up stats + video files
        stats_files = []
        videos = []
        env_infos = []

        for manifest in manifests:
            with open(manifest) as f:
                contents = json.load(f)
                # Make these paths absolute again
                stats_files.append(
                    os.path.join(training_dir, contents['stats']))
                videos += [(os.path.join(training_dir,
                                         v), os.path.join(training_dir, m))
                           for v, m in contents['videos']]
                env_infos.append(contents['env_info'])

        env_info = collapse_env_infos(env_infos, training_dir)

        # If only one stats file is present, there is no need to merge and all fields are included
        if len(stats_files) == 1:
            with open(stats_files[0]) as f:
                content = json.load(f)
                content.update({
                    'manifests': manifests,
                    'env_info': env_info,
                    'videos': videos
                })
                return content
        else:
            data_sources, initial_reset_timestamps, timestamps, episode_lengths, episode_rewards, \
                episode_types, initial_reset_timestamp = merge_stats_files(stats_files)

            return {
                'manifests': manifests,
                'env_info': env_info,
                'data_sources': data_sources,
                'timestamps': timestamps,
                'episode_lengths': episode_lengths,
                'episode_rewards': episode_rewards,
                'episode_types': episode_types,
                'initial_reset_timestamps': initial_reset_timestamps,
                'initial_reset_timestamp': initial_reset_timestamp,
                'videos': videos,
            }
Пример #2
0
    def load_results(training_dir):
        if not os.path.exists(training_dir):
            logger.error('Training directory %s not found', training_dir)
            return

        manifests = detect_training_manifests(training_dir)
        if not manifests:
            logger.error('No manifests found in training directory %s',
                         training_dir)
            return

        logger.debug('Uploading data from manifest %s', ', '.join(manifests))

        # Load up stats + video files
        stats_files = []
        videos = []
        env_infos = []

        for manifest in manifests:
            with open(manifest) as f:
                contents = json.load(f)
                # Make these paths absolute again
                stats_files.append(
                    os.path.join(training_dir, contents['stats']))
                videos += [(os.path.join(training_dir,
                                         v), os.path.join(training_dir, m))
                           for v, m in contents['videos']]
                env_infos.append(contents['env_info'])

        env_info = collapse_env_infos(env_infos, training_dir)

        # If several stats files are found, merge lists together and randomly pick single values
        all_contents = {}
        for file in stats_files:
            with open(file) as f:
                content = json.load(f)
                content.update({
                    'manifests': manifests,
                    'env_info': env_info,
                    'videos': videos
                })
                if not all_contents:
                    all_contents.update(content)
                else:
                    for key, value in content.items():
                        if isinstance(value, list):
                            all_contents[key].extend(value)
                        else:
                            all_contents[key] = value
        return all_contents