3 from __future__
import absolute_import
4 from __future__
import division
5 from __future__
import print_function
6 from __future__
import unicode_literals
8 from caffe2.python
import core, schema
9 from caffe2.python.layers.layers
import (
12 from caffe2.python.layers.tags
import (
20 def __init__(self, model, input_record, name='batch_lr_loss',
21 average_loss=True, **kwargs):
22 super(BatchLRLoss, self).__init__(model, name, input_record, **kwargs)
33 self.
tags.update({Tags.TRAIN_ONLY})
37 model.net.NextScopedBlob(name +
'_output'))
40 def add_ops(self, net):
41 class_probabilities = net.MakeTwoClass(
43 net.NextScopedBlob(
'two_class_predictions')
46 if self.
input_record.label.field_type().base != np.int32:
49 net.NextScopedBlob(
'int32_label'),
50 to=core.DataType.INT32)]
53 xent = net.LabelCrossEntropy(
54 [class_probabilities] + label,
55 net.NextScopedBlob(
'cross_entropy'),
59 if self.
input_record.weight.field_type().base != np.float32:
60 weight_blob = net.Cast(
62 weight_blob +
'_float32',
63 to=core.DataType.FLOAT
65 weight_blob = net.StopGradient([weight_blob], [weight_blob])
68 net.NextScopedBlob(
'weighted_cross_entropy'),
def is_schema_subset(schema, original_schema)