<jupyter_start><jupyter_text>Visualize imagesjust a notebook to show the images that are stored in the different datasetsyou need to set the proper pathremember w, h= 32, 32 for cifar, and 96, 96 for stl<jupyter_code>import numpy as np
from PIL import Image
from skimage import data
from skimage.color import rgb2gray
from matplotlib.pyplot import imshow

IMAGE=5 #any number (mnist, cifar up to 10000, stl up to 8000)<jupyter_output><empty_output><jupyter_text>Show image for stl<jupyter_code>def to_gray_uint(image):
    return np.uint8(rgb2gray(image) * 255)
data1=np.load("/home/andrea/gpu-monitor/fullattacks/DeepFool_stl10_pytorch.npy")
data = np.swapaxes(data1, 1, 3).astype(np.float32)
data = np.swapaxes(data, 1, 2).astype(np.float32)
#cifar:
#'plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'
#stl:
#airplane, bird, car, cat, deer, dog, horse, monkey, ship, truck
d = data[IMAGE].astype(np.float32) #/ 1 # normalize the data to 0 - 1
d = 255 * d # Now scale by 255
img = d.astype(np.uint8)
#print(data[8])
imshow(np.asarray(img))<jupyter_output><empty_output><jupyter_text>Show image for cifar10 (NO RESNET; MOBILENET; DENSENET) See below for CIFAR10RESNET; CIFAR10MOBILENET; CIFAR10DENSENET<jupyter_code>data1=np.load("/home/andrea/gpu-monitor/fullattacks/normal_cifar10_pytorch.npy")
data = np.swapaxes(data1, 1, 3).astype(np.float32)
#data = np.swapaxes(data, 1, 2).astype(np.float32)
d = data[IMAGE].astype(np.float32) #/ 1 # normalize the data to 0 - 1
d = 255 * d # Now scale by 255
img = d.astype(np.uint8)
#print(data[8])
imshow(np.asarray(img))<jupyter_output><empty_output><jupyter_text>Show image for cifar10 resnet, mobilenet, densenet<jupyter_code>data1=np.load("/home/andrea/gpu-monitor/fullattacks/normal_cifar10resnet_pytorch.npy")
data = np.swapaxes(data1, 1, 3).astype(np.float32)
data = np.swapaxes(data, 1, 2).astype(np.float32)
d = data[IMAGE].astype(np.float32) #/ 1 # normalize the data to 0 - 1
d = d +0.5 #a rough "re-coloring" with respect to the original correction factor applied on cifar10
            #so re-coloring is not very good but allows to get the idea
img = d
#print(data[8])
imshow(np.asarray(img))<jupyter_output>Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).<jupyter_text>show image for mnist<jupyter_code>data1=np.load("/home/andrea/gpu-monitor/fullattacks/Zoo_mnist4_pytorch.npy")
data = np.swapaxes(data1, 1, 3).astype(np.float32)
d = data[IMAGE].astype(np.float32) #/ 1 # normalize the data to 0 - 1

d = 255 * d # Now scale by 255
img = d.astype(np.uint8)
print (type(img))
img1 = Image.fromarray(img.squeeze(), 'L')
imshow(np.asarray(img1))<jupyter_output><class 'numpy.ndarray'>
{'fraction_non_alphanumeric': 0.13851227555881276, 'fraction_numerical': 0.04873580065958227, 'mean_word_length': 5.546762589928058, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '89915', 'license': 'MIT', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1074, 'n_words': 267, 'path': 'notebooks/view_images_cifar_stl_mnist.ipynb', 'repo_name': 'AndreaCeccarelli/gpu-monitor', 'size': '2729'}