def _find_label_domain( eval_config: config_pb2.EvalConfig, schema: schema_pb2.Schema, model_name: Text, output_name: Text ) -> Tuple[Optional[Union[int, float]], Optional[Union[int, float]]]: """Find the min and max value for the label_key for this model / output.""" model_spec = model_util.get_model_spec(eval_config, model_name) if not model_spec: return None, None label_key = model_util.get_label_key(model_spec, output_name) if not label_key: return None, None label_schema = None for feature_schema in schema.feature: if feature_schema.name == label_key: label_schema = feature_schema break if label_schema is None: return None, None # Find the domain if label_schema.HasField('int_domain'): label_domain = label_schema.int_domain elif label_schema.HasField('float_domain'): label_domain = label_schema.float_domain else: return None, None left, right = None, None if label_domain.HasField('min'): left = float(label_domain.min) if label_domain.HasField('max'): right = float(label_domain.max) return left, right
def _create_accumulator( self) -> tf_metric_accumulators.TFCompilableMetricsAccumulator: padding_options = None if self._eval_config is not None: model_spec = model_util.get_model_spec(self._eval_config, self._model_name) if model_spec is not None and model_spec.HasField( 'padding_options'): padding_options = model_spec.padding_options return tf_metric_accumulators.TFCompilableMetricsAccumulator( padding_options, self._output_counts, desired_batch_size=self._desired_batch_size)
def create_accumulator( self) -> tf_metric_accumulators.TFCompilableMetricsAccumulator: configs = zip(self._metric_configs, self._loss_configs) padding_options = None if self._eval_config is not None: model_spec = model_util.get_model_spec(self._eval_config, self._model_name) if model_spec is not None and model_spec.HasField('padding_options'): padding_options = model_spec.padding_options return tf_metric_accumulators.TFCompilableMetricsAccumulator( padding_options, [len(m) + len(l) for m, l in configs], desired_batch_size=self._desired_batch_size)
def _get_example_weights(self, model_name: str, features: Dict[str, Any]) -> Any: spec = model_util.get_model_spec(self._eval_config, model_name) if not spec: raise ValueError( 'Missing model_spec for model_name "{}"'.format(model_name)) if spec.example_weight_key: if spec.example_weight_key not in features: raise ValueError( 'Missing feature for example_weight_key "{}": features={}'.format( spec.example_weight_key, features)) return features[spec.example_weight_key] elif spec.example_weight_keys: example_weights = {} for k, v in spec.example_weight_keys.items(): if v not in features: raise ValueError( 'Missing feature for example_weight_key "{}": features={}'.format( k, features)) example_weights[k] = features[v] return example_weights else: return np.array([1.0])