iterator = BatchIterator(10, { 'train_set': 'random_see_all', 'test_set': 'continous' }) 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 my_layer = layers.custom_layer(ops.Dense, ops.BatchNorm, ops.Activation) dnn = sknet.Network(name='model_base') dnn.append( ops.HermiteSplineConv1D(dataset.signals, J=5, Q=16, K=15, trainable_scales=False, trainable_knots=False, complex=False, trainable_filters=False, hilbert=False, init='gabor')) #dnn.append(ops.BatchNorm(dnn[-1],[0,2])) dnn.append(tf.abs(dnn[-1])) dnn.append(tf.expand_dims(dnn[-1], 1))
def get_distance_dense(input,tensor): def doit(c): gradient = tf.gradients(tensor[:,c],input)[0] norm = tf.sqrt(tf.reduce_sum(tf.square(gradient),[1,2,3])) return tf.abs(tensor[:,c])/norm distances = tf.map_fn(doit,tf.range(tensor.shape.as_list()[1]), dtype=tf.float32) return tf.reduce_min(distances,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)) start_op = 2 else: dnn.append(dataset.images) start_op = 1 if MODEL=='cnn': sknet.networks.ConvSmall(dnn,dataset.n_classes) elif MODEL=='dense': dnn.append(sknet.ops.Dense(dnn[-1],4096)) dnn.append(sknet.ops.BatchNorm(dnn[-1],0)) dnn.append(sknet.ops.Activation(dnn[-1],0.1))
# number of points for the grid N = 350 # grid TIME = np.linspace(-7, 7, N) X = np.meshgrid(TIME, TIME) X = np.stack([X[0].flatten(), X[1].flatten()], 1).astype('float32') # load the dataset dataset = sknet.Dataset() dataset['images/train_set'] = X dataset.create_placeholders(50, {'train_set': "continuous"}, device="/cpu:0") # Create Network #--------------- dnn = sknet.Network() np.random.seed(18 + int(RUN)) # first layer going from 2d to 9 units W = np.random.randn(2, 4).astype('float32') / np.sqrt(3) b = np.random.randn(4).astype('float32') / 3 dnn.append(ops.Dense(dataset.images, 4, W=W, b=b)) dnn.append(ops.Activation(dnn[-1], 0.05)) # following layers with same input and output dimension for i in range(1): W = np.random.randn(4, 4).astype('float32') / np.sqrt(3) b = np.random.randn(4).astype('float32') / 3 dnn.append(ops.Dense(dnn[-1], 4, W=W, b=b)) dnn.append(ops.Activation(dnn[-1], 0.05))