def save_svm_images(model_dict, data_dict, X_test, adv_x, dev_mag, rd=None,
dr_alg=None, rev=None):
"""
Save <no_of_img> adv. samples as image files in visual_data folder
"""
no_of_img = 1 # Number of images to save
indices = range(no_of_img)
dataset = model_dict['dataset']
DR = model_dict['dim_red']
channels = model_dict['channels']
abs_path_v = resolve_path_v(model_dict)
no_of_features = data_dict['no_of_features']
height = data_dict['height']
width = data_dict['width']
for i in indices:
if channels == 1:
adv = adv_x[i].reshape((height, width))
orig = X_test[i].reshape((height, width))
cmap = 'gray'
else:
adv = adv_x[i].reshape((channels, height, width))
adv = adv.swapaxes(0, 2).swapaxes(0, 1)
orig = X_test[i].reshape((channels, height, width))
orig = orig.swapaxes(0, 2).swapaxes(0, 1)
cmap = None
fname = abs_path_v
if (rd is not None) and (rev is None):
fname += '{}_{}_{}'.format(i, DR, rd)
elif rd is not None:
fname += '{}_{}_rev_{}'.format(i, DR, rd)
elif rd is None:
fname += '{}'.format(i)
img.imsave(fname + '_mag{}.png'.format(dev_mag), adv, vmin=0, vmax=1,
cmap=cmap)
img.imsave(fname + '_orig.png', orig, vmin=0, vmax=1, cmap=cmap)
#------------------------------------------------------------------------------#
评论列表
文章目录