def __init__(self, action_count): with tf.name_scope('theta') as scope: self.s = tf.placeholder(tf.float32, shape=(None, 84, 84, config.M), name='s') conv1 = tf_util.conv2d('conv1', self.s / 256, [8, 8], 32, 4, tf.nn.relu) conv2 = tf_util.conv2d('conv2', conv1, [4, 4], 64, 2, tf.nn.relu) conv3 = tf_util.conv2d('conv3', conv2, [3, 3], 64, 1, tf.nn.relu) flattened = tf.reshape(conv3, [-1, 11 * 11 * 64]) hidden = tf_util.linear('hidden', flattened, 512, tf.nn.relu) self.V = tf_util.linear('V', hidden, 1) self.pi = tf_util.softmax('pi', hidden, action_count) self.variables = tf.trainable_variables(scope=scope) self.eval_summary_op = tf.summary.merge( tf.get_collection(tf_util.SummaryKeys.EVAL_SUMMARIES, scope=scope)) self.variable_summary_op = tf.summary.merge( tf.get_collection(tf_util.SummaryKeys.VARIABLE_SUMMARIES, scope=scope))
def set_model(self, inputs, is_training=True, reuse=False): h = inputs # fully connect with tf.variable_scope(self.name_scopes[0], reuse=reuse): last_idx = len(self.layer_channels) - 1 for i, s in enumerate(self.layer_channels): if i != last_idx: lin = linear(i, h, s) else: lin = linear(i, h, s, 0.0) h = lrelu(lin) return lin
def set_model(self, z, batch_size, is_training=True, reuse=False): # reshape z with tf.variable_scope(self.name_scopes[0], reuse=reuse): out_dim = self.in_dim * self.in_dim * self.layer_chanels[0] h = linear('_r', z, out_dim) h = batch_norm('reshape', h, decay_rate=0.99, is_training=is_training) h = tf.nn.relu(h) h = tf.reshape(h, [-1, self.in_dim, self.in_dim, self.layer_chanels[0]]) # deconvolution with tf.variable_scope(self.name_scopes[1], reuse=reuse): for i, out_chan in enumerate(self.layer_chanels[1:]): # get out shape h_shape = h.get_shape().as_list() out_width = 2 * h_shape[2] out_height = 2 * h_shape[1] out_shape = [batch_size, out_height, out_width, out_chan] # deconvolution deconved = deconv(i, h, out_shape, 5, 5, 2) # batch normalization bn_deconved = batch_norm(i, deconved, 0.99, is_training) # activation h = tf.nn.relu(bn_deconved) return tf.nn.tanh(deconved)
def set_model(self, input_figs, z, batch_size, is_training = True, reuse = False): assert(self.en_channels[0] == input_figs.get_shape().as_list()[3]) # reshape z with tf.variable_scope(self.name_scopes[0], reuse = reuse): h = linear('_r', z, get_dim(input_figs)) h = batch_norm('reshape', h, decay_rate= 0.99, is_training = is_training) h = tf.nn.relu(h) height = input_figs.get_shape().as_list()[1] width = input_figs.get_shape().as_list()[2] h = tf.reshape(h, [-1, height, width, self.en_channels[0]]) h = tf.concat([h, input_figs], 3) # convolution encoded_list = [] # encode with tf.variable_scope(self.name_scopes[1], reuse = reuse): for i, out_dim in enumerate(self.en_channels[1:]): h = conv(i, h, out_dim, 4, 4, 2) if i == 0: encoded_list.append(h) h = lrelu(h) else: h = batch_norm(i, h, 0.99, is_training) encoded_list.append(h) h = lrelu(h) # deconvolution encoded_list.pop() h = tf.nn.relu(h) with tf.variable_scope(self.name_scopes[2], reuse = reuse): for i, out_chan in enumerate(self.dec_channels[:-1]): # get out shape h_shape = h.get_shape().as_list() out_width = 2 * h_shape[2] out_height = 2 * h_shape[1] out_shape = [batch_size, out_height, out_width, out_chan] # deconvolution deconved = deconv(i, h, out_shape, 4, 4, 2) # batch normalization h = batch_norm(i, deconved, 0.99, is_training) if i <= 2: h = tf.nn.dropout(h, 0.5) h = tf.concat([h, encoded_list.pop()], 3) # activation h = tf.nn.relu(h) height = 2 * h.get_shape().as_list()[1] width = 2 * h.get_shape().as_list()[1] out_shape = [batch_size, height, width, self.dec_channels[-1]] h = deconv(i + 1, h, out_shape, 4, 4, 2) return tf.nn.tanh(h)
def set_model(self, z, is_training=True, reuse=False): h = z # deconvolution with tf.variable_scope(self.name_scopes[0], reuse=reuse): for i, out_chan in enumerate(self.layer_chanels[1:]): lin = linear(i, h, out_chan) h = tf.nn.relu(lin) return lin
def set_model(self, inputs, is_training=True, reuse=False): h = inputs # fully connect with tf.variable_scope(self.name_scopes[0], reuse=reuse): for i, s in enumerate(self.layer_channels): lin = linear(i, h, s, stddev=0.001) h = lrelu(lin) #h = tf.tanh(lin) return lin
def set_model(self, input_img, is_training = True, reuse = False): assert(self.layer_channels[0] == input_img.get_shape().as_list()[-1]) h = input_img # convolution with tf.variable_scope(self.name_scopes[0], reuse = reuse): for i, out_chan in enumerate(self.layer_channels[1:]): h = conv(i, h, out_chan, 5, 5, 2) h = lrelu(h) # fully connect h = flatten(h) with tf.variable_scope(self.name_scopes[1], reuse = reuse): h = linear('disc_fc', h, 1) return h
def set_model(self, inputs, batch_size, is_training = True, reuse = False): assert(self.layer_channels[0] == inputs.get_shape().as_list()[-1]) h = inputs # convolution with tf.variable_scope(self.name_scopes[0], reuse = reuse): for i, out_chan in enumerate(self.layer_channels[1:]): # convolution conved = conv(i, h, out_chan, 5, 5, 2) # batch normalization bn_conved = batch_norm(i, conved, 0.99, is_training) # activation h = lrelu(bn_conved) # fully connect with tf.variable_scope(self.name_scopes[1], reuse = reuse): encoded = linear('fc', flatten(h), self.out_dim) return encoded