当前位置: 首页>>代码示例>>Python>>正文


Python models.regularize_cost方法代码示例

本文整理汇总了Python中tensorpack.models.regularize_cost方法的典型用法代码示例。如果您正苦于以下问题:Python models.regularize_cost方法的具体用法?Python models.regularize_cost怎么用?Python models.regularize_cost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorpack.models的用法示例。


在下文中一共展示了models.regularize_cost方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_graph

# 需要导入模块: from tensorpack import models [as 别名]
# 或者: from tensorpack.models import regularize_cost [as 别名]
def build_graph(self, image, label):
        image = ImageNetModel.image_preprocess(image, bgr=self.image_bgr)
        assert self.data_format in ['NCHW', 'NHWC']
        if self.data_format == 'NCHW':
            image = tf.transpose(image, [0, 3, 1, 2])

        logits = self.get_logits(image)
        print('self.label_smoothing', self.label_smoothing)
        loss = ImageNetModel.compute_loss_and_error(logits, label, self.label_smoothing)

        if self.weight_decay > 0:
            wd_loss = regularize_cost(self.weight_decay_pattern,
                                      tf.contrib.layers.l2_regularizer(self.weight_decay),
                                      name='l2_regularize_loss')
            add_moving_summary(loss, wd_loss)
            total_cost = tf.add_n([loss, wd_loss], name='cost')
        else:
            total_cost = tf.identity(loss, name='cost')
            add_moving_summary(total_cost)

        if self.loss_scale != 1.:
            logger.info("Scaling the total loss by {} ...".format(self.loss_scale))
            return total_cost * self.loss_scale
        else:
            return total_cost 
开发者ID:huawei-noah,项目名称:ghostnet,代码行数:27,代码来源:imagenet_utils.py

示例2: build_graph

# 需要导入模块: from tensorpack import models [as 别名]
# 或者: from tensorpack.models import regularize_cost [as 别名]
def build_graph(self, image, label):
        image = self.image_preprocess(image)
        assert self.data_format == 'NCHW'
        image = tf.transpose(image, [0, 3, 1, 2])

        logits = self.get_logits(image)
        loss = ImageNetModel.compute_loss_and_error(
            logits, label, label_smoothing=self.label_smoothing)

        if self.weight_decay > 0:
            wd_loss = regularize_cost(self.weight_decay_pattern,
                                      tf.contrib.layers.l2_regularizer(self.weight_decay),
                                      name='l2_regularize_loss')
            add_moving_summary(loss, wd_loss)
            total_cost = tf.add_n([loss, wd_loss], name='cost')
        else:
            total_cost = tf.identity(loss, name='cost')
            add_moving_summary(total_cost)

        if self.loss_scale != 1.:
            logger.info("Scaling the total loss by {} ...".format(self.loss_scale))
            return total_cost * self.loss_scale
        else:
            return total_cost 
开发者ID:tensorpack,项目名称:benchmarks,代码行数:26,代码来源:imagenet_utils.py

示例3: _build_graph

# 需要导入模块: from tensorpack import models [as 别名]
# 或者: from tensorpack.models import regularize_cost [as 别名]
def _build_graph(self, inputs):
        image, label = inputs
        image = ImageNetModel.image_preprocess(image, bgr=True)
        if self.data_format == 'NCHW':
            image = tf.transpose(image, [0, 3, 1, 2])

        logits = self.get_logits(image)
        loss = ImageNetModel.compute_loss_and_error(logits, label)

        if self.weight_decay > 0:
            wd_loss = regularize_cost('.*/W', tf.contrib.layers.l2_regularizer(self.weight_decay),
                                      name='l2_regularize_loss')
            add_moving_summary(loss, wd_loss)
            self.cost = tf.add_n([loss, wd_loss], name='cost')
        else:
            self.cost = tf.identity(loss, name='cost')
            add_moving_summary(self.cost) 
开发者ID:qinenergy,项目名称:webvision-2.0-benchmarks,代码行数:19,代码来源:imagenet_utils.py

示例4: build_graph

# 需要导入模块: from tensorpack import models [as 别名]
# 或者: from tensorpack.models import regularize_cost [as 别名]
def build_graph(self, image, label):
        image = self.image_preprocess(image)
        assert self.data_format in ['NCHW', 'NHWC']
        if self.data_format == 'NCHW':
            image = tf.transpose(image, [0, 3, 1, 2])

        logits = self.get_logits(image)
        loss = ImageNetModel.compute_loss_and_error(
            logits, label, label_smoothing=self.label_smoothing)

        if self.weight_decay > 0:
            wd_loss = regularize_cost(self.weight_decay_pattern,
                                      tf.contrib.layers.l2_regularizer(self.weight_decay),
                                      name='l2_regularize_loss')
            add_moving_summary(loss, wd_loss)
            total_cost = tf.add_n([loss, wd_loss], name='cost')
        else:
            total_cost = tf.identity(loss, name='cost')
            add_moving_summary(total_cost)

        if self.loss_scale != 1.:
            logger.info("Scaling the total loss by {} ...".format(self.loss_scale))
            return total_cost * self.loss_scale
        else:
            return total_cost 
开发者ID:ppwwyyxx,项目名称:GroupNorm-reproduce,代码行数:27,代码来源:imagenet_utils.py

示例5: build_graph

# 需要导入模块: from tensorpack import models [as 别名]
# 或者: from tensorpack.models import regularize_cost [as 别名]
def build_graph(self,
                    image,
                    label):

        image = self.image_preprocess(image)
        if is_channels_first(self.data_format):
            image = tf.transpose(image, [0, 3, 1, 2], name="image_transpose")

        # tf.summary.image('input_image_', image)
        # tf.summary.tensor_summary('input_tensor_', image)
        # with tf.name_scope('tmp1_summaries'):
        #     add_tensor_summary(image, ['histogram', 'rms', 'sparsity'], name='tmp1_tensor')

        is_training = get_current_tower_context().is_training
        logits = self.model_lambda(
            x=image,
            training=is_training)
        loss = ImageNetModel.compute_loss_and_error(
            logits=logits,
            label=label,
            label_smoothing=self.label_smoothing)

        if self.weight_decay > 0:
            wd_loss = regularize_cost(
                regex=self.weight_decay_pattern,
                func=tf.contrib.layers.l2_regularizer(self.weight_decay),
                name="l2_regularize_loss")
            add_moving_summary(loss, wd_loss)
            total_cost = tf.add_n([loss, wd_loss], name="cost")
        else:
            total_cost = tf.identity(loss, name="cost")
            add_moving_summary(total_cost)

        if self.loss_scale != 1.0:
            logger.info("Scaling the total loss by {} ...".format(self.loss_scale))
            return total_cost * self.loss_scale
        else:
            return total_cost 
开发者ID:osmr,项目名称:imgclsmob,代码行数:40,代码来源:utils_tp.py

示例6: _build_graph

# 需要导入模块: from tensorpack import models [as 别名]
# 或者: from tensorpack.models import regularize_cost [as 别名]
def _build_graph(self, inputs):
        image, label = inputs
        image = ImageNetModel.image_preprocess(image, bgr=self.image_bgr)
        if self.data_format == 'NCHW':
            image = tf.transpose(image, [0, 3, 1, 2])

        logits = self.get_logits(image)
        loss = ImageNetModel.compute_loss_and_error(logits, label)
        wd_loss = regularize_cost(self.weight_decay_pattern,
                                  tf.contrib.layers.l2_regularizer(self.weight_decay),
                                  name='l2_regularize_loss')
        add_moving_summary(loss, wd_loss)
        self.cost = tf.add_n([loss, wd_loss], name='cost') 
开发者ID:microsoft,项目名称:LQ-Nets,代码行数:15,代码来源:imagenet_utils.py

示例7: build_graph

# 需要导入模块: from tensorpack import models [as 别名]
# 或者: from tensorpack.models import regularize_cost [as 别名]
def build_graph(self, image, label):
        image = self.image_preprocess(image)
        assert self.data_format in ['NCHW', 'NHWC']
        if self.data_format == 'NCHW':
            image = tf.transpose(image, [0, 3, 1, 2])

        logits = self.get_logits(image)
        tf.nn.softmax(logits, name='prob')
        loss = ImageNetModel.compute_loss_and_error(
            logits, label, label_smoothing=self.label_smoothing)

        if self.weight_decay > 0:
            wd_loss = regularize_cost(self.weight_decay_pattern,
                                      l2_regularizer(self.weight_decay),
                                      name='l2_regularize_loss')
            add_moving_summary(loss, wd_loss)
            total_cost = tf.add_n([loss, wd_loss], name='cost')
        else:
            total_cost = tf.identity(loss, name='cost')
            add_moving_summary(total_cost)

        if self.loss_scale != 1.:
            logger.info("Scaling the total loss by {} ...".format(self.loss_scale))
            return total_cost * self.loss_scale
        else:
            return total_cost 
开发者ID:tensorpack,项目名称:tensorpack,代码行数:28,代码来源:imagenet_utils.py


注:本文中的tensorpack.models.regularize_cost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。