Created
January 12, 2017 13:38
-
-
Save sjchoi86/0d2b73992efa194ff1bc7c7f10211348 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import tensorflow as tf | |
import tensorflow.contrib.slim as slim | |
def mapping(feat, is_training=True, reuse=False): | |
batch_norm_params = {'is_training': is_training, 'decay': 0.9, 'updates_collections': None} | |
with tf.variable_scope("mapping") as scope: | |
if reuse: | |
scope.reuse_variables() | |
net = slim.fully_connected(feat, 16 | |
, activation_fn = tf.nn.sigmoid | |
, weights_initializer = tf.truncated_normal_initializer(stddev=0.01) | |
, normalizer_fn = slim.batch_norm | |
, normalizer_params = batch_norm_params | |
, scope='m_fc1') | |
net = slim.dropout(net, keep_prob=0.7, is_training=is_training, scope='m_dr') | |
out = slim.fully_connected(net, 2 | |
, activation_fn = None | |
, normalizer_fn = None | |
, scope='m_fc2') | |
return out | |
feat1 = tf.placeholder(tf.float32, [None, 6]) | |
feat2 = tf.placeholder(tf.float32, [None, 6]) | |
is_train = tf.placeholder(tf.bool) | |
map1 = mapping(feat1, is_train, False) | |
map2 = mapping(feat2, is_train, True) | |
# INIT | |
init = tf.global_variables_initializer() | |
sess = tf.Session() | |
sess.run(init) | |
# CHECK | |
feat = np.random.rand(2, 6) | |
feeds = {feat1: feat, feat2: feat, is_train: True} | |
m1val = sess.run(map1, feed_dict=feeds) | |
m2val = sess.run(map2, feed_dict=feeds) | |
print (m1val) | |
print (m2val) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[[ 0.37606525 -0.41489923]
[-0.07807794 -0.81576711]]
[[-0.69362152 -0.15968615]
[-0.56324488 -0.42829311]]