A powerful, zero-shot anomaly detection system for industrial and manufacturing quality control. Detect defects, anomalies, and irregularities in real-time without training on defect examples.
This is a graphical interface for universal anomaly detection in any industrial or manufacturing setting. Simply show the system what "normal" looks like, and it will automatically flag anything unusual - scratches, dents, missing components, color variations, alignment issues, and more.
No training required. No labeled defect examples needed. Just point and detect.
- Zero-Shot Detection: Detects anomalies without training on defect examples
- Universal Application: Works across any industry - electronics, textiles, metal fabrication, pharmaceuticals, food production, etc.
- Real-Time Inspection: Live camera feed processing for production line monitoring
- Video & Batch Processing: Analyze recorded video or folders of images
- Visual Anomaly Maps: See exactly where defects are located with heatmap overlays
- Customizable Sensitivity: Adjust detection thresholds for your specific use case
- Reference Memory System: Store "golden samples" to improve accuracy
- Multiple AI Backbones: Choose from various pre-trained vision models for optimal performance
- Quality Control: Manufacturing defect detection on production lines
- Assembly Verification: Ensure all components are present and correctly positioned
- Surface Inspection: Detect scratches, dents, cracks, or discoloration
- PCB Inspection: Identify soldering defects, missing components, or trace issues
- Textile Inspection: Find tears, stains, or weaving defects in fabrics
- Food Safety: Spot contamination or packaging defects
- Pharmaceutical QC: Detect pill defects, packaging issues, or label problems
- Metal Fabrication: Identify welding defects, surface irregularities, or dimensional issues
- Python 3.8 or higher
- CUDA-compatible GPU (recommended for real-time performance)
- Webcam (optional, for live inspection)
- Install PyTorch with CUDA support (for GPU acceleration):
# For CUDA 11.8
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# For CUDA 12.1
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
# For CPU only (slower)
pip install torch torchvision torchaudioVisit PyTorch's website for other CUDA versions.
- Install the GUI package + dependencies (after installing PyTorch/TorchVision):
pip install -e .
# or, if you prefer the classic requirements workflow:
pip install -r requirements.txtOptional extras (install only if you need them):
pip install -e .[accelerated]-- pulls in xFormers for faster attention layers.pip install -e .[distributed]-- installs Horovod for large multi-node runs.
- Copy the configuration template:
cp config.example.yaml config.yaml- Run the application:
musc-gui
# or
python industrial_gui.py- The repository ships a
pyproject.toml, sopip install -e .(orpip install .) resolves the runtime dependencies automatically. - Install GPU-specific
torchandtorchvisionwheels from https://pytorch.org/get-started/locally/ before runningpip install -e .if you need a custom CUDA build. pip install -r requirements.txtis still available for simple/air-gapped environments.- Optional extras:
accelerated→ pulls inxformersfor memory-efficient attention.distributed→ installshorovod[pytorch]for large multi-node training.dev→ formatter + lint/test helpers (black,ruff,pytest).
The system uses state-of-the-art vision transformers (CLIP, DINO, DINOv2) to learn what "normal" looks like from your reference images. When processing new images, it compares them against this learned normal appearance and flags anything that deviates significantly.
The Technology: Built on the MuSc (Mutual Scoring) algorithm from ICLR 2024, which achieves 97.8% accuracy on standard industrial anomaly benchmarks without seeing a single defect example during training.
- Launch the GUI:
python industrial_gui.py - Click Configuration to select your AI model and set detection sensitivity
- Position your camera to view the inspection area
- Set Duration (how many seconds to collect frames) and Target FPS
- Click Start to begin real-time detection
- Detected anomalies appear automatically in the sidebar with scores and visual overlays
- Switch to the Load Video tab
- Click Browse Video and select your video file
- Set your collection parameters (Duration, Target FPS)
- Click Start Recording to process frames
- Review detected anomalies in the Anomalous sidebar
- Switch to the Load Video tab
- Click Browse Folder and select a folder of images
- Click Start Folder Inference to process all images
- Review results in the Anomalous sidebar
Edit config.yaml to customize the system:
datasets:
img_resize: 224 # Image size (224, 256, 384, 512)
device: 0 # GPU device (0, 1, etc.) or 'cpu'
models:
backbone_name: dinov2_vitb14 # AI model to use
batch_size: 1
thresholds:
image_threshold: 9.0 # Detection sensitivity (1.0-10.0)
overlay_threshold: 3.5 # Visualization intensityChoose the backbone that best fits your speed/accuracy needs:
Fast (for real-time on modest hardware):
vit_tiny_patch16_224.augreg_in21kvit_small_patch32_224.augreg_in21kdino_deitsmall16
Balanced (recommended):
dinov2_vitb14← Default, good balanceViT-B-16dino_vitbase16
High Accuracy (slower, needs powerful GPU):
dinov2_vitl14ViT-L-14google/siglip-so400m-patch14-384
Image Threshold (1.0-10.0): Controls what gets flagged as anomalous
- High (9.0-10.0): Fewer false alarms, only obvious defects
- Medium (7.0-9.0): Balanced for general use
- Low (1.0-7.0): Very sensitive, catches subtle issues but may have false positives
Overlay Threshold (1.0-10.0): Controls visualization intensity
- Only affects what you see in the heatmap overlay
- Does not change what gets detected
- Recommended: 3.0-5.0
The "Soft Memory" system lets you store 10-50 reference images of known good products. These are included in every inference batch to improve accuracy and reduce false positives.
Best Practices:
- Use 10-50 high-quality reference images
- Include normal variations (lighting, angle, positioning)
- All images should be from the same product/setup
- Update periodically as your product or process changes
Anomalous: View all detected defects with:
- Anomaly scores
- Visual overlay toggle
- Save to disk option
- Add to soft memory
- Delete false positives
Saved: Manually captured frames for later review
Soft Memory: Your reference library of "normal" examples
- GPU is critical: 10-50x faster than CPU for real-time use
- Image size: Smaller (224x224) is faster; larger (512x512) catches finer details
- Model selection: Tiny models process 3-5x faster than large models
- Soft memory: Keep under 50 images for best performance
- Batch size: Can increase for faster batch processing (if GPU memory allows)
- Reduce image size in config (512→384→256→224)
- Use a smaller AI model (try
vit_tiny_patch16_224.augreg_in21k) - Switch to CPU mode:
device: 'cpu'in config.yaml
- Ensure you have a CUDA-enabled GPU and installed PyTorch with CUDA support
- Use a smaller model (
vit_tinyinstead ofvit_large) - Reduce image resolution
- Clear soft memory if it has too many images
- Increase image threshold (try 9.5 or 10.0)
- Add more reference images to soft memory showing normal variations
- Ensure lighting and positioning are consistent
- Lower image threshold (try 7.0 or 8.0)
- Use a larger, more accurate model
- Increase image resolution
- Ensure reference images truly represent "normal"
Built on the MuSc (Mutual Scoring of Unlabeled Images) algorithm published at ICLR 2024:
Performance on Standard Benchmarks:
- MVTec AD: 97.8% classification accuracy, 97.3% segmentation AUROC
- VisA: 92.8% classification accuracy, 98.8% segmentation AUROC
How it works: Uses vision transformer features to compute mutual scoring between test images, identifying outliers without requiring defect examples during training.
If you use this tool in research or commercial applications, please cite the original MuSc paper:
@inproceedings{Li2024MuSc,
title={MuSc: Zero-Shot Industrial Anomaly Classification and Segmentation with Mutual Scoring of the Unlabeled Images},
author={Li, Xurui and Huang, Ziming and Xue, Feng and Zhou, Yu},
booktitle={International Conference on Learning Representations},
year={2024}
}MIT License - see LICENSE file for details.
Original MuSc algorithm by Xurui Li, Ziming Huang, Feng Xue, and Yu Zhou. GUI implementation and industrial application focus by Dylan Martin.
Minimum:
- Python 3.8+
- 8GB RAM
- CPU with AVX support
Recommended:
- Python 3.8+
- 16GB+ RAM
- NVIDIA GPU with 6GB+ VRAM (RTX 3060 or better)
- CUDA 11.8 or 12.1
For Production Line Real-Time:
- NVIDIA RTX 3080/4070 or better
- 16GB+ system RAM
- SSD storage
- Industrial camera (recommended: GigE Vision or USB3 with global shutter)
- Issues: Report bugs or request features via GitHub Issues
- Documentation: See
README_GUI.mdfor detailed GUI documentation - Original Research: See the original MuSc repository for research code
This GUI builds upon the groundbreaking work of the MuSc team at Huazhong University of Science and Technology. The core anomaly detection algorithm is from their ICLR 2024 publication.