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