from multiprocessing import Pool


def filter_img(img):
    gauss = np.zeros(img1.shape, img1.dtype)
    for j in range(3):
        gauss[:, :, j] = filters.gaussian_filter(img1[:, :, j], 10)
    return gauss

def bilateral_filter(old_path):
    print(old_path)
    out_path = old_path.replace("IJCAI_fgsm_output", "holdEdge_output")
    #out_path = old_path
    out_path_dir = os.path.split(out_path)[0] + "/"
    if not os.path.exists(out_path_dir):
        os.makedirs(out_path_dir)

    input_img = Image.open(old_path)
    input_img = np.array(input_img)
    output_img = np.zeros(input_img.shape, np.float32)
    output_img = filter_img(input_img)
    Image.fromarray(output_img.astype(np.uint8)).save(out_path)

train, _ = get_filename('./fgsm_val_list.txt')
p = Pool(8)
p.map(bilateral_filter, train)
p.close()
p.join()


Exemplo n.º 2
0
        # tensor-scalar operation
        images = (images / 255.0) * 2.0 - 1.0
        return images

    if 'resnet' in model_type.lower() or 'vgg' in model_type.lower():
        _R_MEAN = 123.68
        _G_MEAN = 116.78
        _B_MEAN = 103.94
        images = tf.image.resize_bilinear(images, [224,224],align_corners=False)
        tmp_0 = images[:,:,:,0] - _R_MEAN
        tmp_1 = images[:,:,:,1] - _G_MEAN
        tmp_2 = images[:,:,:,2] - _B_MEAN
        images = tf.stack([tmp_0,tmp_1,tmp_2],3)
        return images

train_path, train_label = get_filename('./train_list.txt')
val_path, val_label = get_filename('./val_list.txt')

def load_input_images(batch_shape):
    filenames = []
    output_filenames = []
    input_images = np.zeros(batch_shape)
    idx = 0
    batch_size = batch_shape[0]
    for i in range(len(val_path)):
        path = val_path[i]
        output_path = path.replace("IJCAI_2019_AAAC_train", "IJCAI_fgsm_val")

        out_path_dir = os.path.split(output_path)[0] + "/"
        if not os.path.exists(out_path_dir):
            os.makedirs(out_path_dir)