Ejemplo n.º 1
0
    def infer(self, images: List[OrthographicImage], method: SelectionMethod,
              **params) -> List[Action]:
        if self.monte_carlo:  # Adapt monte carlo progress parameter s
            epoch_in_collection = Loader.get_episode_count(Config.collection)
            s_not_bounded = (epoch_in_collection - 3500) * 1 / (4500 - 3500)
            self.inference.current_s = max(min(s_not_bounded, 1.0), 0.0)

        self.check_for_model_reload()

        if len(images) == 3:
            images[2].mat = images[2].mat[:, :, ::-1]  # BGR to RGB

        action = self.inference.infer(images, method)
        self.indexer.to_action(action)

        print(action, method)

        estimated_reward_lower_than_threshold = action.estimated_reward < Config.bin_empty_at_max_probability
        bin_empty = estimated_reward_lower_than_threshold and Epoch.selection_method_should_be_high(
            method)

        if bin_empty:
            return [Action('bin_empty', safe=1)]

        self.converter.calculate_pose(action, images)
        return [action]
Ejemplo n.º 2
0
    def infer(self, images: List[OrthographicImage],
              method: SelectionMethod) -> Action:
        if self.monte_carlo:  # Adapt monte carlo progress parameter s
            epoch_in_database = Loader.get_episode_count(Config.grasp_database)
            s_not_bounded = (epoch_in_database - 3500) * 1 / (4500 - 3500)
            self.inference.current_s = max(min(s_not_bounded, 1.0), 0.0)

        current_model_st_mtime = Loader.get_model_path(
            self.model).stat().st_mtime
        if self.watch_for_model_modification and current_model_st_mtime > self.model_last_modified + 0.5:  # [s]
            logger.warning(f'Reload model {self.model}.')
            try:
                self.inference.model = Loader.get_model(
                    self.model, output_layer=self.output_layer)
                self.model_last_modified = Loader.get_model_path(
                    self.model).stat().st_mtime
            except OSError:
                logger.info('Could not load model, probabily file locked.')

        if len(images) == 3:
            images[2].mat = images[2].mat[:, :, ::-1]  # BGR to RGB

        action = self.inference.infer(images, method)
        self.indexer.to_action(action)

        estimated_reward_lower_than_threshold = action.estimated_reward < Config.bin_empty_at_max_probability
        bin_empty = estimated_reward_lower_than_threshold and Epoch.selection_method_should_be_high(
            method)

        if bin_empty:
            return Action('bin_empty', safe=1)

        self.converter.calculate_pose(action, images)
        return action
Ejemplo n.º 3
0
from collections import defaultdict

from data.loader import Loader

database_list = Loader.get_databases()
total_count = sum(Loader.get_episode_count(d) for d in database_list)
print(f'Total count {total_count}')

recordings_on_date = defaultdict(lambda: 0)
image_count = 0

for d in database_list:
    for _, e in Loader.yield_episodes(d):
        data = e['id'].split('-')
        date = f'{data[0]}-{data[1]}' # -{data[2]}'
        recordings_on_date[date] += 1
        image_count += len(e['actions'][0]['images'])

print(f'Total image count {image_count}')
for m in sorted(recordings_on_date):
    print(f'{m}: {recordings_on_date[m]}')