How to log images to Neptune?

Problem

I generate model predictions after every epoch. How can I log them as images to Neptune?

Solution

Step 1

Create PIL image that you want to log. For example:

1
2
3
4
5
import imgaug as ia
from PIL import Image

img = ia.quokka()
img_pil = Image.fromarray(img)

Step 2

Log image to Neptune

1
2
3
4
5
6
7
import neptune 

# This function assumes that NEPTUNE_API_TOKEN environment variable is defined.
neptune.init(project_qualified_name='username/my_project')

with neptune.create_experiment() as exp:
    exp.send_image('quokka', img_pil)

image

More about images in neptune

You can log images in a loop. For example, you can augment your image and log it to Neptune:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from imgaug import augmenters as iaa

aug_seq = iaa.Affine(scale={"x": (0.8, 1.2), "y": (0.8, 1.2)},
                     translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)},
                     rotate=(-25, 25),
                     )

exp2 = neptune.create_experiment():
for run in range(20):
    img_aug= aug_seq.augment_image(img)
    img_pil_aug = Image.fromarray(img_aug)
    exp2.send_image('quokka_version_{}'.format(run), img_pil_aug)

exp2.close()

image

See also