Moondream Vision Language Models
repository·main·Indexed 27 days ago
https://github.com/m87-labs/moondreamA 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.
What's inside Moondream
- 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.
Use the Command Line Interface for Video Redaction
mainThe CLI allows for automated batch processing of videos.
- Create an
inputsdirectory in the script folder. - Place your video files (
.mp4,.avi,.mov,.mkv,.webm) into theinputsdirectory. - Run
python main.pyto process all videos in the folder.
mkdir inputs # Place videos in ./inputs/ python main.py- Create an
Install Promptable Content Moderation
mainTo 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
ffmpegandlibvipsinstalled on your system:- Ubuntu/Debian:
sudo apt-get install ffmpeg libvips - macOS:
brew install ffmpeg libvips - Windows: Download FFmpeg from ffmpeg.org and follow the libvips Windows installation guide.
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\activate3. 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/cu121Then, install the remaining requirements:
pip install -r requirements.txtgit 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- Ubuntu/Debian:
Run Moondream locally or in the cloud
mainMoondream can be deployed locally or via cloud providers. For detailed setup instructions and getting started guides, visit the official Getting Started documentation.Use the Content Moderation Web Interface
mainThe easiest way to moderate video content is via the built-in web interface.
- Start the server:
python app.py - Open the URL provided in the terminal (typically
http://localhost:7860) in your browser. - 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- Start the server:
Run Gaze Detection on Videos
mainThe Gaze Detection Video Processor automates face detection and gaze direction tracking in video files.
- Prepare Input: Place your video files (
.mp4,.avi,.mov, or.mkv) into theinputdirectory. The directory will be created automatically if it does not exist. - Execute: Run the processing script.
- Retrieve Results: Processed videos are saved to the
outputdirectory with the prefixprocessed_(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.
- Prepare Input: Place your video files (
Install the Gaze Detection Video Processor on Windows
mainWindows installation requires manual setup of
libvipsandFFmpegto ensure proper GPU support and video processing.- Clone and Environment: Clone the repository and create a virtual environment.
- PyTorch with CUDA: Install PyTorch specifically with CUDA support for NVIDIA GPUs.
- libvips:
- Download the appropriate version (e.g.,
vips-dev-w64-all-8.16.0.zipfor 64-bit x64). - Extract and copy all DLL files from
vips-dev-8.16\binto your project root orC:\Windows\System32. - Add the
vips-dev-8.16\bindirectory to your systemPATH.
- Download the appropriate version (e.g.,
- FFmpeg: Download from ffmpeg.org, extract, and add the
binfolder to your systemPATHor project root. - 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.txtBest Practices for Content Moderation
mainTo 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.
Install the Gaze Detection Video Processor on Linux/macOS
mainTo install the Gaze Detection Video Processor on Linux or macOS, you must first install the system dependencies
libvipsandffmpeg, 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- Ubuntu/Debian:
Install Promptable Video Redaction
mainTo set up the Promptable Video Redaction tool, clone the repository, create a virtual environment, and install the dependencies. You must also have
ffmpeginstalled on your system.System Requirements:
- Python 3.8+
ffmpeg(installed viaapt-get,brew, or manual download)libvips(required for Windows users)
Setup Steps:
- Clone the repository and set up a virtual environment.
- Install Python packages via
requirements.txt. - Install
ffmpegusing 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.txtUse the Web Interface for Video Redaction
mainThe tool provides a Gradio-based web interface for users who prefer a GUI over the command line.
- Start the server by running
python app.py. - Open the URL provided in the terminal in your web browser.
- 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- Start the server by running
Use the Promptable Video Redaction Gradio App
mainThe 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
rowsandcolsto 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
rowsandcols(1-4) to control the grid layout.