model.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:woipv 作者: Panaetius 项目源码 文件源码
def inference(self, inputs):
        # resnet
        with tf.variable_scope('first_layer'):
            kernel = tf.get_variable('weights', [7, 7, 3, 64],
                                     initializer=xavier_initializer(
                                         dtype=tf.float32),
                                     dtype=tf.float32)
            conv = tf.nn.conv2d(inputs, kernel, [1, 2, 2, 1],
                                padding='SAME',
                                name='conv')
            batch_norm = self.__batch_norm_wrapper(conv, shape=[0, 1, 2, 3])
            conv = tf.nn.elu(batch_norm, 'elu')

            grid = self.__put_kernels_on_grid(kernel, (8, 8))
            tf.summary.image('conv1/features', grid, max_outputs=1)
            grid = self.__put_activations_on_grid(conv, (8, 8))
            tf.summary.image('conv1/activations', grid, max_outputs=1)

            inputs = tf.nn.max_pool(conv, ksize=[1, 2, 2, 1],
                                    strides=[1, 2, 2, 1], padding='SAME',
                                    name='pool')

        if self.net == NetworkType.RESNET34:
            inputs = self.__resnet34(inputs)
        elif self.net == NetworkType.RESNET50:
            inputs = self.__resnet50(inputs)

        # classify regions and add final region adjustments
        with tf.variable_scope('fully_connected'):
            fc = tf.reduce_mean(inputs, [1, 2])
            class_weights = tf.get_variable('class_weights',
                                            [self.conv_feature_count,
                                             self.num_classes],
                                            initializer=xavier_initializer(
                                                dtype=tf.float32),
                                            dtype=tf.float32)
            class_bias = tf.get_variable("class_bias", [
                self.num_classes],
                initializer=tf.constant_initializer(
                0.1),
                dtype=tf.float32)

            class_score = tf.matmul(fc, class_weights)
            class_score = tf.nn.bias_add(class_score, class_bias)


        return class_score
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号