CIFAR-10 Crystal
NeuralCrystal was built by Pete DeLaurentis with Shellcaster, an IDE for building complex projects with agents.
This model represents a physical crystal with 40 etched surfaces and 13M parameters that is trained to classify color photos with light. The photo goes in as light, makes four passes through the block, and lights up a pair of squares naming one of ten classes.
Demo
Run this crystal in the optical simulator at NeuralCrystal.com: pick a photo and watch the crystal name it, and see the light travel through the glass.
Input
The photo goes in as a 256 × 256 picture on a micromirror array. Each photo pixel becomes a small 2 × 2 patch of colored regions (red, green, blue and a dark copy of its brightness), each one shown by switching mirrors on and off in a dither pattern. Here's a frog from the test set, and what the mirrors show:
Output
Between passes, a camera reads the light and writes its picture back onto the mirrors, the only electronics in the loop. After the fourth pass, the light lands on twenty squares on the exit face: a plus square and a minus square for each class. A class's score is its plus square's share of the light in its pair, and the highest score wins. Below, the squares are outlined in teal and the answer, frog, in white:
Results
Accuracy on the 10,000 CIFAR-10 test photos (higher is better). "With the mirror" adds the scores of the photo flipped left to right, a second run of the crystal.
| Precision | One run | With the mirror |
|---|---|---|
| 32-bit | 68.70 % | 70.23 % |
| 16-bit | 68.72 % | 70.17 % |
| 8-bit | 68.64 % | 70.07 % |
The three precisions score within 0.2 points of each other.
Use it
Install the neuralcrystal Python package, which runs the crystal's light path in PyTorch. Its code and more examples are on GitHub at neuralcrystal/neuralcrystal.
pip install neuralcrystal
import numpy as np
from PIL import Image
import neuralcrystal as nc
from neuralcrystal import cifar10
crystal = nc.load("cifar10-crystal.safetensors")
# 32 × 32
photo = np.array(Image.open("photo.png").convert("RGB"))
cls, scores = cifar10.classify(crystal, photo, flip=True)
print(cifar10.LABELS[int(cls[0])])
With ONNX Runtime
cifar10-crystal.onnx is the same light path as one ONNX graph, all four passes included, so ONNX Runtime can run the crystal from Python, C++, C#, Java or JavaScript, on a CPU or a GPU. It takes the 256 × 256 picture on the micromirrors and returns the light on the twenty squares, a plus and a minus square for each class. Here the package draws the picture (it needs PyTorch installed); the light runs in ONNX Runtime. It gives the same classes as the package (checked on a CPU, on CUDA and on an Apple GPU), in about a quarter of a second a photo on a laptop CPU and 30 ms on an NVIDIA GPU.
pip install onnxruntime neuralcrystal
import numpy as np
from PIL import Image
import onnxruntime as ort
import neuralcrystal as nc
from neuralcrystal import cifar10
session = ort.InferenceSession("cifar10-crystal.onnx")
# the 256 × 256 micromirror picture the crystal was trained on (its settings come from the crystal file)
crystal = nc.load("cifar10-crystal.safetensors")
photo = np.array(Image.open("photo.png").convert("RGB"))
frame = cifar10.frame(crystal, photo).numpy()
# the light on the twenty squares: each class's plus square, then its minus square
light = session.run(["det"], {"frames": frame})[0][0]
score = (light[:10] - light[10:]) / (light[:10] + light[10:])
print(cifar10.LABELS[int(score.argmax())])
On an NVIDIA GPU, ask for CUDA with TF32 off. TF32 rounds the matrix multiplies to 10 bits, and between passes the crystal rounds its light to the micromirrors' levels, so the error grows from pass to pass:
session = ort.InferenceSession("cifar10-crystal.onnx", providers=[("CUDAExecutionProvider", {"use_tf32": 0}), "CPUExecutionProvider"])
On a Mac, Core ML runs it on the GPU. Core ML needs a fixed batch size, so pin batch to 1 and send one picture at a time:
opts = ort.SessionOptions()
opts.add_free_dimension_override_by_name("batch", 1)
session = ort.InferenceSession("cifar10-crystal.onnx", opts, providers=[("CoreMLExecutionProvider", {"ModelFormat": "MLProgram", "MLComputeUnits": "CPUAndGPU"}), "CPUExecutionProvider"])
Besides the answer, the graph also returns frame (the camera's picture), intensity (the light leaving the glass, 1024 × 1024) and hid1–hid3 (the pictures between the passes). Ask only for the output you need, as above, so the large ones stay on the device.
Files
| File | Size | What it holds |
|---|---|---|
cifar10-crystal.safetensors |
168 MB | 40 phase surfaces, fp32 radians |
cifar10-crystal-16bit.safetensors |
26.6 MB | phase wrapped to one turn, 16 bits a sample, cropped to the lit window |
cifar10-crystal-8bit.safetensors |
13.3 MB | the same at 8 bits |
cifar10-crystal.onnx |
200 MB | the same light path as one ONNX graph (fp32), for ONNX Runtime |
The crystal
| Part | Details |
|---|---|
| Light | 617 nm, coherent |
| Glass | fused silica, n = 1.4607; four sections side by side in one block, separated by air slots |
| Surfaces | 10 per section, each 1024 × 1024 samples at 1 µm; 8 mm of glass per pass |
| Lit window | 576 µm square |
| Input | the photo as a 256 × 256 frame: each photo pixel becomes a 2 × 2 of color regions (red, green, blue, 255 − luma), area-dithered on 576 × 576 mirrors |
| Between passes | the camera's picture exposed from its own mean and spread, plus a quarter of that section's input added back, dithered to 5 levels (2 × 2 mirrors a pixel) |
| Output | ten differential pairs of squares; class k scores (p⁺ − p⁻) / (p⁺ + p⁻) |
Training
Trained in simulation on the 50,000 CIFAR-10 training photos (Krizhevsky, 2009), in stages:
- The base: photos with random flips, crops and cut-out patches, so it learns the class rather than the exact picture.
- Warm restarts: a chain of training segments, 344 passes over the data in all, each starting the learning rate high again.
- Even light: the last segments spread the light evenly over the twenty squares, so no class's pair goes dark.
Credits
The crystal was trained on photos from CIFAR-10 (Krizhevsky, 2009).
License
The crystal is CC BY-NC 4.0: free to use, share and adapt for non-commercial purposes, with credit. For commercial use, contact TextJam, Inc.
The neuralcrystal code is MIT.
© 2026 TextJam, Inc.


