Images Reporting

The image_reporting.py example demonstrates reporting (uploading) images in several formats, including NumPy arrays, uint8, uint8 RGB, PIL Image objects, and local files. Trains reports these images as debug samples in the Trains Web (UI), experiment details, RESULTS tab, DEBUG SAMPLES sub-tab. When the script runs, it creates an experiment named image reporting, which is associated with the examples project.

Images are uploaded to the bucket specified in the Trains configuration file, or a default upload destination which can be a bucket or folder location, see set_default_upload_destination. Credentials for the storage location are set in the Trains configuration file. Image destinations are not the same as the destination for artifacts and checkpoint models (see Artifacts Reporting).

Logger.report_image

Report images using the following formats by calling the Logger.report_image method.

  • Numpy arrays
  • uint8
  • uint8 RGB
  • PIL Image object
# report image as float image
m = np.eye(256, 256, dtype=np.float)
logger.report_image("image", "image float", iteration=iteration, image=m)

# report image as uint8
m = np.eye(256, 256, dtype=np.uint8) * 255
logger.report_image("image", "image uint8", iteration=iteration, image=m)

# report image as uint8 RGB
m = np.concatenate((np.atleast_3d(m), np.zeros((256, 256, 2), dtype=np.uint8)), axis=2)
logger.report_image("image", "image color red", iteration=iteration, image=m)

# report PIL Image object
image_open = Image.open(os.path.join("data_samples", "picasso.jpg"))
logger.report_image("image", "image PIL", iteration=iteration, image=image_open)

Logger.report_media

Also, report images by calling the Logger.report_media.

# Image can be uploaded via 'report_media' too.
logger.report_media(
    "image",
    "image with report media",
    iteration=iteration,
    local_path=os.path.join("data_samples", "picasso.jpg"),
    file_extension="jpg",
)