def test_pipeline_postprocess_multiple_one_hot_to_labels(): pipeline = pipeline_module.Pipeline( inputs=[[]], outputs=[ [preprocessors.OneHotEncoder(["a", "b", "c"])], [preprocessors.OneHotEncoder(["a", "b", "c"])], ], ) result = pipeline.postprocess([np.eye(3), np.eye(3)]) assert np.array_equal(result[0], [["a"], ["b"], ["c"]]) assert np.array_equal(result[1], [["a"], ["b"], ["c"]])
def get_hyper_preprocessors(self): hyper_preprocessors = [] if self._add_one_dimension: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.AddOneDimension())) if self._dtype in [tf.uint8, tf.uint16, tf.uint32, tf.uint64]: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.CastToInt32())) if not self._encoded and self._dtype != tf.string: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.CastToString())) if self.multi_label: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.MultiLabelEncoder())) if not self._encoded: if self.num_classes == 2 and not self.multi_label: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.LabelEncoder(self._labels))) else: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.OneHotEncoder(self._labels))) return hyper_preprocessors
def get_hyper_preprocessors(self): hyper_preprocessors = [] if self._add_one_dimension: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.AddOneDimension())) if self.dtype in [tf.uint8, tf.uint16, tf.uint32, tf.uint64]: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.CastToInt32())) if not self._encoded and self.dtype != tf.string: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.CastToString())) if self._encoded_for_sigmoid: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.SigmoidPostprocessor())) elif self._encoded_for_softmax: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.SoftmaxPostprocessor())) elif self.num_classes == 2: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.LabelEncoder(self._labels))) else: hyper_preprocessors.append( hpps_module.DefaultHyperPreprocessor( preprocessors.OneHotEncoder(self._labels))) return hyper_preprocessors
def test_pipeline_postprocess_one_hot_to_labels(): pipeline = pipeline_module.Pipeline( inputs=[[]], outputs=[[preprocessors.OneHotEncoder(["a", "b", "c"])]]) assert np.array_equal(pipeline.postprocess(np.eye(3)), [["a"], ["b"], ["c"]])