diff --git a/.gitattributes b/.gitattributes index 2c91e8510f64988b36eacc6b4b64244ce27799ea..80afa15e7b516c61723af0bbdc66333499256bb6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -26,3 +26,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.zstandard filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text *ubyte* filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text diff --git a/app.py b/app.py index 51ea7d02a7b7b01a674d2eaae5f82ef8d06c3982..8230c595559834407fe3688b5d07c9320cc6d765 100644 --- a/app.py +++ b/app.py @@ -2,51 +2,163 @@ import os import torch import gradio as gr import torchvision +from PIL import Image from utils import * import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from huggingface_hub import Repository, upload_file +from torch.utils.data import Dataset +import numpy as np +from collections import Counter -n_epochs = 3 -batch_size_train = 64 + +n_epochs = 10 +batch_size_train = 128 batch_size_test = 1000 learning_rate = 0.01 momentum = 0.5 log_interval = 10 random_seed = 1 - +TRAIN_CUTOFF = 5 +WHAT_TO_DO=WHAT_TO_DO.format(num_samples=TRAIN_CUTOFF) +METRIC_PATH = './metrics.json' REPOSITORY_DIR = "data" LOCAL_DIR = 'data_local' os.makedirs(LOCAL_DIR,exist_ok=True) + + HF_TOKEN = os.getenv("HF_TOKEN") HF_DATASET ="mnist-adversarial-dataset" +DATASET_REPO_URL = f"https://huggingface.co/datasets/chrisjay/{HF_DATASET}" +repo = Repository( + local_dir="data_mnist", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN +) +repo.git_pull() torch.backends.cudnn.enabled = False torch.manual_seed(random_seed) -train_loader = torch.utils.data.DataLoader( - torchvision.datasets.MNIST('files/', train=True, download=True, - transform=torchvision.transforms.Compose([ + +class MNISTAdversarial_Dataset(Dataset): + + def __init__(self,data_dir,transform): + repo.git_pull() + self.data_dir = os.path.join(data_dir,'data') + self.transform = transform + files = [f.name for f in os.scandir(self.data_dir)] + self.images = [] + self.numbers = [] + for f in files: + self.FOLDER = os.path.join(os.path.join(self.data_dir,f)) + + metadata_path = os.path.join(self.FOLDER,'metadata.jsonl') + + image_path =os.path.join(self.FOLDER,'image.png') + if os.path.exists(image_path) and os.path.exists(metadata_path): + img = Image.open(image_path) + self.images.append(img) + metadata = read_json_lines(metadata_path) + self.numbers.append(metadata[0]['correct_number']) + assert len(self.images)==len(self.numbers), f"Length of images and numbers must be the same. Got {len(self.images)} for images and {len(self.numbers)} for numbers." + def __len__(self): + return len(self.images) + + def __getitem__(self,idx): + img, label = self.images[idx], self.numbers[idx] + img = self.transform(img) + return img, label + +class MNISTCorrupted_By_Digit(Dataset): + def __init__(self,transform,digit,limit=30): + self.transform = transform + self.digit = digit + corrupted_dir="./mnist_c" + files = [f.name for f in os.scandir(corrupted_dir)] + images = [np.load(os.path.join(os.path.join(corrupted_dir,f),'test_images.npy')) for f in files] + labels = [np.load(os.path.join(os.path.join(corrupted_dir,f),'test_labels.npy')) for f in files] + self.data = np.vstack(images) + self.labels = np.hstack(labels) + + assert (self.data.shape[0] == self.labels.shape[0]) + + mask = self.labels == self.digit + + data_masked = self.data[mask] + # Just to be on the safe side, ensure limit is more than the minimum + limit = min(limit,data_masked.shape[0]) + + self.data_for_use = data_masked[:limit] + self.labels_for_use = self.labels[mask][:limit] + assert (self.data_for_use.shape[0] == self.labels_for_use.shape[0]) + + def __len__(self): + return len(self.data_for_use) + def __getitem__(self,idx): + if torch.is_tensor(idx): + idx = idx.tolist() + + image = self.data_for_use[idx] + label = self.labels_for_use[idx] + if self.transform: + image_pil = torchvision.transforms.ToPILImage()(image) # Need to transform to PIL before using default transforms + image = self.transform(image_pil) + + return image, label + + + + + +class MNISTCorrupted(Dataset): + def __init__(self,transform): + self.transform = transform + corrupted_dir="./mnist_c" + files = [f.name for f in os.scandir(corrupted_dir)] + images = [np.load(os.path.join(os.path.join(corrupted_dir,f),'test_images.npy')) for f in files] + labels = [np.load(os.path.join(os.path.join(corrupted_dir,f),'test_labels.npy')) for f in files] + self.data = np.vstack(images) + self.labels = np.hstack(labels) + + assert (self.data.shape[0] == self.labels.shape[0]) + + def __len__(self): + return len(self.data) + + def __getitem__(self, idx): + if torch.is_tensor(idx): + idx = idx.tolist() + + image = self.data[idx] + label = self.labels[idx] + if self.transform: + image_pil = torchvision.transforms.ToPILImage()(image) # Need to transform to PIL before using default transforms + image = self.transform(image_pil) + + return image, label + + + +TRAIN_TRANSFORM = torchvision.transforms.Compose([ torchvision.transforms.ToTensor(), torchvision.transforms.Normalize( (0.1307,), (0.3081,)) - ])), + ]) + +''' +train_loader = torch.utils.data.DataLoader( + torchvision.datasets.MNIST('files/', train=True, download=True, + transform=TRAIN_TRANSFORM), batch_size=batch_size_train, shuffle=True) +''' -test_loader = torch.utils.data.DataLoader( - torchvision.datasets.MNIST('files/', train=False, download=True, - transform=torchvision.transforms.Compose([ - torchvision.transforms.ToTensor(), - torchvision.transforms.Normalize( - (0.1307,), (0.3081,)) - ])), - batch_size=batch_size_test, shuffle=True) +test_loader = torch.utils.data.DataLoader(MNISTCorrupted(TRAIN_TRANSFORM), + batch_size=batch_size_test, shuffle=False) # Source: https://nextjournal.com/gkoehler/pytorch-mnist @@ -69,7 +181,7 @@ class MNIST_Model(nn.Module): return F.log_softmax(x) -def train(epochs,network,optimizer): +def train(epochs,network,optimizer,train_loader): train_losses=[] network.train() @@ -102,10 +214,11 @@ def test(): correct += pred.eq(target.data.view_as(pred)).sum() test_loss /= len(test_loader.dataset) test_losses.append(test_loss) + acc = 100. * correct / len(test_loader.dataset) + acc = acc.item() test_metric = '〽Current test metric - Avg. loss: `{:.4f}`, Accuracy: `{}/{}` (`{:.0f}%`)\n'.format( - test_loss, correct, len(test_loader.dataset), - 100. * correct / len(test_loader.dataset)) - return test_metric + test_loss, correct, len(test_loader.dataset),acc ) + return test_metric,acc @@ -156,15 +269,41 @@ def image_classifier(inp): def train_and_test(): # Train for one epoch and test - train(1,network,optimizer) - test_metric = test() - -def flag(input_image,correct_result,train): - # take an image, the wrong result, the correct result. - # push to dataset. - # get size of current dataset - - # Write audio to file + train_dataset = MNISTAdversarial_Dataset('./data_mnist',TRAIN_TRANSFORM) + + train_loader = torch.utils.data.DataLoader(train_dataset,batch_size=batch_size_test, shuffle=True + ) + train(n_epochs,network,optimizer,train_loader) + test_metric,test_acc = test() + + if os.path.exists(METRIC_PATH): + metric_dict = read_json(METRIC_PATH) + metric_dict['all'] = metric_dict['all'] if 'all' in metric_dict else [] + [test_acc] + else: + metric_dict={} + metric_dict['all'] = [test_acc] + + for i in range(10): + data_per_digit = MNISTCorrupted_By_Digit(TRAIN_TRANSFORM,i) + dataloader_per_digit = torch.utils.data.DataLoader(data_per_digit,batch_size=len(data_per_digit), shuffle=False) + data_per_digit, label_per_digit = iter(dataloader_per_digit).next() + output = network(data_per_digit) + pred = output.data.max(1, keepdim=True)[1] + correct = pred.eq(label_per_digit.data.view_as(pred)).sum() + acc = 100. * correct / len(data_per_digit) + acc=acc.item() + if os.path.exists(METRIC_PATH): + metric_dict[str(i)].append(acc) + else: + metric_dict[str(i)] = [acc] + + dump_json(thing=metric_dict,file=METRIC_PATH) + return test_metric + +def flag(input_image,correct_result,adversarial_number): + + adversarial_number = 0 if None else adversarial_number + metadata_name = get_unique_name() SAVE_FILE_DIR = os.path.join(LOCAL_DIR,metadata_name) os.makedirs(SAVE_FILE_DIR,exist_ok=True) @@ -182,7 +321,7 @@ def flag(input_image,correct_result,train): dump_json(metadata,json_file_path) - # Simply upload the audio file and metadata using the hub's upload_file + # Simply upload the image file and metadata using the hub's upload_file # Upload the image repo_image_path = os.path.join(REPOSITORY_DIR,os.path.join(metadata_name,'image.png')) @@ -201,43 +340,84 @@ def flag(input_image,correct_result,train): repo_type='dataset', token=HF_TOKEN ) + adversarial_number+=1 + output = f'
✔ ({adversarial_number}) Successfully saved your adversarial data.
' + repo.git_pull() + length_of_dataset = len([f for f in os.scandir("./data_mnist/data")]) + test_metric = f" {DEFAULT_TEST_METRIC} " + if length_of_dataset % TRAIN_CUTOFF ==0: + test_metric_ = train_and_test() + test_metric = f" {test_metric_} " + output = f'
✔ ({adversarial_number}) Successfully saved your adversarial data and trained the model on adversarial data!
' + return output,test_metric,adversarial_number + +def get_number_dict(DATA_DIR): + files = [f.name for f in os.scandir(DATA_DIR)] + numbers = [read_json_lines(os.path.join(os.path.join(DATA_DIR,f),'metadata.jsonl'))[0]['correct_number'] for f in files] + numbers_count = Counter(numbers) + numbers_count_keys = list(numbers_count.keys()) + numbers_count_values = [numbers_count[k] for k in numbers_count_keys] + return numbers_count_keys,numbers_count_values + + + +def get_statistics(): + model_state_dict = 'model.pth' + optimizer_state_dict = 'optmizer.pth' + + if os.path.exists(model_state_dict): + network_state_dict = torch.load(model_state_dict) + network.load_state_dict(network_state_dict) + + if os.path.exists(optimizer_state_dict): + optimizer_state_dict = torch.load(optimizer_state_dict) + optimizer.load_state_dict(optimizer_state_dict) + repo.git_pull() + DATA_DIR = './data_mnist/data' + numbers_count_keys,numbers_count_values = get_number_dict(DATA_DIR) + + + plt_digits = plot_bar(numbers_count_values,numbers_count_keys,'Number of adversarial samples',"Digit",f"Distribution of adversarial samples over digits") - output = f'
✔ Successfully saved to flagged dataset.
' - train=True - if train: - output = f'
✔ Successfully saved to flagged dataset. Training the model on adversarial data!
' + fig_d, ax_d = plt.subplots(figsize=(10,4),tight_layout=True) - return output,train + if os.path.exists(METRIC_PATH): + metric_dict = read_json(METRIC_PATH) + for i in range(10): + try: + x_i = [i+1 for i in range(len(metric_dict[str(i)]))] + ax_d.plot(x_i, metric_dict[str(i)],label=str(i)) + except Exception: + continue + dump_json(thing=metric_dict,file=METRIC_PATH) + else: + metric_dict={} + fig_d.legend() + ax_d.set(xlabel='Adversarial train steps', ylabel='MNIST_C Test Accuracy',title="Test Accuracy over digits per train step") + done_html = """
+

✅ Statistics loaded successfully!

+
+ """ -def main(): - TITLE = "# MNIST Adversarial: Try to fool this MNIST model" - description = """This project is about dynamic adversarial data collection (DADC). - The basic idea is to collect “adversarial data” - the kind of data that is difficult for a model to predict correctly. - This kind of data is presumably the most valuable for a model, so this can be helpful in low-resource settings where data is hard to collect and label. - - ### What to do: - - Draw a number from 0-9. - - Click `Submit` and see the model's prediciton. - - If the model misclassifies it, Flag that example. - - This will add your (adversarial) example to a dataset on which the model will be trained later. - """ + return plt_digits,fig_d,done_html - MODEL_IS_WRONG = """ - --- - > Did the model get it wrong? Choose the correct prediction below and flag it. When you flag it, the instance is saved to our dataset and the model is trained on it. - """ + + +def main(): #block = gr.Blocks(css=BLOCK_CSS) block = gr.Blocks() with block: gr.Markdown(TITLE) + gr.Markdown(description) with gr.Tabs(): - gr.Markdown(description) with gr.TabItem('MNIST'): + gr.Markdown(WHAT_TO_DO) + test_metric = gr.outputs.HTML(DEFAULT_TEST_METRIC) with gr.Row(): @@ -249,15 +429,32 @@ def main(): number_dropdown = gr.Dropdown(choices=[i for i in range(10)],type='value',default=None,label="What was the correct prediction?") flag_btn = gr.Button("Flag") + output_result = gr.outputs.HTML() - to_train = gr.Variable(value=False) + adversarial_number = gr.Variable(value=0) + + submit.click(image_classifier,inputs = [image_input],outputs=[label_output]) - flag_btn.click(flag,inputs=[image_input,number_dropdown,to_train],outputs=[output_result,to_train]) - if to_train.value: - import pdb;pdb.set_trace() - train_and_test() + flag_btn.click(flag,inputs=[image_input,number_dropdown,adversarial_number],outputs=[output_result,test_metric,adversarial_number]) - + with gr.TabItem('Dashboard') as dashboard: + notification = gr.HTML("""
+

⌛ Creating statistics...

+
+ """) + _,numbers_count_values_ = get_number_dict('./data_mnist/data') + + STATS_EXPLANATION_ = STATS_EXPLANATION.format(num_adv_samples = sum(numbers_count_values_)) + + gr.Markdown(STATS_EXPLANATION_) + stat_adv_image =gr.Plot(type="matplotlib") + gr.Markdown(DASHBOARD_EXPLANATION) + test_results=gr.Plot(type="matplotlib") + + dashboard.select(get_statistics,inputs=[],outputs=[stat_adv_image,test_results,notification]) + + + block.launch() diff --git a/data_mnist b/data_mnist new file mode 160000 index 0000000000000000000000000000000000000000..eb1e3cf9de597112c1da3b921ffcd07c8e4419c1 --- /dev/null +++ b/data_mnist @@ -0,0 +1 @@ +Subproject commit eb1e3cf9de597112c1da3b921ffcd07c8e4419c1 diff --git a/mnist_c/brightness/test_images.npy b/mnist_c/brightness/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..4c6b3fc66e0877c8b1fc69d13dde3196f4680b22 --- /dev/null +++ b/mnist_c/brightness/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0be26b927b2be43bc0b2430ccf6aa6048a5fcd8bcd087d97576972f009c1e8a9 +size 7840128 diff --git a/mnist_c/brightness/test_labels.npy b/mnist_c/brightness/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/brightness/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/brightness/train_images.npy b/mnist_c/brightness/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..aac2b87692c5df66c0aee0ddecf1a5483f881df7 --- /dev/null +++ b/mnist_c/brightness/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:466c8f7365f37d14012ec66e2d1203ef07acae08240bb1af1863f09318293255 +size 47040128 diff --git a/mnist_c/brightness/train_labels.npy b/mnist_c/brightness/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/brightness/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/canny_edges/test_images.npy b/mnist_c/canny_edges/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..70243c28d31fb06672c6c585cb78c9dd99f231e2 --- /dev/null +++ b/mnist_c/canny_edges/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e86b158456cbaf0bf621092259f186a223b68e31128c18cceedb8a2f1b8baf1f +size 7840128 diff --git a/mnist_c/canny_edges/test_labels.npy b/mnist_c/canny_edges/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/canny_edges/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/canny_edges/train_images.npy b/mnist_c/canny_edges/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..c428ae5c697811252c2e873aabd909affc895793 --- /dev/null +++ b/mnist_c/canny_edges/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d6454058f0025bd15f34f9d14df4fdf2cca8f47b38661da5b650bee9c77aac5 +size 47040128 diff --git a/mnist_c/canny_edges/train_labels.npy b/mnist_c/canny_edges/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/canny_edges/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/dotted_line/test_images.npy b/mnist_c/dotted_line/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..6fdcb0364e788fcc6e94b1cd0108f28cc914f0c0 --- /dev/null +++ b/mnist_c/dotted_line/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:02f5a8bd11e1bed6ca5f31418c6804a4f89ab5abdaba38f880e4743294516c6b +size 7840128 diff --git a/mnist_c/dotted_line/test_labels.npy b/mnist_c/dotted_line/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/dotted_line/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/dotted_line/train_images.npy b/mnist_c/dotted_line/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..885d769f80bdb555b3f7adb58c29e06bad320a0b --- /dev/null +++ b/mnist_c/dotted_line/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d2d1ad4696a96af19f6bcd07a2ea9f2fb0990910397ef41b969d26080aef23cb +size 47040128 diff --git a/mnist_c/dotted_line/train_labels.npy b/mnist_c/dotted_line/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/dotted_line/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/fog/test_images.npy b/mnist_c/fog/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..8b025e0afdaf7a7376f430fa16e8c0fa13690531 --- /dev/null +++ b/mnist_c/fog/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f48ea89b4793c45bedda39bd27b42710f4f0cbf5bced559597c015157188488 +size 7840128 diff --git a/mnist_c/fog/test_labels.npy b/mnist_c/fog/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/fog/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/fog/train_images.npy b/mnist_c/fog/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..50ef606c4100072a652661a2fd42b6361ee59655 --- /dev/null +++ b/mnist_c/fog/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c92a6df9c3703b3df29fdb272d829736e706150104a7f7c81f37387940120e9 +size 47040128 diff --git a/mnist_c/fog/train_labels.npy b/mnist_c/fog/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/fog/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/glass_blur/test_images.npy b/mnist_c/glass_blur/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..d93c611572cf80d346fa32d0419829f91fc8133b --- /dev/null +++ b/mnist_c/glass_blur/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:300a4829b7fe6e4cfa5ad0e134cf19136e2c23e1e6bc29b6c574848b6a493388 +size 7840128 diff --git a/mnist_c/glass_blur/test_labels.npy b/mnist_c/glass_blur/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/glass_blur/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/glass_blur/train_images.npy b/mnist_c/glass_blur/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..15c6a87497836ca21b19656a57d247124f553655 --- /dev/null +++ b/mnist_c/glass_blur/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:255b6832620840d2db4423212d02c903d4edf5b31b94e16ac130f2539c73275f +size 47040128 diff --git a/mnist_c/glass_blur/train_labels.npy b/mnist_c/glass_blur/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/glass_blur/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/identity/test_images.npy b/mnist_c/identity/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..72018c1df6f7ea54f6ca63ea3920addcf501adac --- /dev/null +++ b/mnist_c/identity/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c544e9053023b30ffd401a9825696f84af6fb1eb822bba5fcffc6992808357c3 +size 7840128 diff --git a/mnist_c/identity/test_labels.npy b/mnist_c/identity/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/identity/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/identity/train_images.npy b/mnist_c/identity/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..3f5a226511a6fdd9b56efc8d4b0c07f7a81b770f --- /dev/null +++ b/mnist_c/identity/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f323590fab80abce68b33a35fb0a176bed275ab73b934621f7583bd1c7c1b1ba +size 47040128 diff --git a/mnist_c/identity/train_labels.npy b/mnist_c/identity/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/identity/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/impulse_noise/test_images.npy b/mnist_c/impulse_noise/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..4dbb66c396d03c3c7d0cdd8655a7f405ef850d9a --- /dev/null +++ b/mnist_c/impulse_noise/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63ad2d4c0860dca3814da6034943dda6e9fe267ba6e12136341c52f2c13ca3d5 +size 7840128 diff --git a/mnist_c/impulse_noise/test_labels.npy b/mnist_c/impulse_noise/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/impulse_noise/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/impulse_noise/train_images.npy b/mnist_c/impulse_noise/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..6ccf793ef1710b45b448c474307788ff03921caf --- /dev/null +++ b/mnist_c/impulse_noise/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5921469548b8d051544f29b984112d0680054bba619b7a69a1479cbd082b9563 +size 47040128 diff --git a/mnist_c/impulse_noise/train_labels.npy b/mnist_c/impulse_noise/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/impulse_noise/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/motion_blur/test_images.npy b/mnist_c/motion_blur/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..d087b162c7eb44b3b1d0754f8b85c878e0007b96 --- /dev/null +++ b/mnist_c/motion_blur/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7767b48be95a63abcdf851a4baedc0491d5643a192072e4f6de0a14c75cb089e +size 7840128 diff --git a/mnist_c/motion_blur/test_labels.npy b/mnist_c/motion_blur/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/motion_blur/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/motion_blur/train_images.npy b/mnist_c/motion_blur/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..dc00c443eccd3d9485f66860e66f4dd8d9dc7057 --- /dev/null +++ b/mnist_c/motion_blur/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f11f24aa857845517b700892d5dcbeeb8c2ee3a7b0028e27a6231c9aaa4f32db +size 47040128 diff --git a/mnist_c/motion_blur/train_labels.npy b/mnist_c/motion_blur/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/motion_blur/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/rotate/test_images.npy b/mnist_c/rotate/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..28fab914bfbea68e23b8f15753fc1fceea8ad060 --- /dev/null +++ b/mnist_c/rotate/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8fb565f28d858733ec94d4e6d976d9f2cb3e6aa75deb9a7a11b0504b9ae64520 +size 7840128 diff --git a/mnist_c/rotate/test_labels.npy b/mnist_c/rotate/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/rotate/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/rotate/train_images.npy b/mnist_c/rotate/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..7d29e8e34958d7ea72ea47d5fd1da972bc52db5b --- /dev/null +++ b/mnist_c/rotate/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:505bcc0035d1f36fe6560e39cbb3888ed0130d429bca92019f29b0cfe5ab8724 +size 47040128 diff --git a/mnist_c/rotate/train_labels.npy b/mnist_c/rotate/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/rotate/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/scale/test_images.npy b/mnist_c/scale/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..4def287dc4972dcd55d9359767ce494062f93005 --- /dev/null +++ b/mnist_c/scale/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:282dfee12607c13ea76cc82985e3e5d78f36b44d56d6ad9f12a2298e20ea2200 +size 7840128 diff --git a/mnist_c/scale/test_labels.npy b/mnist_c/scale/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/scale/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/scale/train_images.npy b/mnist_c/scale/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..1fe50003eb38d0a05c31f43fbc66454f529c6406 --- /dev/null +++ b/mnist_c/scale/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f558258555337a45d82b572a6a2ed48c3117985213937ded3fc6a738832b4f1b +size 47040128 diff --git a/mnist_c/scale/train_labels.npy b/mnist_c/scale/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/scale/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/shear/test_images.npy b/mnist_c/shear/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..16083885b08fbc703fdf7c4aa95f7b094579130c --- /dev/null +++ b/mnist_c/shear/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:38412620554c8d775e38d6b9d771b4825605998179e88bd004d8d5d0a7afaa7d +size 7840128 diff --git a/mnist_c/shear/test_labels.npy b/mnist_c/shear/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/shear/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/shear/train_images.npy b/mnist_c/shear/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..ac459e7a5d6c1d74fda8bb39d4f82e1ca34162e2 --- /dev/null +++ b/mnist_c/shear/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:133295f31cf838b4905b8e05083570e8189e37839168f37e3e83831244e54579 +size 47040128 diff --git a/mnist_c/shear/train_labels.npy b/mnist_c/shear/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/shear/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/shot_noise/test_images.npy b/mnist_c/shot_noise/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..6fc4c65632cf1939096d5a64e5c037f1a5647302 --- /dev/null +++ b/mnist_c/shot_noise/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c7026fb754f234a1563711576266f179f47b6f5e4a8e43dfbbb182e1299d764 +size 7840128 diff --git a/mnist_c/shot_noise/test_labels.npy b/mnist_c/shot_noise/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/shot_noise/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/shot_noise/train_images.npy b/mnist_c/shot_noise/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..c0ecbca847b5b19eec049f6e835010cb8af93e55 --- /dev/null +++ b/mnist_c/shot_noise/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67dc136c87501002f971be5dabd14c8e56615af61c699a7707faf4185dfbfdf6 +size 47040128 diff --git a/mnist_c/shot_noise/train_labels.npy b/mnist_c/shot_noise/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/shot_noise/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/spatter/test_images.npy b/mnist_c/spatter/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..2f0ef28f03fd4254fa5ac797bcde31c0256d4357 --- /dev/null +++ b/mnist_c/spatter/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c2944a2bcf07747a61235e759f039498848f6a975a8646e1fe50bd9378e3365e +size 7840128 diff --git a/mnist_c/spatter/test_labels.npy b/mnist_c/spatter/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/spatter/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/spatter/train_images.npy b/mnist_c/spatter/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..ad60c9f6ebd82e7fe82d0042f1628d4624f5f619 --- /dev/null +++ b/mnist_c/spatter/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f3bb2e5eaa946f9a5ca485f34991b05a06cd6725d76563eb6cce578555d7ae6 +size 47040128 diff --git a/mnist_c/spatter/train_labels.npy b/mnist_c/spatter/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/spatter/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/stripe/test_images.npy b/mnist_c/stripe/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..987055cf71b012337528e585650ed4bcffd340b6 --- /dev/null +++ b/mnist_c/stripe/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e1037ade91e048957df2b942657ac23b944b6b061f1331e0abca0d60f385b9a0 +size 7840128 diff --git a/mnist_c/stripe/test_labels.npy b/mnist_c/stripe/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/stripe/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/stripe/train_images.npy b/mnist_c/stripe/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..b121e77f6d922fd60c523ae431cfc0091a5b21eb --- /dev/null +++ b/mnist_c/stripe/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51eddcea6573b839caa27d4ca6497b4b25099172607d46a34242190dba7ede53 +size 47040128 diff --git a/mnist_c/stripe/train_labels.npy b/mnist_c/stripe/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/stripe/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/translate/test_images.npy b/mnist_c/translate/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..579f45efa729b68862f09eddffc30f50d81624f3 --- /dev/null +++ b/mnist_c/translate/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c4954a5bd344e047f016d2a64cc1b8bf9624a11526dc75acef8367181ba0ab3b +size 7840128 diff --git a/mnist_c/translate/test_labels.npy b/mnist_c/translate/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/translate/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/translate/train_images.npy b/mnist_c/translate/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..ea59e679dc0fa905e1a0126698518fca14a1b27b --- /dev/null +++ b/mnist_c/translate/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:892a62e9a5285b79bcd57b64e5029cd12d874a26cee9c02cc0885d2da363daf0 +size 47040128 diff --git a/mnist_c/translate/train_labels.npy b/mnist_c/translate/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/translate/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/mnist_c/zigzag/test_images.npy b/mnist_c/zigzag/test_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..7c04755f3fd716dbbd75676f417d90a633d21827 --- /dev/null +++ b/mnist_c/zigzag/test_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae655a6b0bdfd2d70951431465d1045274ab8f8bce475edba4477114c2fbfa7d +size 7840128 diff --git a/mnist_c/zigzag/test_labels.npy b/mnist_c/zigzag/test_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ce07e05c1214c0952870ff3b429cc44e57d24e87 --- /dev/null +++ b/mnist_c/zigzag/test_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:996074233ccae69ee65b8551233f608adc1bce84b6b440e3531478a847958149 +size 80128 diff --git a/mnist_c/zigzag/train_images.npy b/mnist_c/zigzag/train_images.npy new file mode 100644 index 0000000000000000000000000000000000000000..254ccc96cee8d7654981f6f12d7ab289c8b3986c --- /dev/null +++ b/mnist_c/zigzag/train_images.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dabd6850f75dc068802cccf858d06c9e0a61505362d04823979c7109768d5679 +size 47040128 diff --git a/mnist_c/zigzag/train_labels.npy b/mnist_c/zigzag/train_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..ef05f30cdaef1c8904b9a10f504fe3763fc3d254 --- /dev/null +++ b/mnist_c/zigzag/train_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10226b938104d9231ead4e9a0627f17e66cd18baf31a28784f1b72147057decf +size 480128 diff --git a/model.pth b/model.pth index c838b738bb8cdff2390f77b295778104da183600..f7466bfd48ff4ed72891a7be15c2401d18e58347 100644 --- a/model.pth +++ b/model.pth @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ffe16177c76477e22a35b45ac44d3a06f758d07df5ca37379a490ed69f7ff80e +oid sha256:70d9632141eaf1062d2973b2fc9c4c9b286d6ae563297328ed929be8401b4a15 size 89871 diff --git a/optimizer.pth b/optimizer.pth index 80c67ea1a7d3fa48f7f11b224a67441606503aba..6a458a5e5f4a05e24eb1bb147ff884a2653a1eda 100644 --- a/optimizer.pth +++ b/optimizer.pth @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ea0b9cee5af7847bf896b2c9692b1cf36fe447d67be87d1b98634091f20babe6 +oid sha256:4c6a2a19c5c0dc6aabfa195bfc337c3d9c29e5ef78c546b65b08aa86dcc60287 size 89807 diff --git a/requirements.txt b/requirements.txt index ac988bdf8417d99a3c45236479862b18684c79f5..cd095e4cd3d6e7c8a5e3728d83434dc34b027337 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ torch torchvision +matplotlib \ No newline at end of file diff --git a/utils.py b/utils.py index f56708d24eff9522a7aee51996554a9f7a7cc215..3458a79d945ed4d9a4df3cf731a826be8a3e9633 100644 --- a/utils.py +++ b/utils.py @@ -3,14 +3,42 @@ import json import hashlib import random import string +import matplotlib.pyplot as plt +TITLE = "# MNIST Adversarial: Try to fool this MNIST model" +description = """This project is about dynamic adversarial data collection (DADC). +The basic idea is to collect “adversarial data” - the kind of data that is difficult for a model to predict correctly. +This kind of data is presumably the most valuable for a model, so this can be helpful in low-resource settings where data is hard to collect and label. +""" +WHAT_TO_DO=""" +### What to do: +1. Draw a number from 0-9. +2. Click `Submit` and see the model's prediciton. +3. If the model misclassifies it, Flag that example. +4. This will add your (adversarial) example to a dataset on which the model will be trained later. +5. The model will finetune on the adversarial samples after every __{num_samples}__ samples have been generated. +""" +MODEL_IS_WRONG = """ +--- + +> Did the model get it wrong? Choose the correct prediction below and flag it. When you flag it, the instance is saved to our dataset and the model is trained on it. +""" +DEFAULT_TEST_METRIC = " Current test metric - Avg. loss: 1000, Accuracy: 30/1000 (30%) " + +DASHBOARD_EXPLANATION="To see the effect of our model on out-of-distribution data, we test it on the [MNIST Corrupted test dataset](https://zenodo.org/record/3239543)." + +STATS_EXPLANATION = "Here is the distribution of the __{num_adv_samples}__ adversarial samples we've got. The dataset can be found [here](https://huggingface.co/datasets/chrisjay/mnist-adversarial-dataset)." def get_unique_name(): return ''.join([random.choice(string.ascii_letters + string.digits) for n in range(32)]) +def read_json(file): + with open(file,'r',encoding="utf8") as f: + return json.load(f) + def read_json_lines(file): with open(file,'r',encoding="utf8") as f: lines = f.readlines() @@ -35,10 +63,12 @@ def dump_json(thing,file): with open(file,'w+',encoding="utf8") as f: json.dump(thing,f) -def read_json_lines(file): - with open(file,'r',encoding="utf8") as f: - lines = f.readlines() - data=[] - for l in lines: - data.append(json.loads(l)) - return data \ No newline at end of file + +def plot_bar(value,name,x_name,y_name,title): + fig, ax = plt.subplots(figsize=(10,4),tight_layout=True) + + ax.set(xlabel=x_name, ylabel=y_name,title=title) + + ax.barh(name, value) + + return ax.figure \ No newline at end of file