Coverage for hypergan/ops/tensorflow/activations.py : 27%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
# http://stackoverflow.com/questions/39975676/how-to-implement-prelu-activation-in-tensorflow name = (prefix+"prelu_"+str(i)) orig_shape = _x.get_shape() _x = tf.reshape(_x, [config['batch_size'], -1])
#print("prelu for", _x.get_shape()[-1]) alphas = tf.get_variable(name, _x.get_shape()[-1], initializer=tf.random_normal_initializer(mean=0.0,stddev=0.01), dtype=tf.float32) pos = tf.nn.relu(_x) neg = alphas * (_x - abs(_x)) * 0.5
return tf.reshape(pos + neg, orig_shape)
return tf.concat(axis=len(x.get_shape()) - 1, values=[tf.sin(x), tf.cos(x)])
shape = [int(e) for e in x.get_shape()] ax = len(shape) ch = shape[-1] assert ch % k == 0 shape[-1] = ch // k shape.append(k) x = tf.reshape(x, shape) return tf.reduce_max(x, ax)
shape = [int(e) for e in x.get_shape()] ax = len(shape) ch = shape[-1] assert ch % k == 0 shape[-1] = ch // k shape.append(k) x = tf.reshape(x, shape) ofs = rng.randn(1000, k).max(axis=1).mean() return tf.reduce_max(x, ax) - ofs
""" Concatenates lrelu and square """ dim = len(x.get_shape()) - 1 return tf.concat(axis=dim, values=[lrelu(x), tf.minimum(tf.abs(x), tf.square(x))])
with tf.variable_scope(name): scale = tf.get_variable("scale", [1], initializer=tf.constant_initializer(1.,dtype=config['dtype']),dtype=config['dtype']) decay_scale = tf.get_variable("decay_scale", [1], initializer=tf.constant_initializer(1.,dtype=config['dtype']),dtype=config['dtype']) relu = tf.nn.relu(x) return scale * relu / (1. + tf.abs(decay_scale) * tf.square(decay_scale))
with tf.variable_scope(name): scale = tf.get_variable("scale", [int(x.get_shape()[-1])], initializer=tf.constant_initializer(1.,dtype=config['dtype']),dtype=config['dtype']) decay_scale = tf.get_variable("decay_scale", [int(x.get_shape()[-1])], initializer=tf.constant_initializer(1.,dtype=config['dtype']), dtype=config['dtype']) relu = tf.nn.relu(x) return scale * relu / (1. + tf.abs(decay_scale) * tf.square(decay_scale))
shape = [int(e) for e in x.get_shape()] prefix = [0] * (len(shape) - 1) most = shape[:-1] assert shape[-1] % 2 == 0 half = shape[-1] // 2 first_half = tf.slice(x, prefix + [0], most + [half]) second_half = tf.slice(x, prefix + [half], most + [half]) return tf.nn.relu(first_half) * tf.nn.sigmoid(second_half)
# Helper function with main phase shift operation bsize, a, b, c = I.get_shape().as_list() X = tf.reshape(I, (bsize, a, b, r, r)) X = tf.transpose(X, (0, 1, 2, 4, 3)) # bsize, a, b, 1, 1 X = tf.split(axis=1, num_or_size_splits=a, value=X) # a, [bsize, b, r, r] X = tf.concat(axis=2, values=[tf.squeeze(x) for x in X]) # bsize, b, a*r, r X = tf.split(axis=1, num_or_size_splits=b, value=X) # b, [bsize, a*r, r] X = tf.concat(axis=2, values=[tf.squeeze(x) for x in X]) # bsize, a*r, b*r return tf.reshape(X, (bsize, a*r, b*r, 1))
# Main OP that you can arbitrarily use in you tensorflow code if color: Xc = tf.split(axis=3, num_or_size_splits=3, value=X) X = tf.concat(axis=3, values=[_phase_shift(x, r) for x in Xc]) else: X = _phase_shift(X, r) return X
net = tf.minimum(net, 1) net = tf.maximum(net, -1) return net
net = tf.minimum(net, 1) net = tf.maximum(net, 0) return net |