Skip to main content

Image Models

One way to send image data to a navio prediction endpoint is to encode it as a base64 string. This is possible with any popular python image processing library, such as PIL:

import base64
from io import BytesIO
import numpy as np
from PIL import Image


def from_base64(encoding: str) -> np.ndarray:
img = Image.open(BytesIO(base64.b64decode(encoding.encode())))
img = np.array(img)
return img.reshape(*img.shape)


def to_base64(image: np.ndarray) -> str:
buffer = BytesIO()
Image.fromarray(image).save(buffer, 'PNG')
return base64.b64encode(buffer.getvalue()).decode()

The base64 representation of the image can be easily included in the request body. The type of the image column in the request schema can be set to string or image, with the latter option instructing the navio UI to display the input data as an image and not a string: try it out view of input as image

try-out view for an MNIST classifier model defining an input column of type image