Пример #1
0
extractor = FeatureExtractor(cache_folder=model_cache_folder,
                             which_net='vgg16',
                             which_layer=VC['layer'],
                             which_snapshot=0)

res = np.zeros((featDim, 0))
loc_set = np.zeros((5, 0))

# for ii,iid in enumerate(range(img_num)):
for ii, iid in enumerate(subset_ls):
    img = cv2.imread(os.path.join(Dict['file_dir'], image_path[iid]))
    # img = cv2.resize(img, (scale_size, scale_size))
    img = myresize(img, scale_size, 'short')

    tmp = extractor.extract_feature_image(img)[0]
    assert (tmp.shape[2] == featDim)
    height, width = tmp.shape[0:2]
    tmp = tmp[offset:height - offset, offset:width - offset, :]
    ntmp = np.transpose(tmp, (2, 0, 1))
    gtmp = ntmp.reshape(ntmp.shape[0], -1)
    if gtmp.shape[1] >= samp_size:
        rand_idx = np.random.permutation(gtmp.shape[1])[:samp_size]
    else:
        rand_idx = np.random.permutation(gtmp.shape[1])[:samp_size -
                                                        gtmp.shape[1]]
        rand_idx = np.append(range(gtmp.shape[1]), rand_idx)

    res = np.column_stack((res, deepcopy(gtmp[:, rand_idx])))
    for rr in rand_idx:
        ihi, iwi = np.unravel_index(rr,