# isolated=True,
            # runs_path=Path(__file__).parent.parent / 'runs',
    ):

        # load hyper-parameter settings
        with (param_path / 'param2val.yaml').open('r') as f:
            param2val = yaml.load(f, Loader=yaml.FullLoader)
        params = Params.from_param2val(param2val)

        # re-generate data  the way it was during training
        world = World(params)
        dataset = DataSet(world.generate_sequences(
            leftout_colors=params.leftout_colors,
            leftout_shapes=params.leftout_shapes,
            leftout_variants=params.leftout_variants,
            leftout_positions=get_leftout_positions(params.leftout_half),
        ),
                          params,
                          name='re-generated')

        # multiple models may exist for the same hyper-parameter configuration
        for path_to_net in list(param_path.rglob('model.pt')):

            print(f'Loading net from {path_to_net}')

            # load net
            net = Network(params)
            state_dict = torch.load(path_to_net,
                                    map_location=torch.device('cpu'))
            net.load_state_dict(state_dict)
            net.requires_grad_(False)
Пример #2
0
            isolated=True,
            runs_path=Path(__file__).parent.parent / 'runs',
    ):

        # load hyper-parameter settings
        with (param_path / 'param2val.yaml').open('r') as f:
            param2val = yaml.load(f, Loader=yaml.FullLoader)
        params = Params.from_param2val(param2val)

        # use all locations, rotations, shapes, and colors - and filter later
        world = World(params)
        data = DataSet(world.generate_sequences(
            leftout_colors=('', ),
            leftout_shapes=('', ),
            leftout_variants='',
            leftout_positions=get_leftout_positions(''),
        ),
                       params,
                       name='re-generated')

        if RGB_ID is not None:
            name_of_color_channel = {0: 'red', 1: 'green', 2: 'blue'}[RGB_ID]
        else:
            name_of_color_channel = None

        # multiple models may exist for the same hyper-parameter configuration - use first only
        for path_to_net in list(param_path.rglob('model.pt'))[:1]:

            print(f'Loading net from {path_to_net}')

            # load net