Moondream Vision Language Models

repository·main·Indexed 27 days ago

https://github.com/m87-labs/moondream

A family of tiny, efficient open-source vision language models (VLM) designed for image captioning, visual question answering (VQA), and object detection. Available in Moondream 2B for general-purpose understanding and Moondream 0.5B for edge devices. The project includes specialized recipes for gaze detection, promptable content moderation, and promptable video redaction, supporting deployment from local hardware to the cloud via Modal.

Tokens
7.7K
Snippets
12
Records
42
Agent score
94%

What's inside Moondream

  1. Overview of Moondream vision language models

    main
    Moondream is an efficient, open-source vision language model designed for image understanding tasks like captioning, visual question answering (VQA), and object detection. It is optimized to run on a wide range of devices and platforms.
  2. Install Promptable Content Moderation

    main

    To set up the content moderation tool, clone the repository, create a virtual environment, and install the necessary system and Python dependencies.

    1. System Requirements

    You must have ffmpeg and libvips installed on your system:

    2. Python Environment Setup

    Clone the repository and initialize a virtual environment:

    git clone https://github.com/vikhyat/moondream/blob/main/recipes/promptable-video-redaction
    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate

    3. Install Python Dependencies

    Windows Users: You must install PyTorch with CUDA support first:

    pip install torch==2.5.1+cu121 torchvision==0.20.1+cu121 --index-url https://download.pytorch.org/whl/cu121

    Then, install the remaining requirements:

    pip install -r requirements.txt
    git clone https://github.com/vikhyat/moondream/blob/main/recipes/promptable-video-redaction
    python -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt
  3. Use the Content Moderation Web Interface

    main

    The easiest way to moderate video content is via the built-in web interface.

    1. Start the server:
      python app.py
    2. Open the URL provided in the terminal (typically http://localhost:7860) in your browser.
    3. Moderation Workflow:
      • Upload a video file.
      • Enter a natural language prompt for the content you want to detect (e.g., "face", "cigarette", "gun").
      • Select a redaction style (e.g., obfuscated-pixel).
      • Optional Settings:
        • Adjust processing speed/quality.
        • Configure Grid size for detection (improves accuracy in complex scenes).
        • Use Test mode (defaults to 3 seconds) for quick validation before processing long videos.
      • Process the video and download the results.
    python app.py
  4. Run Gaze Detection on Videos

    main

    The Gaze Detection Video Processor automates face detection and gaze direction tracking in video files.

    1. Prepare Input: Place your video files (.mp4, .avi, .mov, or .mkv) into the input directory. The directory will be created automatically if it does not exist.
    2. Execute: Run the processing script.
    3. Retrieve Results: Processed videos are saved to the output directory with the prefix processed_ (e.g., output/processed_video.mp4).

    Each output frame includes colored bounding boxes for faces, lines for gaze direction, and points indicating the gaze target.

  5. Install the Gaze Detection Video Processor on Windows

    main

    Windows installation requires manual setup of libvips and FFmpeg to ensure proper GPU support and video processing.

    1. Clone and Environment: Clone the repository and create a virtual environment.
    2. PyTorch with CUDA: Install PyTorch specifically with CUDA support for NVIDIA GPUs.
    3. libvips:
      • Download the appropriate version (e.g., vips-dev-w64-all-8.16.0.zip for 64-bit x64).
      • Extract and copy all DLL files from vips-dev-8.16\bin to your project root or C:\Windows\System32.
      • Add the vips-dev-8.16\bin directory to your system PATH.
    4. FFmpeg: Download from ffmpeg.org, extract, and add the bin folder to your system PATH or project root.
    5. Dependencies: Install Python requirements via pip.
    # Clone and setup environment
    git clone [repository-url]
    cd moondream/recipes/gaze-detection-video
    python -m venv venv
    .\venv\Scripts\activate
    
    # Install PyTorch with CUDA support
    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
    
    # Install other dependencies
    pip install -r requirements.txt
  6. Best Practices for Content Moderation

    main

    To optimize your moderation workflow, follow these recommendations:

    • Validation: Always use Test mode first to ensure your natural language prompts are working as expected.
    • Accuracy: Enable grid-based detection for complex scenes where objects might be small or obscured (note: this increases processing time).
    • Redaction Styles:
      • Censor: Use for complete content blocking.
      • Blur styles: Use for less intrusive moderation.
      • Bounding Box: Use for content review and manual analysis.
    • Hardware: A GPU is strongly recommended to reduce processing time.
    • Resource Management: Monitor system resources, especially when using high-quality settings or grid-based detection.
  7. Install the Gaze Detection Video Processor on Linux/macOS

    main

    To install the Gaze Detection Video Processor on Linux or macOS, you must first install the system dependencies libvips and ffmpeg, then set up a Python virtual environment and install the project requirements.

    System Dependencies

    • Ubuntu/Debian: sudo apt-get update && sudo apt-get install -y libvips42 libvips-dev ffmpeg
    • CentOS/RHEL: sudo yum install vips vips-devel ffmpeg
    • macOS: brew install vips ffmpeg

    Project Setup

    Clone the repository, navigate to the recipe directory, and install the Python dependencies:

    git clone https://github.com/vikhyat/moondream.git
    cd moondream/recipes/gaze-detection-video
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
    # Ubuntu/Debian
    sudo apt-get update && sudo apt-get install -y libvips42 libvips-dev ffmpeg
    
    # CentOS/RHEL
    sudo yum install vips vips-devel ffmpeg
    
    # macOS
    brew install vips ffmpeg
    
    # Project Setup
    git clone https://github.com/vikhyat/moondream.git
    cd moondream/recipes/gaze-detection-video
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  8. Install Promptable Video Redaction

    main

    To set up the Promptable Video Redaction tool, clone the repository, create a virtual environment, and install the dependencies. You must also have ffmpeg installed on your system.

    System Requirements:

    • Python 3.8+
    • ffmpeg (installed via apt-get, brew, or manual download)
    • libvips (required for Windows users)

    Setup Steps:

    1. Clone the repository and set up a virtual environment.
    2. Install Python packages via requirements.txt.
    3. Install ffmpeg using your OS package manager.
    git clone https://github.com/vikhyat/moondream/blob/main/recipes/promptable-video-redaction
    python -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt
  9. Use the Web Interface for Video Redaction

    main

    The tool provides a Gradio-based web interface for users who prefer a GUI over the command line.

    1. Start the server by running python app.py.
    2. Open the URL provided in the terminal in your web browser.
    3. Upload a video, specify the object to censor (e.g., 'face', 'logo'), adjust processing settings (speed, quality, grid size), and download the result.
    python app.py
  10. Use the Promptable Video Redaction Gradio App

    main

    The Promptable Video Redaction application allows you to upload a video and use natural language to detect and redact/visualize objects (e.g., 'face', 'car', 'logo').

    Key Features:

    • Detection: Describe any object in natural language.
    • Visualization Styles:
      • censor: Redacts the detected object.
      • bounding-box: Draws a box around the object.
      • hitmarker: Applies a hitmarker style.
    • Test Mode: When enabled, the app only processes the first 3 seconds of the video, allowing for quick verification of settings.
    • Grid Processing: You can specify rows and cols to process video in a grid format.

    Advanced Settings:

    • Processing Speed: Choose an ffmpeg_preset (e.g., ultrafast, medium, slow). Faster presets result in lower quality but quicker processing.
    • Grid Configuration: Adjust rows and cols (1-4) to control the grid layout.