def _assert_encode_decode(self, coder, expected_proto_text, expected_decoded):
example = tf.train.Example()
text_format.Merge(expected_proto_text, example)
data = example.SerializeToString()
# Assert the data is decoded into the expected format.
decoded = coder.decode(data)
np.testing.assert_equal(expected_decoded, decoded)
# Assert the decoded data can be encoded back into the original proto.
encoded = coder.encode(decoded)
parsed_example = tf.train.Example()
parsed_example.ParseFromString(encoded)
self.assertEqual(example, parsed_example)
# Assert the data can be decoded from the encoded string.
decoded_again = coder.decode(encoded)
np.testing.assert_equal(expected_decoded, decoded_again)
评论列表
文章目录