I encountered the following python function in a GAN code.
def img_to_bytes(x_sample): imgObj = PIL.Image.fromarray(x_sample) imgByteArr = io.BytesIO()