def reconstructor_tf(x, angles, reuse = True): with tf.variable_scope("Reconstructor", reuse = reuse): aco = tf.cos(angles*math.pi) asi = tf.sin(angles*math.pi) acosi = tf.stack((aco,asi),axis=-1) x = tf.concat((x, acosi), axis=1) x = tf.identity(x, name="input") NCAP = 128 NMAPS = 128 SMAP = 7 # size of map # we have different activations for different maps x = tf.layers.dense(x, 1024, activation=tf.nn.relu) cap_r = tf.layers.dense(x, NCAP * 2, activation=None) cap_r = tf.reshape(cap_r, (-1, NCAP, 2)) # [-1,1] - > [0,SMAP-1] (to index space) cap_r = (cap_r + 1) * (SMAP - 1) / 2.0 # all acap is positive because of sigmoid cap_a = tf.layers.dense(x, NCAP * NMAPS, activation=tf.nn.sigmoid) cap_a = tf.reshape(cap_a, (-1, NCAP, NMAPS)) x = caps.caps_tf(cap_r, cap_a, SMAP) x = tf.layers.conv2d_transpose(x, 64, 4, 2, padding='same', activation=tf.nn.relu) x = tf.layers.conv2d_transpose(x, 1, 4, 2, padding='same', activation=tf.nn.tanh) x = tf.identity(x, name="output") return x
def reconstructor_tf(x, angles, reuse=True): with tf.variable_scope("Reconstructor", reuse=reuse): aco = tf.cos(angles * math.pi) asi = tf.sin(angles * math.pi) acosi = tf.stack((aco, asi), axis=-1) x = tf.concat((x, acosi), axis=1) x = tf.identity(x, name="input") CAP_LEN = 10 NCAP = 20 NCATEGORICAL = 10 NMAPS = 32 SMAP = 7 # size of map x_categorical = tf.nn.softmax(x[:, :NCATEGORICAL]) x_pose = x[:, NCATEGORICAL:] x_firstcaps = tf.layers.dense(x_pose, CAP_LEN * NCATEGORICAL * NCAP) x_firstcaps = tf.reshape(x_firstcaps, (-1, NCAP, CAP_LEN, NCATEGORICAL)) x_firstcaps = tf.einsum('bcln,bn->bcl', x_firstcaps, x_categorical) cap_r = [] cap_a = [] for i in range(NCAP): x = x_firstcaps[:, i, :] x_r = tf.layers.dense(x, 128, activation=tf.nn.relu) x_r = tf.layers.dense(x_r, 2, activation=None) x_a = tf.layers.dense(x, 128, activation=tf.nn.relu) x_a = tf.layers.dense(x_a, NMAPS, activation=tf.nn.sigmoid) cap_r.append(x_r) cap_a.append(x_a) cap_r = tf.stack(cap_r, axis=1) cap_a = tf.stack(cap_a, axis=1) # [-1,1] - > [0,SMAP-1] (to index space) cap_r = (cap_r + 1) * (SMAP - 1) / 2.0 x = caps.caps_tf(cap_r, cap_a, SMAP) x = tf.layers.conv2d_transpose(x, 32, 4, 2, padding='same', activation=tf.nn.relu) x = tf.layers.conv2d_transpose(x, 1, 4, 2, padding='same', activation=tf.nn.tanh) x = tf.identity(x, name="output") return x