Esempio n. 1
0
 # Extracting one image per class
 indexes, labels = one_image_per_class(test_labels, len(class_names))
 train_images = np.array([train_images[idx] for idx in indexes])
 train_labels = np.array(labels)
 # Extraction of a random image
 image_index = random.randint(0, len(train_images) - 1)
 #image_index = 1614
 train_image = train_images[image_index, :, :, :]
 train_label = int(train_labels[image_index])
 train_image_4dim = np.reshape(train_image, (batch_size, 32, 32, 3))
 # Convolutional features extraction
 net_features = net.extract_features(train_image_4dim)
 net_distribution = np.reshape(net(train_image_4dim).numpy(), (10, ))
 # Environment initialization
 environment = DyadicConvnetGymEnv(features=net_features,
                                   image_class=train_label,
                                   distribution=net_distribution,
                                   max_steps=steps_per_episode)
 num_actions = len(environment.actions)
 environment = Environment.create(
     environment=environment,
     states=dict(
         # 64 features + 3 positional coding
         features=dict(type=float, shape=(67, )), ),
     actions=dict(movement=dict(type=int, num_values=num_actions),
                  classification=dict(type=int,
                                      num_values=len(class_names))),
     max_episode_timesteps=steps_per_episode)
 # Agent initialization
 for i in range(1, int(last_episode / 1000) + 1):
     old_episodes = i * 1000
     print('Loading checkpoint. Last episode: %d' % old_episodes)
Esempio n. 2
0
             net.extract_features(image,
                                  active_layers=layers,
                                  last_layer=4))
         idx += 1
     test_images = copy.deepcopy(tmp)
     del train_images, train_labels
     del tmp
 #########################################################################
 # Environment initialization
 environment = DyadicConvnetGymEnv(
     dataset=test_images,
     labels=test_labels,
     images=RGB_images,
     layers=layers,
     max_steps=steps_per_episode,
     visualize=visualize,
     training=False,
     class_penalty=class_penalty,
     correct_class=correct_class,
     illegal_mov=illegal_mov,
     same_position=same_position,
     non_classified=non_classified,
     step_reward_multiplier=step_reward_multiplier)
 num_actions = len(environment.actions)
 environment = Environment.create(
     environment=environment,
     states=dict(features=dict(type=float, shape=(147, )), ),
     actions=dict(type=int, num_values=num_actions + num_classes),
     max_episode_timesteps=steps_per_episode)
 dirs = ['models/RL/20210428-125328']
 for directory in dirs:
     check_dir = directory + '/checkpoints/'
Esempio n. 3
0
 old_epochs = 15
 #threads = []
 for size in num_agents:
     environments = []
     jedi_council = []
     consensus = Consensus()
     print('Testing {s} agents'.format(s=size))
     for i in range(size):
         environment = DyadicConvnetGymEnv(dataset=test_images,
                                           labels=test_labels,
                                           images=RGB_images,
                                           layers=layers,
                                           num_classes=10,
                                           num_features=num_features,
                                           max_steps=steps_per_episode,
                                           visualize=visualize,
                                           training=False,
                                           class_penalty=class_penalty,
                                           correct_class=correct_class,
                                           illegal_mov=illegal_mov,
                                           same_position=same_position,
                                           non_classified=non_classified,
                                           step_reward_multiplier=step_reward_multiplier
                                           )
         num_actions = len(environment.actions)
         environment = Environment.create(environment=environment,
                                          states=dict(
                                              features=dict(type=float, shape=(num_features,)),
                                          ),
                                          actions=dict(type=int, num_values=num_actions+num_classes),
                                          max_episode_timesteps=steps_per_episode
                                          )