DaisyKit: AI for Everyone
Lesson 2 of 10

Lesson 02: Installation & First Program

4 min readViet-Anh NguyenViet-Anh Nguyen

Installing DaisyKit

DaisyKit provides prebuilt wheels for Linux x86_64 and Windows x86_64 (CPU only). Install with pip:

# Linux (Ubuntu 18.04+)
sudo apt install pybind11-dev libopencv-dev libvulkan-dev
pip install --upgrade pip
pip install daisykit

# Windows (no extra dependencies)
pip install daisykit

Verify:

import daisykit
print(daisykit.__version__)

GPU / Other platforms: For GPU support or non-x86 architectures (Raspberry Pi, Jetson, Apple Silicon), you need to build from source. See the build guide.

Google Colab: DaisyKit runs in Colab without any extra setup — just pip install daisykit. Use static images instead of webcam (Colab doesn't support cv2.imshow()).

The get_asset_file Model Registry

DaisyKit uses a central asset registry to manage model weights. When you call get_asset_file("models/...") for the first time, it downloads the file from daisykit-assets and caches it locally. Subsequent calls use the cached file — no internet required.

from daisykit.utils import get_asset_file

# First call: downloads the model (~10 MB)
model_path = get_asset_file("models/face_detection/yolo_fastest_with_mask/yolo-fastest-opt.param")
print(model_path)  # e.g. /home/user/.daisykit/assets/models/face_detection/...

# Second call: instant (file already cached)
model_path = get_asset_file("models/face_detection/yolo_fastest_with_mask/yolo-fastest-opt.param")

You can also provide your own model paths directly — skip get_asset_file and point to local files.

Your First Program: Face Detection on a Static Image

The fastest way to see DaisyKit in action is running face detection on a downloaded image:

import cv2
import json
import urllib.request
from daisykit.utils import get_asset_file, to_py_type
import daisykit

# Download a test image
urllib.request.urlretrieve(
    "https://ultralytics.com/images/zidane.jpg", "zidane.jpg"
)

# Configure the face detector flow
config = {
    "face_detection_model": {
        "model": get_asset_file(
            "models/face_detection/yolo_fastest_with_mask/yolo-fastest-opt.param"
        ),
        "weights": get_asset_file(
            "models/face_detection/yolo_fastest_with_mask/yolo-fastest-opt.bin"
        ),
        "input_width": 320,
        "input_height": 320,
        "score_threshold": 0.7,
        "iou_threshold": 0.5,
        "use_gpu": False,
    },
    "with_landmark": True,
    "facial_landmark_model": {
        "model": get_asset_file("models/facial_landmark/pfld-sim.param"),
        "weights": get_asset_file("models/facial_landmark/pfld-sim.bin"),
        "input_width": 112,
        "input_height": 112,
        "use_gpu": False,
    },
}

# Create the flow
flow = daisykit.FaceDetectorFlow(json.dumps(config))

# Load image and convert to RGB (DaisyKit expects RGB)
img = cv2.imread("zidane.jpg")
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

# Run inference
faces = flow.Process(img_rgb)
print(f"Detected {len(faces)} face(s)")

# Draw results on the image
flow.DrawResult(img_rgb, faces)

# Display
result = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR)
cv2.imshow("DaisyKit: Face Detection", result)
cv2.waitKey(0)
cv2.destroyAllWindows()

# Expected: window showing the portrait with face bounding boxes and 68 landmark dots

Important: DaisyKit expects images in RGB format. Always convert from OpenCV's BGR with cv2.cvtColor(img, cv2.COLOR_BGR2RGB) before calling Process(), and convert back with cv2.COLOR_RGB2BGR for display.

Saving Results to File (Headless / Colab)

Replace the imshow block with imwrite when running without a display:

result = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR)
cv2.imwrite("result.jpg", result)
print("Saved result.jpg")

Reading Inference Results

Every flow returns a list of Python objects via to_py_type():

from daisykit.utils import to_py_type

faces_py = to_py_type(faces)
for face in faces_py:
    print(f"  bbox: ({face['x']}, {face['y']}, {face['w']}, {face['h']})")
    print(f"  confidence: {face['confidence']:.2f}")
    print(f"  wearing mask: {face['wearing_mask_prob']:.2f}")
    # face['landmark'] is a list of (x, y) tuples if with_landmark=True

The config Dictionary Pattern

All DaisyKit flows follow the same initialization pattern:

config = {
    "model_name": {
        "model":        "<path to .param file>",
        "weights":      "<path to .bin file>",
        "input_width":  <int>,
        "input_height": <int>,
        "use_gpu":      False,       # True requires Vulkan-capable build
        # flow-specific keys...
    }
}
flow = SomeFlow(json.dumps(config))   # config must be a JSON string

The key insight: DaisyKit uses json.dumps(config) so the same config format works across Python, C++, Android, and iOS — the C++ core parses JSON natively.

What's Next

You now have DaisyKit installed and a working face detection pipeline. In the next lesson we go deeper into FaceDetectorFlow — examining the face and landmark models, tuning confidence thresholds, and building a real-time webcam application.

Lesson 02: Installation & First Program - Viet-Anh on Software