nn/pspnet.py
def make_optimizer(self, train_var_filter):
        """
        Make optimizer fot the network, Adam is used
        :param train_var_filter: if not None, only optimize variables in train_var_filter
        :return:
        """
        # According from the prototxt in Caffe implement, learning rate must multiply by 10.0 in pyramid module
        fc_list = ['conv5_3_pool1_conv', 'conv5_3_pool2_conv', 'conv5_3_pool3_conv', 'conv5_3_pool6_conv', 'conv6',
                   'conv5_4']
        all_trainable = [v for v in tf.trainable_variables() if
                         ('beta' not in v.name and 'gamma' not in v.name) or True]
        fc_trainable = [v for v in all_trainable if v.name.split('/')[0] in fc_list]
        conv_trainable = [v for v in all_trainable if v.name.split('/')[0] not in fc_list]  # lr * 1.0
        fc_w_trainable = [v for v in fc_trainable if 'weights' in v.name]  # lr * 10.0
        fc_b_trainable = [v for v in fc_trainable if 'biases' in v.name]  # lr * 20.0
        assert (len(all_trainable) == len(fc_trainable) + len(conv_trainable))
        assert (len(fc_trainable) == len(fc_w_trainable) + len(fc_b_trainable))

        with tf.control_dependencies(self.update_ops):
            opt_conv = tf.train.MomentumOptimizer(self.lr_op, self.momentum)
            opt_fc_w = tf.train.MomentumOptimizer(self.lr_op * 10.0, self.momentum)
            opt_fc_b = tf.train.MomentumOptimizer(self.lr_op * 20.0, self.momentum)

            grads = tf.gradients(self.loss, conv_trainable + fc_w_trainable + fc_b_trainable)
            grads_conv = grads[:len(conv_trainable)]
            grads_fc_w = grads[len(conv_trainable): (len(conv_trainable) + len(fc_w_trainable))]
            grads_fc_b = grads[(len(conv_trainable) + len(fc_w_trainable)):]

            train_op_conv = opt_conv.apply_gradients(zip(grads_conv, conv_trainable), global_step=self.global_step)
            train_op_fc_w = opt_fc_w.apply_gradients(zip(grads_fc_w, fc_w_trainable))
            train_op_fc_b = opt_fc_b.apply_gradients(zip(grads_fc_b, fc_b_trainable))

            self.optimizer = tf.group(train_op_conv, train_op_fc_w, train_op_fc_b)

        Make optimizer fot the network, Adam is used
        :param train_var_filter: if not None, only optimize variables in train_var_filter
        :return:
        
Make optimizer fot the network, Adam is used
Make optimizer fot the network Adam is used
def make_optimizer(self, train_var_filter):
        fc_list = ['conv5_3_pool1_conv', 'conv5_3_pool2_conv', 'conv5_3_pool3_conv', 'conv5_3_pool6_conv', 'conv6',
                   'conv5_4']
        all_trainable = [v for v in tf.trainable_variables() if
                         ('beta' not in v.name and 'gamma' not in v.name) or True]
        fc_trainable = [v for v in all_trainable if v.name.split('/')[0] in fc_list]
        conv_trainable = [v for v in all_trainable if v.name.split('/')[0] not in fc_list]  
        fc_w_trainable = [v for v in fc_trainable if 'weights' in v.name]  
        fc_b_trainable = [v for v in fc_trainable if 'biases' in v.name]  
        assert (len(all_trainable) == len(fc_trainable) + len(conv_trainable))
        assert (len(fc_trainable) == len(fc_w_trainable) + len(fc_b_trainable))
        with tf.control_dependencies(self.update_ops):
            opt_conv = tf.train.MomentumOptimizer(self.lr_op, self.momentum)
            opt_fc_w = tf.train.MomentumOptimizer(self.lr_op * 10.0, self.momentum)
            opt_fc_b = tf.train.MomentumOptimizer(self.lr_op * 20.0, self.momentum)
            grads = tf.gradients(self.loss, conv_trainable + fc_w_trainable + fc_b_trainable)
            grads_conv = grads[:len(conv_trainable)]
            grads_fc_w = grads[len(conv_trainable): (len(conv_trainable) + len(fc_w_trainable))]
            grads_fc_b = grads[(len(conv_trainable) + len(fc_w_trainable)):]
            train_op_conv = opt_conv.apply_gradients(zip(grads_conv, conv_trainable), global_step=self.global_step)
            train_op_fc_w = opt_fc_w.apply_gradients(zip(grads_fc_w, fc_w_trainable))
            train_op_fc_b = opt_fc_b.apply_gradients(zip(grads_fc_b, fc_b_trainable))
            self.optimizer = tf.group(train_op_conv, train_op_fc_w, train_op_fc_b)
def make_optimizer ( self , train_var_filter ) : fc_list = [ 'conv5_3_pool1_conv' , 'conv5_3_pool2_conv' , 'conv5_3_pool3_conv' , 'conv5_3_pool6_conv' , 'conv6' , 'conv5_4' ] all_trainable = [ v for v in tf . trainable_variables ( ) if ( 'beta' not in v . name and 'gamma' not in v . name ) or True ] fc_trainable = [ v for v in all_trainable if v . name . split ( '/' ) [ 0 ] in fc_list ] conv_trainable = [ v for v in all_trainable if v . name . split ( '/' ) [ 0 ] not in fc_list ] fc_w_trainable = [ v for v in fc_trainable if 'weights' in v . name ] fc_b_trainable = [ v for v in fc_trainable if 'biases' in v . name ] assert ( len ( all_trainable ) == len ( fc_trainable ) + len ( conv_trainable ) ) assert ( len ( fc_trainable ) == len ( fc_w_trainable ) + len ( fc_b_trainable ) ) with tf . control_dependencies ( self . update_ops ) : opt_conv = tf . train . MomentumOptimizer ( self . lr_op , self . momentum ) opt_fc_w = tf . train . MomentumOptimizer ( self . lr_op * 10.0 , self . momentum ) opt_fc_b = tf . train . MomentumOptimizer ( self . lr_op * 20.0 , self . momentum ) grads = tf . gradients ( self . loss , conv_trainable + fc_w_trainable + fc_b_trainable ) grads_conv = grads [ : len ( conv_trainable ) ] grads_fc_w = grads [ len ( conv_trainable ) : ( len ( conv_trainable ) + len ( fc_w_trainable ) ) ] grads_fc_b = grads [ ( len ( conv_trainable ) + len ( fc_w_trainable ) ) : ] train_op_conv = opt_conv . apply_gradients ( zip ( grads_conv , conv_trainable ) , global_step = self . global_step ) train_op_fc_w = opt_fc_w . apply_gradients ( zip ( grads_fc_w , fc_w_trainable ) ) train_op_fc_b = opt_fc_b . apply_gradients ( zip ( grads_fc_b , fc_b_trainable ) ) self . optimizer = tf . group ( train_op_conv , train_op_fc_w , train_op_fc_b )
Make optimizer fot the network, Adam is used
Make optimizer fot the network Adam is used
"""
        Make optimizer fot the network, Adam is used
        :param train_var_filter: if not None, only optimize variables in train_var_filter
        :return:
        """ # According from the prototxt in Caffe implement, learning rate must multiply by 10.0 in pyramid module # lr * 1.0 # lr * 10.0 # lr * 20.0
None
self
train_var_filter
if not None, only optimize variables in train_var_filter
if not None only optimize variables in train_var_filter