(
self,
model,
input_record,
prediction_layer,
output_dims,
subtract_log_odd=True,
name='sampling_train',
**kwargs
)
| 12 | |
| 13 | class SamplingTrain(ModelLayer): |
| 14 | def __init__( |
| 15 | self, |
| 16 | model, |
| 17 | input_record, |
| 18 | prediction_layer, |
| 19 | output_dims, |
| 20 | subtract_log_odd=True, |
| 21 | name='sampling_train', |
| 22 | **kwargs |
| 23 | ): |
| 24 | super().__init__(model, name, input_record, **kwargs) |
| 25 | |
| 26 | layer_class = get_layer_class(prediction_layer) |
| 27 | assert issubclass(layer_class, SamplingTrainableMixin) |
| 28 | |
| 29 | assert 'indices' in input_record |
| 30 | assert isinstance(input_record.indices, schema.Scalar),\ |
| 31 | "input_record.indices is expected to be a schema.Scalar" |
| 32 | assert 'input' in input_record |
| 33 | |
| 34 | self.subtract_log_odd = subtract_log_odd |
| 35 | if self.subtract_log_odd: |
| 36 | assert 'sampling_prob' in input_record |
| 37 | |
| 38 | self._prediction_layer = layer_class( |
| 39 | model, |
| 40 | input_record.input, |
| 41 | output_dims=output_dims, |
| 42 | **kwargs |
| 43 | ) |
| 44 | |
| 45 | self._prediction_layer.train_param_blobs = [ |
| 46 | model.net.NextBlob(str(blob) + '_sampled') |
| 47 | for blob in self._prediction_layer.param_blobs |
| 48 | ] |
| 49 | |
| 50 | self.params = self._prediction_layer.params |
| 51 | |
| 52 | self.output_schema = self._prediction_layer.output_schema |
| 53 | |
| 54 | def add_ops(self, net): |
| 55 | self._prediction_layer.add_ops(net) |
nothing calls this directly
no test coverage detected