# -*- coding: utf-8 -*-
"""
Created on Fri Oct 21 07:53:10 2022

@author: james
"""

import matplotlib.pyplot as plt
import numpy as np
import json

''' Load CIFAR-10 images '''
img_cifar = np.load('../adv_egs/cifar_rand_images.npy')

''' Load sorted random CIFAR-10 indices and create dictionary lookup'''
with open('../input/randCIFAR.json', 'r') as f:
    indices = json.load(f)
indices = {v:i for i,v in enumerate(indices)}

''' scen = scenario name as the parameter set joined by underscores when the adversarial examples are generated by the controller program.
    For example: model2_L2_rank-linear_bright_bf_ '''
scen = 'model2_L2_rank-linear_bright_bf_'

# img_id = CIFAR-10 ID
img_id = 977

adv_eg = np.load(f'../output/images/{scen}{str(img_id)}.npy').reshape(32,32,3)
cifar = img_cifar[indices[img_id]].reshape(32,32,3)

fig,ax = plt.subplots(1,2)
ax[0].imshow(cifar)
ax[1].imshow(adv_eg)
plt.show()