Skip to content

Log arrays and tensors#

Multidimensional arrays or tensors (logged with, for example, PyTorch or TensorFlow) can be displayed as images in Neptune.

Logging NumPy arrays#

You can log 2D or 3D NumPy arrays directly from memory.

To visualize the array as an image, use the upload() method together with File.as_image():

import numpy as np
import neptune
from neptune.types import File

run = neptune.init_run()

im_array = np.random.rand(100, 100, 3) * 255
run["np_image"].upload(File.as_image(im_array))

To log a series of NumPy arrays, use append() instead:

for epoch in range(data):
    im_array = ...
    run["train/distribution"].append(File.as_image(im_array))

See example in Neptune 

Logging tensors#

You can log 2D or 3D tensors directly from memory.

To visualize the tensor as an image, use the upload() method together with File.as_image():

TensorFlow#

import tensorflow as tf
from neptune.types import File

tf_tensor = tensorflow.random.uniform(shape=[10, 20, 3])
run["tf_image"].upload(File.as_image(tf_tensor))

You can also log a series of TensorFlow tensors:

from neptune.types import File

for epoch in range(data):
    tf_tensor = ...
    run["train/distribution"].append(File.as_image(tf_tensor))

See example in Neptune 

PyTorch#

import torch
from neptune.types import File

torch_tensor = torch.rand(30, 30)
run["torch_tensor"].upload(File.as_image(torch_tensor))

You can also log a series of PyTorch tensors:

from neptune.types import File

for epoch in range(data):
    torch_tensor = ...
    run["train/distribution"].append(File.as_image(torch_tensor))

See example in Neptune 

Logging channel-first format images#

Neptune assumes that colored images are in the channel-last format ([height][width][channels]) and throws a ValueError if you try to log channel-first images.

To log channel-first images, convert them to channel-last format:

You can use numpy.moveaxis(image_array, 0, -1) to move the channel axis to the last position:

import numpy as np
import neptune
from neptune.types import File

run = neptune.init_run()

channel_first_image_array = np.random.rand(3, 100, 100) * 255

# Move the channel axis (first) to the last position
channel_last_image_array = np.moveaxis(channel_first_image_array, 0, -1)

run["image_array"].upload(File.as_image(channel_last_image_array))

You can use tensorflow.transpose(image_tensor, perm=[1, 2, 0]) to move the channel axis to the last position:

import tensorflow as tf 
import neptune
from neptune.types import File 

run = neptune.init_run()

channel_first_tensor = tf.random.uniform(shape=(3, 255, 255))

# Move the channel axis (first) to the last position
channel_last_tensor = tf.transpose(channel_first_tensor, perm=[1, 2, 0])

run["tensor_image"].upload(File.as_image(channel_last_tensor))

You can use torch.moveaxis(image_tensor, 0, -1) to move the channel axis to the last position:

import torch
import neptune
from neptune.types import File

run = neptune.init_run()

channel_first_torch_tensor = torch.rand(3, 255, 255)

# Move the channel axis (first) to the last position
channel_last_torch_tensor = torch.moveaxis(channel_first_torch_tensor, 0, -1)

run["torch_tensor"].upload(File.as_image(channel_last_torch_tensor))

Logging 1D arrays#

If your data is a 1D array (such as audio data, waveform, or time series) you can log it as a FloatSeries.

Use the extend() method to log the list of values:

values = list(np.array([1,2,3,4]))
run["my-series"].extend(values)

Or use the append() method to add values one by one:

for value in np.array([1,2,3,4]):
    run["my-series"].append(value)

You can then display the values of series field (in this case, "my-series") as a chart in Neptune.

See example charts in Neptune 

Related