Exemplo n.º 1
0
import pickle
from util.load_mnist import load_mnist_train_XY
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
from sklearn.metrics import pairwise_distances

x, y = load_mnist_train_XY()
'''
x_r = load_robust_output()
x_nr = load_nonrobust_output()
'''

with open('../robust_morph.bin', 'rb') as infile:
    x_r = pickle.load(infile)

with open('../nonrobust_morph.bin', 'rb') as infile:
    x_nr = pickle.load(infile)

numSamples = x.shape[0]

x = x.reshape((numSamples, -1)).astype(np.float) / 255.0
x_r = x_r.reshape((numSamples, -1))
x_nr = x_nr.reshape((numSamples, -1))

locations = [np.where(y == i)[0] for i in range(10)]

result = []

for i in range(10):
    sampleMat = x[locations[i], ...]
import warnings
from util.load_mnist import load_mnist_train_XY, preprocess_mnist_data
from sklearn.model_selection import train_test_split
warnings.filterwarnings(action='ignore', category=FutureWarning)
import pickle
import tensorflow as tf

_, y = preprocess_mnist_data(*load_mnist_train_XY())

#data = load_robust_output()
#data = load_nonrobust_output()
with open('../robust_morph.bin', 'rb') as infile:
    data = pickle.load(infile)

train_X, test_X, train_Y, test_Y = train_test_split(data, y, test_size=0.1)


def get_new_network():
    network = tf.keras.Sequential([
        tf.keras.layers.Conv2D(32, (3, 3),
                               input_shape=train_X.shape[1:],
                               activation='relu'),
        tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),
        tf.keras.layers.MaxPooling2D((2, 2)),
        tf.keras.layers.Dropout(0.4),
        tf.keras.layers.Flatten(),
        tf.keras.layers.Dense(100, activation='relu', name="FC"),
        tf.keras.layers.Dropout(0.4),
        tf.keras.layers.Dense(
            10, activation='softmax')  # no activation for the last layer
    ])
Exemplo n.º 3
0
import subprocess
from util.load_mnist import load_mnist_train_XY
import time
import re
import threading
from queue import Queue

train_X, _ = load_mnist_train_XY()

concurrency = 5
readLineTimeout = 0.1


def enqueue_output(id, fileobj, queue):
    for line in iter(fileobj.readline, b''):
        queue.put((id, line))


def reconstruct_robust_dataset(left=0, right=-1):
    if right == -1:
        right = train_X.shape[0]

    assert right > left

    numSamples = right - left
    taskStep = numSamples // concurrency

    params = []

    for i in range(concurrency):
        params.append([