Skip to content

dxtrnear/TinyML-Model-Inspector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TinyML Security Scanner

A command-line tool to analyze TensorFlow Lite models for embedded ML applications.

Features

  • Metadata Extraction: Model size, architecture, input/output shapes, quantization type
  • Weight Analysis: Statistical analysis of model weights with anomaly detection
  • Quantization Detection: Automatically identifies float32, float16, int8, and mixed quantization

Installation

python -m venv tflite_venv
source tflite_venv/bin/activate  # On Windows: tflite_venv\Scripts\activate
pip install -r requirements.txt

Usage

Basic scan:

python src/cli.py model.tflite

Skip weight analysis (faster):

python src/cli.py model.tflite --skip-weights

Example Output

============================================================
MODEL METADATA
============================================================
Size: 0.42 MB (438,476 bytes)
Tensors: 8
Input shape: (1, 784)
Output shape: (1, 10)
Quantization: float32
Operators: MatMul

============================================================
WEIGHT ANALYSIS
============================================================
Total parameters: 109,184
Weight tensors analyzed: 3

No anomalies detected

============================================================
SUMMARY
============================================================
Status: PASS
Errors: 0
Warnings: 0

Detected Anomalies

The scanner detects:

  • All zeros: Weight layer is entirely zeros (model broken)
  • Constant weights: All weights identical (initialization failed)
  • Extreme sparsity: >99.5% weights are zero (unusual pruning)
  • High sparsity: >95% weights are zero (may be intentional)
  • Unusual range: Weight values outside typical range

Testing

pytest tests/

Development

Generate test models:

python tests/generate_test_models.py

Inspect models:

python tests/inspect_models.py

Exit Codes

  • 0: Success (no issues)
  • 1: File not found
  • 2: Invalid model format
  • 10: Warnings found
  • 20: Critical errors found
  • 99: Unexpected error

Project Structure

src/
├── cli.py                 # Command-line interface
├── core/
│   ├── model_loader.py    # Model loading and validation
│   └── exceptions.py      # Custom exceptions
├── analyzers/
│   ├── metadata.py        # Metadata extraction
│   └── weights.py         # Weight analysis
└── reporting/
    └── text_reporter.py   # Output formatting

License

MIT

About

ML Models scanning, to verify quantization quality.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages