Esempio n. 1
0
np.random.seed(2)

BATCH_SIZE = 128


def list_split(l, size):
    return [l[m:m + size] for m in range(0, len(l), size)]


if __name__ == '__main__':
    images_dir = '/home/hsli/gnode02/imagenet-data/train/'

    feature_extractor = load_model(
        'checkpoints/mobilenetv2_predictor_2W_acc_0.6955_epoch50.hdf5')

    rm = ResultManager('results')
    agent_acc_size_dict = []
    origin_acc_size_dict = []

    agent = Q_Agent(s_dim=2,
                    a_dim=10,
                    epsilon_decay=0.9993,
                    epsilon_min=0.2,
                    lr=0.1,
                    gamma=0.95)

    step_count = 0

    env = BatchImgEnvironment(imagenet_train_path=images_dir,
                              samples_per_class=3,
                              backbone_model=InceptionV3(),
        if len(self.agent_memory['reward']) < self.recent_zone:
            recent_reward = np.mean(self.agent_memory['reward'])
            recent_acc = np.mean(self.agent_memory['accuracy'])
        else:
            recent_reward = np.mean(
                self.agent_memory['reward'][-self.recent_zone:])
            recent_acc = np.mean(
                self.agent_memory['accuracy'][-self.recent_zone:])
        return recent_acc, recent_reward


#

if __name__ == '__main__':
    api = Baidu()
    rm = ResultManager('evaluation_results')

    running_agent = RunningAgent(
        dqn_path='evaluation_results/agent_DQN_train_baidu_imagenet.h5',
        banchmark_q=75,
        cloud_backend=api,
    )

    imagenet_paths = _gen_sample_set_imagenet(
        '/home/hsli/gnode02/imagenet-data/train/', 3)[-500:]

    test_image_paths = imagenet_paths

    for idx, path in enumerate(test_image_paths):
        error_code, log_dict = running_agent.agent_upload(path)
        if error_code > 0: continue
    def estimate(self):
        if len(self.agent_memory['reward']) < self.recent_zone:
            recent_reward = np.mean(self.agent_memory['reward'])
            recent_acc = np.mean(self.agent_memory['accuracy'])
        else:
            recent_reward = np.mean(self.agent_memory['reward'][-self.recent_zone:])
            recent_acc = np.mean(self.agent_memory['accuracy'][-self.recent_zone:])
        return recent_acc, recent_reward


#

if __name__ == '__main__':
    api = Baidu()
    # api = FacePP()
    rm = ResultManager('result')

    running_agent = RunningAgent(# dqn_path='evaluation_results/agent_DQN_train_baidu_DNIM.h5',
                                 # dqn_path='evaluation_results/agent_DQN_train_face_imagenet.h5',
                                 # dqn_path='evaluation_results/agent_DQN_train_face_DNIM.h5',
                                 # dqn_path='evaluation_results/agent_DQN_retrain_face_DNIM.h5',
                                 # dqn_path='evaluation_results/agent_DQN_retrain_baidu_DNIM.h5',
                                 dqn_path='result/agent_DQN_train_baidu_imagenet.h5',
                                 banchmark_q=75,
                                 cloud_backend=api,
                                 )

    # imagenet_paths = _gen_sample_set_imagenet('/home/hsli/gnode02/imagenet-data/train/', 2)
    # imagenet_paths = _gen_sample_set_imagenet('/home/imagenet-data/train/', 2)

    with open("result/imagenet_baidu_ref2000.pkl", "rb") as file: