# What Is the Format and Size of Magika's Deep Learning Model?

> Discover Magika's deep learning model format and size. It's a lightweight TensorFlow.js graph model under a few MB, running inference in milliseconds on CPU.

- Repository: [Google/magika](https://github.com/google/magika)
- Tags: internals
- Published: 2026-04-16

---

**Magika's deep learning model is a TensorFlow.js graph-model stored as JSON topology with binary weight shards, weighing only a few megabytes and capable of running inference in milliseconds on a single CPU.**

The format and size of Magika's deep learning model are central to its portability and speed. Located in the `google/magika` repository, this compact neural network powers fast file-type detection across Python, Rust, and JavaScript environments without requiring GPU acceleration.

## Model Format and Storage Structure

### TensorFlow.js Graph-Model Architecture

The model follows the **TensorFlow.js "graph-model"** format, which separates the neural network topology from its learned parameters. In [`website/public/models/standard_v3_3/model.json`](https://github.com/google/magika/blob/main/website/public/models/standard_v3_3/model.json), the format is explicitly declared:

```json
{"format":"graph-model", ...}

```

This JSON file defines the model's inputs, outputs, and layer architecture, while referencing external binary shards for the actual weights. The weight data resides in `group1-shard1of1.bin`, a binary file containing the quantized parameters necessary for inference.

### Directory Layout and Key Files

The complete model distribution resides in `website/public/models/standard_v3_3/` and includes:

| File | Purpose |
|------|---------|
| [`model.json`](https://github.com/google/magika/blob/main/model.json) | Graph topology definition and weight shard references |
| `group1-shard1of1.bin` | Binary weight shard (~few MB) |
| [`README.md`](https://github.com/google/magika/blob/main/README.md) | Output documentation and usage notes |

For development and conversion workflows, the ONNX representation is available at `assets/models/standard_v3_3/model.onnx`, serving as the source of truth for generating the TensorFlow.js artifacts.

## Model Size and Performance Characteristics

### Compact Footprint for CPU Inference

The model is deliberately optimized for minimal size. According to the repository's README, it is **"a custom, highly optimized model that only weighs about a few MBs"**. This compact footprint enables:

- **Sub-millisecond inference** on standard CPUs
- **Browser-based execution** without downloading large artifacts
- **Embedded deployment** in resource-constrained environments

The single weight shard (`group1-shard1of1.bin`) contains all learned parameters, eliminating the network latency of fetching multiple chunks during initialization.

### ONNX Source and Conversion Pipeline

While the runtime uses TensorFlow.js format, the model originates as an **ONNX** file. The `assets/models/standard_v3_3/model.onnx` path contains the platform-agnostic representation, which undergoes conversion to generate the website-optimized graph-model. This dual-format approach ensures:

- **Cross-platform consistency** (Python/Rust use ONNX, JavaScript uses TF.js)
- **Version synchronization** between backend and frontend implementations

## Loading the Model in Practice

### Python Implementation

The Python package loads the model via TensorFlow or ONNX Runtime. In [`python/src/magika/magika.py`](https://github.com/google/magika/blob/main/python/src/magika/magika.py), the `Magika` class initializes the neural network:

```python
from magika import Magika

mag = Magika()
result = mag.identify_path("example.pdf")
print(result.prediction.output.label)   # → pdf

print(result.score)                    # confidence score

```

### JavaScript Browser Usage

The JavaScript API fetches the graph-model from the `standard_v3_3` directory:

```javascript
import { Magika } from "magika";

const magika = new Magika();
const { label, score } = await magika.identifyFile(fileBlob);
console.log(`Detected: ${label} (score ${score})`);

```

### Rust CLI

The Rust implementation provides command-line access to the same model:

```bash
magika -l example.pdf   # prints the label only

magika --json example.pdf   # JSON output with score

```

All three implementations ultimately rely on the same compact [`model.json`](https://github.com/google/magika/blob/main/model.json) and `group1-shard1of1.bin` files, ensuring consistent predictions across environments.

## Summary

- **Format**: TensorFlow.js graph-model (JSON topology + binary weight shards) generated from ONNX
- **Location**: `website/public/models/standard_v3_3/` containing [`model.json`](https://github.com/google/magika/blob/main/model.json) and `group1-shard1of1.bin`
- **Size**: Approximately a few megabytes, enabling fast downloads and low memory usage
- **Performance**: Sub-millisecond inference on single CPU without GPU requirements
- **Cross-platform**: Python/Rust use ONNX source; JavaScript uses the TF.js graph-model

## Frequently Asked Questions

### What file format does Magika use for its neural network?

Magika uses the **TensorFlow.js graph-model format** for its runtime deployment. This consists of a [`model.json`](https://github.com/google/magika/blob/main/model.json) file describing the network architecture and binary weight shards (such as `group1-shard1of1.bin`) containing the learned parameters. The model is converted from an ONNX representation stored in `assets/models/standard_v3_3/model.onnx`.

### How large is the Magika model download?

The complete model weighs **only a few megabytes**. According to the google/magika README, it is "a custom, highly optimized model that only weighs about a few MBs." The single weight shard file is approximately this size, making it suitable for browser-based applications and embedded systems with limited bandwidth.

### Can Magika run without a GPU?

Yes, Magika is specifically optimized for **CPU-only inference**. The compact model size and efficient architecture enable inference in a few milliseconds on a single CPU core, regardless of input file size. This design choice eliminates the need for GPU hardware, making Magika accessible on servers, desktops, and mobile devices without specialized accelerators.

### Where is the model stored in the repository?

The TensorFlow.js model files are located in **`website/public/models/standard_v3_3/`**. This directory contains the [`model.json`](https://github.com/google/magika/blob/main/model.json) topology file and the `group1-shard1of1.bin` weight shard. The ONNX source file is stored separately at `assets/models/standard_v3_3/model.onnx` for backend implementations and conversion workflows.