Beispiel #1
0
    def _declare_variables(self):

        with tf.variable_scope('vfeedbacknet_{}'.format(Model.model_name)):

            with tf.variable_scope('feedbackcell1'):
                self.feedbackLSTMCell1 = FeedbackLSTMCell_stack1(
                    [14, 14, 128], Model.NFEEDBACK)

            with tf.variable_scope('convlstm1'):
                with tf.variable_scope('rnn'):
                    with tf.variable_scope('conv_lstm_cell'):

                        regularizer = None  # tf.contrib.layers.l2_regularizer(scale=0.25)
                        initializer = tf.contrib.layers.xavier_initializer()

                        n = 128
                        m = 4 * n
                        input_size = [7, 7, n]
                        kernel2d_size = [3, 3]
                        kernel_size = kernel2d_size + [2 * n] + [m]

                        with tf.variable_scope('convlstm'):
                            kernel = tf.get_variable('kernel',
                                                     kernel_size,
                                                     initializer=initializer,
                                                     regularizer=regularizer)
                            W_ci = tf.get_variable('W_ci',
                                                   input_size,
                                                   initializer=initializer,
                                                   regularizer=regularizer)
                            W_cf = tf.get_variable('W_cf',
                                                   input_size,
                                                   initializer=initializer,
                                                   regularizer=regularizer)
                            W_co = tf.get_variable('W_co',
                                                   input_size,
                                                   initializer=initializer,
                                                   regularizer=regularizer)
                            bias = tf.get_variable(
                                'bias', [m],
                                initializer=tf.zeros_initializer(),
                                regularizer=regularizer)

                self.convLSTMCell1 = ConvLSTMCell(input_size[:2], n, [3, 3])

            with tf.variable_scope('reshape_convs'):
                with tf.variable_scope('conv1'):

                    regularizer = None  # tf.contrib.layers.l2_regularizer(scale=0.25)
                    initializer = tf.contrib.layers.xavier_initializer()

                    kernel = tf.get_variable('kernel',
                                             shape=[7, 7, 3, 32],
                                             dtype=tf.float32,
                                             regularizer=regularizer,
                                             initializer=initializer)
                    biases = tf.get_variable('biases',
                                             shape=[32],
                                             dtype=tf.float32,
                                             regularizer=regularizer,
                                             initializer=initializer)

                with tf.variable_scope('conv2'):

                    regularizer = None  # tf.contrib.layers.l2_regularizer(scale=0.25)
                    initializer = tf.contrib.layers.xavier_initializer()

                    kernel = tf.get_variable('kernel',
                                             shape=[3, 3, 32, 64],
                                             dtype=tf.float32,
                                             regularizer=regularizer,
                                             initializer=initializer)
                    biases = tf.get_variable('biases',
                                             shape=[64],
                                             dtype=tf.float32,
                                             regularizer=regularizer,
                                             initializer=initializer)

                with tf.variable_scope('conv3'):

                    regularizer = None  # tf.contrib.layers.l2_regularizer(scale=0.25)
                    initializer = tf.contrib.layers.xavier_initializer()

                    kernel = tf.get_variable('kernel',
                                             shape=[3, 3, 64, 128],
                                             dtype=tf.float32,
                                             regularizer=regularizer,
                                             initializer=initializer)
                    biases = tf.get_variable('biases',
                                             shape=[128],
                                             dtype=tf.float32,
                                             regularizer=regularizer,
                                             initializer=initializer)

                # with tf.variable_scope('conv4'):

                #     regularizer = None # tf.contrib.layers.l2_regularizer(scale=0.25)
                #     initializer = tf.contrib.layers.xavier_initializer()

                #     kernel = tf.get_variable('kernel', shape=[3, 3, 512, 1024], dtype=tf.float32, regularizer=regularizer, initializer=initializer)
                #     biases = tf.get_variable('biases', shape=[1024], dtype=tf.float32, regularizer=regularizer, initializer=initializer)

                # with tf.variable_scope('conv5'):

                #     regularizer = None # tf.contrib.layers.l2_regularizer(scale=0.25)
                #     initializer = tf.contrib.layers.xavier_initializer()

                #     kernel = tf.get_variable('kernel', shape=[3, 3, 128, 256], dtype=tf.float32, regularizer=regularizer, initializer=initializer)
                #     biases = tf.get_variable('biases', shape=[256], dtype=tf.float32, regularizer=regularizer, initializer=initializer)

            with tf.variable_scope('fc1'):

                regularizer = None  # tf.contrib.layers.l2_regularizer(scale=0.25)
                initializer = tf.contrib.layers.xavier_initializer()

                trainable = False if self.train_fc == 'NO' else True

                weight = tf.get_variable('weights',
                                         shape=[128, 128],
                                         dtype=tf.float32,
                                         initializer=initializer,
                                         regularizer=regularizer,
                                         trainable=trainable)
                biases = tf.get_variable('biases',
                                         shape=[128],
                                         dtype=tf.float32,
                                         initializer=initializer,
                                         regularizer=regularizer,
                                         trainable=trainable)

            with tf.variable_scope('fc2'):

                regularizer = None  # tf.contrib.layers.l2_regularizer(scale=0.25)
                initializer = tf.contrib.layers.xavier_initializer()

                trainable = False if self.train_fc == 'NO' else True

                weight = tf.get_variable('weights',
                                         shape=[128, self.num_classes],
                                         dtype=tf.float32,
                                         initializer=initializer,
                                         regularizer=regularizer,
                                         trainable=trainable)
                biases = tf.get_variable('biases',
                                         shape=[self.num_classes],
                                         dtype=tf.float32,
                                         initializer=initializer,
                                         regularizer=regularizer,
                                         trainable=trainable)
    def _declare_variables(self):

        with tf.variable_scope('vfeedbacknet_model1'):

            with tf.variable_scope('feedbackcell1'):
                self.feedbackLSTMCell1 = FeedbackLSTMCell_stack1(
                    [4, 4, 512], Model.NFEEDBACK)

            with tf.variable_scope('convlstm1'):
                with tf.variable_scope('rnn'):
                    with tf.variable_scope('conv_lstm_cell'):

                        regularizer = None  # tf.contrib.layers.l2_regularizer(scale=0.25)
                        initializer = tf.contrib.layers.xavier_initializer()

                        n = 512
                        m = 4 * n
                        input_size = [4, 4, n]
                        kernel2d_size = [3, 3]
                        kernel_size = kernel2d_size + [2 * n] + [m]

                        with tf.variable_scope('convlstm'):
                            kernel = tf.get_variable('kernel',
                                                     kernel_size,
                                                     initializer=initializer,
                                                     regularizer=regularizer)
                            W_ci = tf.get_variable('W_ci',
                                                   input_size,
                                                   initializer=initializer,
                                                   regularizer=regularizer)
                            W_cf = tf.get_variable('W_cf',
                                                   input_size,
                                                   initializer=initializer,
                                                   regularizer=regularizer)
                            W_co = tf.get_variable('W_co',
                                                   input_size,
                                                   initializer=initializer,
                                                   regularizer=regularizer)
                            bias = tf.get_variable(
                                'bias', [m],
                                initializer=tf.zeros_initializer(),
                                regularizer=regularizer)

                self.convLSTMCell1 = ConvLSTMCell([4, 4], 512, [3, 3])

            with tf.variable_scope('convlstm2'):
                with tf.variable_scope('rnn'):
                    with tf.variable_scope('conv_lstm_cell'):

                        regularizer = None  # tf.contrib.layers.l2_regularizer(scale=0.25)
                        initializer = tf.contrib.layers.xavier_initializer()

                        n = 512
                        m = 4 * n
                        input_size = [4, 4, n]
                        kernel2d_size = [3, 3]
                        kernel_size = kernel2d_size + [2 * n] + [m]

                        with tf.variable_scope('convlstm'):
                            kernel = tf.get_variable('kernel',
                                                     kernel_size,
                                                     initializer=initializer,
                                                     regularizer=regularizer)
                            W_ci = tf.get_variable('W_ci',
                                                   input_size,
                                                   initializer=initializer,
                                                   regularizer=regularizer)
                            W_cf = tf.get_variable('W_cf',
                                                   input_size,
                                                   initializer=initializer,
                                                   regularizer=regularizer)
                            W_co = tf.get_variable('W_co',
                                                   input_size,
                                                   initializer=initializer,
                                                   regularizer=regularizer)
                            bias = tf.get_variable(
                                'bias', [m],
                                initializer=tf.zeros_initializer(),
                                regularizer=regularizer)

                self.convLSTMCell2 = ConvLSTMCell([4, 4], 512, [3, 3])