Пример #1
0
def _save_image_from_record(record: Dict[str, tf.Tensor], outfile: str):
    """Extracts image data from parsed TFRecord and saves it to a file."""

    b64_image = record['image'].numpy()
    image = beam_image.decode(b64_image, record['image_width'],
                              record['image_height'], record['image_channels'])
    image.save(outfile)
Пример #2
0
    def test_base64_decode(self):
        """Tests `decode` function."""

        image = Image.open(self.image_file)
        b64_bytes = base64.b64encode(image.tobytes(),
                                     altchars=beam_image.BASE64_ALTCHARS)
        width, height = image.size
        actual = beam_image.decode(b64_bytes, width, height, 3)
        np.testing.assert_array_equal(np.asarray(actual), np.asarray(image))