Example #1
0
elif DATASET=='svhn':
    dataset = sknet.dataset.load_svhn()

if "valid_set" not in dataset.sets:
    dataset.split_set("train_set", "valid_set", 0.15)

standardize = sknet.dataset.Standardize().fit(dataset['images/train_set'])
dataset['images/train_set'] = \
                        standardize.transform(dataset['images/train_set'])
dataset['images/test_set'] = \
                        standardize.transform(dataset['images/test_set'])
dataset['images/valid_set'] = \
                        standardize.transform(dataset['images/valid_set'])

iterator = BatchIterator(32, {'train_set': "random_see_all",
                         'valid_set': 'continuous',
                         'test_set': 'continuous'})

dataset.create_placeholders(iterator, device="/cpu:0")

# Utility function
#-----------------

#c_p = tf.placeholder(tf.int32)
i_p = tf.placeholder(tf.int32)
j_p = tf.placeholder(tf.int32)

def get_distance(input,tensor):
    def doit(c):
        gradient = tf.gradients(tensor[:,c,i_p,j_p],input)[0]
        norm = tf.sqrt(tf.reduce_sum(tf.square(gradient),[1,2,3]))
Example #2
0
from sknet.dataset import BatchIterator
from sknet import ops, layers
from sknet.utils import flatten
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

dataset = sknet.dataset.load_freefield1010(n_samples=2000, subsample=6)
dataset['signals/train_set'] /= dataset['signals/train_set'].max(2,
                                                                 keepdims=True)

if "test_set" not in dataset.sets:
    dataset.split_set("train_set", "test_set", 0.33)

dataset.create_placeholders(batch_size=5,
                            iterators_dict={
                                'train_set': BatchIterator("random_see_all"),
                                'valid_set': BatchIterator('continuous'),
                                'test_set': BatchIterator('continuous')
                            },
                            device="/cpu:0")

# Create Network
#---------------

dnn = sknet.Network(name='simple_model')

dnn.append(
    sknet.ops.HermiteSplineConv1D(dataset.signals,
                                  J=5,
                                  Q=6,
                                  K=15,
Example #3
0
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors

# Data Loading
#-------------
N = 500
TIME = np.linspace(-2, 2, N)
X = np.meshgrid(TIME, TIME)
X = np.stack([X[0].flatten(), X[1].flatten()], 1).astype('float32')

dataset = sknet.dataset.Dataset()
dataset.add_variable({'input': {'train_set': X}})

dataset.create_placeholders(
    batch_size=50,
    iterators_dict={'train_set': BatchIterator("continuous")},
    device="/cpu:0")

# Create Network
#---------------

# we use a batch_size of 64 and use the dataset.datum shape to
# obtain the shape of 1 observation and create the input shape

# DN for the layer case

# RANK 1 PARALLEL
opt = int(sys.argv[-1])
b1 = np.asarray([-2.1, -1, -0.3, 1, 1.6, 2]).astype('float32') / 5
if opt == 0:
    dnn = sknet.network.Network(name='simple_model')
Example #4
0
# Data Loading
#-------------
dataset = sknet.dataset.load_cifar10()

dataset['images/train_set'] -= dataset['images/train_set'].mean((1, 2, 3),
                                                                keepdims=True)
dataset['images/train_set'] /= dataset['images/train_set'].max((1, 2, 3),
                                                               keepdims=True)
dataset['images/test_set'] -= dataset['images/test_set'].mean((1, 2, 3),
                                                              keepdims=True)
dataset['images/test_set'] /= dataset['images/test_set'].max((1, 2, 3),
                                                             keepdims=True)

iterator = BatchIterator(64, {
    'train_set': 'random_see_all',
    'test_set': 'continuous'
})

dataset.create_placeholders(iterator, device="/cpu:0")

# Create Network
#---------------

# we use a batch_size of 64 and use the dataset.datum shape to
# obtain the shape of 1 observation and create the input shape

dnn = sknet.Network(name='simple_model')

dnn.append(ops.RandomAxisReverse(dataset.images, axis=[-1]))
dnn.append(ops.RandomCrop(dnn[-1], (28, 28)))
Example #5
0
elif DATASET=='svhn':
    dataset = sknet.dataset.load_svhn()

if "valid_set" not in dataset.sets:
    dataset.split_set("train_set","valid_set",0.15)

#standardize = sknet.dataset.Standardize().fit(dataset['images/train_set'])
#dataset['images/train_set'] = \
#                        standardize.transform(dataset['images/train_set'])
#dataset['images/test_set'] = \
#                        standardize.transform(dataset['images/test_set'])
#dataset['images/valid_set'] = \
#                        standardize.transform(dataset['images/valid_set'])

dataset.create_placeholders(batch_size=32,
        iterators_dict={'train_set':BatchIterator("random_see_all"),
                        'valid_set':BatchIterator('continuous'),
                        'test_set':BatchIterator('continuous')},device="/cpu:0")

# Create Network
#---------------

dnn       = sknet.Network(name='simple_model')

if DATA_AUGMENTATION:
    dnn.append(ops.RandomAxisReverse(dataset.images,axis=[-1]))
    dnn.append(ops.RandomCrop(dnn[-1],(28,28),seed=10))
else:
    dnn.append(dataset.images)

if MODEL=='cnn':