Skip to content

Instantly share code, notes, and snippets.

@shugert
Created July 17, 2017 19:22
Show Gist options
  • Save shugert/91d931267e8c3906ee7bc85303b2eeea to your computer and use it in GitHub Desktop.
Save shugert/91d931267e8c3906ee7bc85303b2eeea to your computer and use it in GitHub Desktop.
# fully-conected layer
def dense(x, inputFeatures, outputFeatures, scope=None, with_w=False):
with tf.variable_scope(scope or "Linear"):
matrix = tf.get_variable("Matrix", [inputFeatures, outputFeatures], tf.float32, tf.random_normal_initializer(stddev=0.02))
bias = tf.get_variable("bias", [outputFeatures], initializer=tf.constant_initializer(0.0))
if with_w:
return tf.matmul(x, matrix) + bias, matrix, bias
else:
return tf.matmul(x, matrix) + bias
# merge images
def merge(images, size):
h, w = images.shape[1], images.shape[2]
img = np.zeros((h * size[0], w * size[1]))
for idx, image in enumerate(images):
i = idx % size[1]
j = idx / size[1]
img[j*h:j*h+h, i*w:i*w+w] = image
return img
# save image on local machine
def ims(name, img):
# print img[:10][:10]
scipy.misc.toimage(img, cmin=0, cmax=1).save(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment