def label_encoder_deserializer_test(self): labels = ['a', 'b', 'c'] le = LabelEncoder(input_features=['label_feature'], output_features='label_feature_le_encoded') le.fit(labels) self.assertEqual(labels, le.classes_.tolist()) le.serialize_to_bundle(self.tmp_dir, le.name) # Test model.json with open("{}/{}.node/model.json".format(self.tmp_dir, le.name)) as json_data: model = json.load(json_data) # Deserialize the LabelEncoder node_name = "{}.node".format(le.name) label_encoder_tf = LabelEncoder() label_encoder_tf.deserialize_from_bundle(self.tmp_dir, node_name) # Transform some sample data res_a = le.transform(labels) res_b = label_encoder_tf.transform(labels) print("le.output_features: {}".format(le.output_features)) print("label_encoder_tf.output_features: {}".format( label_encoder_tf.output_features)) self.assertEqual(res_a[0], res_b[0]) self.assertEqual(res_a[1], res_b[1]) self.assertEqual(res_a[2], res_b[2]) self.assertEqual(le.input_features, label_encoder_tf.input_features) self.assertEqual(le.output_features, label_encoder_tf.output_features[0])
def label_encoder_test(self): labels = ['a', 'b', 'c'] le = LabelEncoder(input_features=['label_feature'], output_features='label_feature_le_encoded') le.fit(labels) self.assertEqual(labels, le.classes_.tolist()) le.serialize_to_bundle(self.tmp_dir, le.name) # Test model.json with open("{}/{}.node/model.json".format(self.tmp_dir, le.name)) as json_data: model = json.load(json_data) self.assertEqual(le.op, model['op']) self.assertEqual('labels', model['attributes'].keys()[0]) # Test node.json with open("{}/{}.node/node.json".format(self.tmp_dir, le.name)) as json_data: node = json.load(json_data) self.assertEqual(le.name, node['name']) self.assertEqual(le.input_features[0], node['shape']['inputs'][0]['name']) self.assertEqual(le.output_features, node['shape']['outputs'][0]['name'])