FPGA AI Suite Handbook

ID 863373
Date 11/21/2025
Public
Document Table of Contents

12.3.4. Hostless DDR-Free Design Example Input Data Conversion

The hostless DDR-free design example streams data into the FPGA AI Suite IP from the ingress on-chip memory. To achieve this, the system console script must stage input data in a .bin file format instead of .bmp format. The .bin file must be in organized in HWC (height-width-channel) format and in the following precision modes, depending on your input type:
  • Layout transform (full or lightweight) input_type is FP16, the precision mode of the .bin file must be FP16 (half-precision floating-point).
  • Otherwise, the precision mode of the .bin file must be U8 (unsigned 8-bit).
To facilitate this conversion from values in a .bmp file to FP16 values, refer to the following example Python code. This script reads a .bmp file, converts the image data to FP16 format, and saves it in the required .bin format.
Figure 37. Python Example Code for .bmp to .bin Conversion
import sys
from PIL import Image
import numpy as np

def convert_image_to_bin(input_image_name):
    # Read the BMP file
    img = Image.open(input_image_name)
    output_file_name = 'array_hwc_fp16.bin'

    # Convert the image to a numpy array
    arr = np.array(img)

    # Convert the image to FP16 format
    arr_fp16 = arr.astype(np.float16)

    # Save the FP16 HWC formatted data to a .bin file
    with open(output_file_name, 'wb') as f:
        arr_fp16.tofile(f)

    print(f"Converted {input_image_name} to {output_file_name}")

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python bmp_to_bin_converter.py <input_image_name>")
        sys.exit(1)

    input_image_name = sys.argv[1]
    convert_image_to_bin(input_image_name)