def build_FF_controller(self, input_, output_list_prev, hidden_list_prev, scope="content"): """Build Feedforward controller.""" with tf.variable_scope("controller_" + scope): output_list = [] hidden_list = [] for layer_idx in range(self.ctl_layer_size): if layer_idx == 0: z = Linear(input_, self.ctl_hidden_size, stddev=self.init_range, name="ff_%s" % layer_idx) else: z = Linear(output_list[-1], self.ctl_hidden_size, stddev=self.init_range, name="ff_%s" % layer_idx) out = tf.nn.tanh(z) hidden_list.append(out) output_list.append(out) return output_list, hidden_list
def init_state(self, dummy_value=0.0): dummy = tf.Variable(tf.constant([[dummy_value]], dtype=tf.float32)) M = [tf.zeros(shape) for shape in self.M_shapes] R = tf.zeros([1, self.G_shape[0] * self.G_shape[1]]) val = tf.zeros([1, sum(self.read_sizes)]) # controller state output_init_list = [] hidden_init_list = [] for idx in range(self.ctl_layer_size): output_init_idx = Linear(dummy, self.ctl_hidden_size, squeeze=True, stddev=self.init_range, name='output_init_%s' % idx) output_init_list.append(tf.tanh(output_init_idx)) hidden_init_idx = Linear(dummy, self.ctl_hidden_size, squeeze=True, stddev=self.init_range, name='hidden_init_%s' % idx) hidden_init_list.append(tf.tanh(hidden_init_idx)) state = { 'M': M, 'R': R, 'val': val, 'ptr': tf.zeros([1, self.ptr_size]), #weight('ptr_init', [1, self.ptr_size], init='constant'), 'dptr': tf.zeros([1, self.ptr_size]), 'seq_length': 0, 'output': output_init_list, 'hidden': hidden_init_list, } self.__call__(state,0) return state
def build_RNN_controller(self, input_, output_list_prev, hidden_list_prev, scope="content"): """Build RNN controller.""" with tf.variable_scope("controller_" + scope): output_list = [] hidden_list = [] for layer_idx in range(self.ctl_layer_size): o_prev = output_list_prev[layer_idx] h_prev = hidden_list_prev[layer_idx] if layer_idx == 0: hid = tf.nn.tanh(linear([input_, o_prev], output_size = self.ctl_hidden_size, bias = True, stddev=self.init_range, scope = "f1_%s" % (layer_idx))) else: hid = tf.nn.tanh(linear([output_list[-1], o_prev], output_size = self.ctl_hidden_size, bias = True, stddev=self.init_range, scope="f1_%s" % (layer_idx))) out = tf.nn.tanh(Linear(hid, self.ctl_hidden_size, stddev=self.init_range, name="f2_%s" % (layer_idx))) hidden_list.append(out) output_list.append(out) return output_list, hidden_list
def MobileNet(x, is_training=True): with tf.variable_scope('mobilenet'): x = Conv3x3(x, 3, 32, 2, is_training, 'conv1') # 224 -> 112 x = Separable(x, 32, 64, 1, is_training, 'sepa1') x = Separable(x, 64, 128, 2, is_training, 'sepa2') # 112 -> 56 x = Separable(x, 128, 128, 1, is_training, 'sepa3_1') x = Separable(x, 128, 256, 2, is_training, 'sepa3_2') # 56 -> 28 x = Separable(x, 256, 256, 1, is_training, 'sepa4_1') x = Separable(x, 256, 512, 2, is_training, 'sepa4_2') # 28 -> 14 for i in range(5): x = Separable(x, 512, 512, 1, is_training, 'sepa5_{}'.format(i + 1)) x = Separable(x, 512, 1024, 2, is_training, 'sepa5_6') # 14 -> 7 x = Separable(x, 1024, 1024, 1, is_training, 'sepa6') x = AvgPool7x7(x) x = Linear(x, 1024, 1000) return x