def single_evaluate(net, probe_path, gallery_path, adv_index, target_index,
                    adv_id, target_id, graph, res):

    #load the bobo dataset. 1)adv images; 2) target images; 3)other pid images
    #and their infos (pid, cid)
    img_names = sorted(os.listdir(probe_path))
    imgs, infos = load(probe_path, img_names)

    # divide the adv images into 2 part. 1) probe  2)gallery_add
    rand_index = np.arange(len(adv_index))
    #np.random.shuffle(rand_index)
    adv_index = adv_index[rand_index]

    adv_probe_imgs = imgs[adv_index[0:1]]
    adv_probe_infos = [infos[i] for i in adv_index[0:1]]

    # construct the gallery_add imgs and the infos
    num_per_pc = 6
    gal_add_pid = sorted(list(set(range(1502, 1513)) - {adv_id, target_id}))
    otherpid_index = np.random.randint(0, 24, size=3 * (11-2) * num_per_pc) + \
                     np.array([np.arange(3)+(i-1502)*3 for i in gal_add_pid]).flatten().repeat(num_per_pc)*24

    gal_add_index = np.concatenate(
        (adv_index[1:], target_index, otherpid_index))

    gallery_imgs_add = imgs[gal_add_index]
    gallery_infos_add = [infos[i] for i in gal_add_index]

    #a. untarget test
    # the probe adv serving as probe
    # gallery is obtained by concat target image, other pid, gallery_add adv
    # do the test:
    result_untarget = eval_without_noise(net, adv_probe_imgs, adv_probe_infos,
                                         gallery_imgs_add, gallery_infos_add,
                                         graph, res)

    #b. target test
    # change the adv infos to (target_id, cid)
    # gallery is obtained by concat target image, other pid, gallery_add adv
    # do the test
    # noted that if the probe comes from the camera of target, if would cause error when we change the id
    # because there is no correct img in gallery matched to the probe

    for i in adv_index:
        if infos[i][1] == infos[adv_index[0]][
                1]:  # means we set the first img of adv_index as the probe
            infos[i] = (target_id, infos[i][1])

    adv_probe_infos = [infos[i] for i in adv_index[0:1]]
    gal_add_index = np.concatenate(
        (adv_index[1:], target_index, otherpid_index))
    gallery_infos_add = [infos[i] for i in gal_add_index]

    result_target = eval_without_noise(net, adv_probe_imgs, adv_probe_infos,
                                       gallery_imgs_add, gallery_infos_add,
                                       graph, res)

    res.put((result_untarget, result_target))
    return [result_untarget, result_target]
Esempio n. 2
0
def bobo_evaluate(net, probe_path, gallery_path):
    img_names = sorted(os.listdir(probe_path))
    imgs, infos = load(probe_path, img_names)
    index = np.arange(len(imgs))

    probe_index = index[::4]  #only the forward
    gal_add_index = index[2::4]

    probe_imgs = imgs[probe_index]
    probe_infos = [infos[i] for i in probe_index]

    gallery_imgs_add = imgs[gal_add_index]
    gallery_infos_add = [infos[i] for i in gal_add_index]

    eval_without_noise(net, probe_imgs, probe_infos, gallery_imgs_add,
                       gallery_infos_add)
Esempio n. 3
0
def single_evaluate(net, probe_path, gallery_path, adv_index, adv_id, target_id, num_target):

    #load the bobo dataset. 1)adv images; 2) target images; 3)other pid images
    #and their infos (pid, cid)
    img_names = sorted(os.listdir(probe_path))
    imgs, infos = load(probe_path, img_names)

    # divide the adv images into 2 part. 1) probe  2)gallery_add
    adv_probe_imgs = imgs[adv_index[0:1]]
    adv_probe_infos = [infos[i] for i in adv_index[0:1]]

    # construct the gallery_add imgs and the infos
    num_per_pc = 6
    gal_add_pid = sorted(list(set(range(1502,1513))-{adv_id}))
    otherpid_index = np.random.randint(0, 24, size=3 * (11-1) * num_per_pc) + \
                     np.array([np.arange(3)+(i-1502)*3 for i in gal_add_pid]).flatten().repeat(num_per_pc)*24

    gal_add_index = np.concatenate(
        (adv_index[1:], otherpid_index)
    )

    gallery_imgs_add = imgs[gal_add_index]
    gallery_infos_add = [infos[i] for i in gal_add_index]

    #a. untarget test
    result_untarget = eval_without_noise(net, adv_probe_imgs, adv_probe_infos, gallery_path, gallery_imgs_add, gallery_infos_add,
                                         target_id, num_target)

    #b. target test
    for i in adv_index:
        if infos[i][1] == infos[adv_index[0]][1]:  #means we set the first img of adv_index as the probe
            infos[i] = (target_id, infos[i][1])

    adv_probe_infos = [infos[i] for i in adv_index[0:1]]
    gal_add_index = np.concatenate(
        (adv_index[1:], otherpid_index)
    )
    gallery_infos_add = [infos[i] for i in gal_add_index]
    result_target = eval_without_noise(net, adv_probe_imgs, adv_probe_infos, gallery_path, gallery_imgs_add, gallery_infos_add,
                                       target_id, num_target)

    return [result_untarget, result_target]