Ejemplo n.º 1
0
    feature_extractor = Model(inputs=feature_extractor.input, outputs=x)

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

    agent = DQN_Agent(s_dim=1280,
                      a_dim=10,
                      epsilon_decay=0.99,
                      epsilon_min=0.02,
                      gamma=0.95,
                      replay_batchsize=256)

    if EVALUATION:
        agent.model = load_model(
            'evaluation_results/agent_DQN_train_amazon_imagenet.h5'
        )  # If in evaluation phase, replace this with the actual pretrained model
        agent.curr_exploration_rate = 0

    step_count = 0

    env = EnvironmentAPI(
        imagenet_train_path=images_dir,
        # cloud_agent=AmazonRekognition(),
        cloud_agent=FacePP(),
        dataset='imagenet',
        # cache_path='evaluation_results/image_reference_cache_amazon.defaultdict')
        cache_path='evaluation_results/image_reference_cache_face.defaultdict')
    # In order to reduce some billing recognition service requests, I cached the recognized result locally.
    # Can be replaced by loading an empty dict from a pickled file. Navigate to the code for more details.
Ejemplo n.º 2
0
    test_image_paths = imagenet_paths[:10]
    print(test_image_paths)
    flag = 1
    for index, path in enumerate(test_image_paths):
        image = Image.open(path).convert("RGB")
        image_data = preprocess_input(
            np.expand_dims(np.asarray(image.resize((224, 224)),
                                      dtype=np.float32),
                           axis=0))
        # features = feature_extractor.predict(image_data)[0][0][0]
        # state_actions, action_id = agent.choose_action(features)
        # action = [i for i in np.arange(5, 105, 10)][action_id]
        print(index)
        print(array)
        # time.sleep(1)
        if flag == 1:
            print("xxx")
            print(array)
            handle_process.join()
            agent.model = array[0]
            flag = 0

# if __name__ == "__main__":
#     main()
# array = multiprocessing.Manager().list()
# print('父进程pid: %d' % os.getpid())  # os.getpid获取当前进程的进程号
# handle_process = Process(target=process_handle, args=(array,))
# handle_process.start()
# # handle_process.join()
# array.extend([5, 6, 7])
# print(array)
Ejemplo n.º 3
0
    # test_image_paths = FLIR[:1000]
    cloud_agent = Baidu()

    train_log = defaultdict(list)
    ref_results = defaultdict(dict)
    compress_results = defaultdict(dict)

    choose_action_total_time = 0
    feedback_total_time = 0
    feature_total_time = 0
    recent_accuracy = 0
    recent_reward = 0

    start_time = time.time()
    if EVALUATION:
        agent.model = load_model('compute_time_results/baidu_imagenet.h5')
        # agent.model = load_model('compute_time_results/baidu_FLIR.h5')
        agent.curr_exploration_rate = 0
    load_model_time = time.time()
    # init feature
    compute_memory(103)
    image = Image.open(test_image_paths[0]).convert("RGB")
    image_data = preprocess_input(
        np.expand_dims(np.asarray(image.resize((224, 224)), dtype=np.float32),
                       axis=0))
    features = feature_extractor.predict(image_data)[0][0][0]
    compute_memory(104)
    # for
    for step_count, path in enumerate(test_image_paths):
        compute_memory(step_count)
        image = Image.open(path).convert("RGB")