feat: differentiability proof - CNN learns inverse 3D rotations#2
feat: differentiability proof - CNN learns inverse 3D rotations#2divital-coder merged 5 commits intomainfrom
Conversation
Demonstrates that 3D image rotation is usefully differentiable by training a CNN+MLP to predict inverse rotation angles via gradient descent. Results: 68.7% L2 loss reduction over baseline (0.004906 → 0.001535) across 50 epochs on 16³ synthetic line images with ±30° rotations. Pipeline: 1. Generate rotated training data using MedImages.rotate_mi 2. CNN+MLP predicts 3 Euler angles from rotated image 3. Differentiable rotation (pure Julia + ForwardDiff rrule) applies predicted angles 4. L2 loss vs original drives gradient descent Adds Flux and ForwardDiff as dependencies for the example script. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a differentiability proof example (examples/differentiability_proof.jl) that demonstrates MedImages.jl's 3D rotation operations are usefully differentiable by training a CNN+MLP to learn inverse rotations via gradient descent. The example implements a standalone differentiable rotation using pure Julia (Euler rotation matrices + trilinear interpolation) with ForwardDiff-based angle gradients, achieving a 68.7% improvement in L2 loss over the baseline across 50 training epochs. This serves as a proof-of-concept showing that rotation operations can be made angle-differentiable, complementing MedImages' existing coordinate-differentiable interpolation.
Changes:
- Adds comprehensive differentiability proof script with synthetic 3D line data generation, custom differentiable rotation implementation, CNN+MLP model, and training loop
- Adds Flux (v0.16.9) and ForwardDiff (v1.3.2) as main package dependencies for the example
- Updates Manifest.toml with all transitive dependencies required by Flux and ForwardDiff
Reviewed changes
Copilot reviewed 1 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| examples/differentiability_proof.jl | Complete differentiability proof script implementing data generation, standalone differentiable 3D rotation (Euler matrices + trilinear interpolation), CNN+MLP model, and training loop to demonstrate that rotation is usefully differentiable |
| Project.toml | Adds Flux and ForwardDiff to dependencies with version constraints |
| Manifest.toml | Updates with all transitive dependencies for Flux and ForwardDiff |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace frame PNG images with proper text-based markdown content. All sections now use standard markdown tables, code blocks, and ASCII diagrams instead of embedded images. No emojis. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use a proper Mermaid graph that GitHub renders natively. Shows input formats, MedImage core, operations, output formats, backends, and autodiff support in a clean visual layout. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Shorten all sections, cap code blocks at 3-4 lines, consolidate redundant sections (challenge/solution into intro, GPU backend/usage into one, gradient/differentiability into one), add Quick Start. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…de images Architecture diagram and all tables (data structure, interpolation, API reference) are now rendered via Typst as dark-mode PNGs with no borders. Typst sources live in docs/typst/ for easy editing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Adds a differentiability proof script (
examples/differentiability_proof.jl) that demonstrates MedImages.jl's 3D rotation is usefully differentiable by training a CNN+MLP to learn inverse rotations via gradient descent.Results
Pipeline
MedImages.rotate_miwith random ±30° angles on 3 axesTechnical Notes
interpolate_purealready computes coordinate gradients via Enzyme — makingrotate_miitself angle-differentiable only requires rewriting the rotation matrix construction in pure Julia (removing@non_differentiableannotations)Run
~/.julia/juliaup/julia-1.11.6+0.x64.linux.gnu/bin/julia --project examples/differentiability_proof.jlTest plan
🤖 Generated with Claude Code