[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-115083":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":14,"subscribersCount":14,"size":14,"stars1d":15,"stars7d":16,"stars30d":16,"stars90d":14,"forks30d":14,"starsTrendScore":17,"compositeScore":18,"rankGlobal":9,"rankLanguage":9,"license":9,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":9,"pushedAt":23,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":14,"starSnapshotCount":14,"syncStatus":15,"lastSyncTime":27,"discoverSource":28},115083,"gradient-descent-for-a-face","sirioberati\u002Fgradient-descent-for-a-face","sirioberati","Blobs of colour trained by gradient descent into a photo, entirely in code. Then turned in 3D.",null,"HTML",105,29,101,0,2,4,7,47.79,false,"main",true,[],"2026-11-11 22:48:09","2026-11-22 15:57:32","# Gradient Descent for a Face\n\n**This isn't a photo. It's tens of thousands of blobs of colour that taught themselves to be one.**\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"docs\u002Fmedia\u002Ftraining-side-by-side.gif\" width=\"720\" alt=\"Left: the real photo. Right: blobs of colour training from noise into the same picture.\">\n\u003C\u002Fp>\n\nOne photo goes in. The code starts from pure noise, and every step it paints the blobs, measures how wrong the picture is, and nudges every blob to be a little less wrong. No diffusion model and no image generator: the right-hand picture is drawn entirely by code. The method is the same training loop that AI image models use (gradient descent), pointed at a single photo.\n\nThe code was written by Claude (Fable 5.2 and Opus 5.5 in Claude Code).\n\n---\n\n## Which one is the photo?\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"docs\u002Fmedia\u002Fwhich-one-is-the-photo.jpg\" width=\"900\" alt=\"The real photo and the blob painting side by side\">\n\u003C\u002Fp>\n\nLeft is the real photo. Right is the code, after 3,540 steps and 50,400 blobs.\n\n## Zoom in, and it's blobs\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"docs\u002Fmedia\u002Fthe-blobs.jpg\" width=\"420\" alt=\"Close-up of the eye drawn as separate coloured discs\">\n  &nbsp;\n  \u003Cimg src=\"docs\u002Fmedia\u002Feye-from-noise.gif\" width=\"420\" alt=\"The eye forming out of noise as training runs\">\n\u003C\u002Fp>\n\nLeft: the same eye with every blob shrunk and drawn as a hard disc, so you can see what it's made of. Right: that eye forming from noise over the whole run.\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"docs\u002Fmedia\u002Fphoto-vs-code-zoom.jpg\" width=\"620\" alt=\"Real photo and code, full picture and a 7.5x zoom on the eye\">\n\u003C\u002Fp>\n\n## How it works, in plain words\n\n1. **A blob** is a soft, see-through dab of colour. Each one is nine numbers: where it sits (2), how wide and tall it is (2), its angle (1), its colour (3) and how strong it is (1).\n2. **Start random.** 1,500 blobs with random positions, sizes and colours. It looks like confetti.\n3. **Paint.** The code draws all the blobs into a picture.\n4. **Measure the mistake.** It compares that picture with the photo and gets one number for how wrong it is: the loss.\n5. **Nudge.** The maths works out, for every number on every blob, which way makes the mistake smaller, and moves it a tiny step that way (the Adam optimiser).\n6. **Repeat**, thousands of times. Nobody tells it \"this is an eye\". The eye appears because it lowers the mistake.\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"docs\u002Fmedia\u002Ffirst-steps.jpg\" width=\"900\" alt=\"Steps 0, 5, 15, 40, 100 and 300 of a short training run\">\n\u003C\u002Fp>\n\nThree tricks make it work:\n\n- **Blurry first, sharp later.** It learns a 160 px version of the photo, then 320 px, then close-up crops at 640 px and finally at the photo's full 1200 px.\n- **More blobs where it's wrong.** Every few steps it finds the spots with the biggest mistake and adds small new blobs there. The count grows from 1,500 toward 100,000.\n- **Close-ups.** Late in training it studies random zoomed-in patches, mostly of the face. That's where the lashes and stubble come from.\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"docs\u002Fmedia\u002Fface-from-noise.gif\" width=\"360\" alt=\"The whole face forming from noise\">\n\u003C\u002Fp>\n\n## The 3D turn\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"docs\u002Fmedia\u002F3d-turn.gif\" width=\"420\" alt=\"The blob painting turned in 3D, with a blink and a small smile\">\n\u003C\u002Fp>\n\nThe blob painting is pushed onto a depth surface and the camera turns. Honest note: **the depth is not learned by the blobs.** It comes from a separate, ready-made depth model (Depth Anything V2 Small) that guesses depth from the single photo. A full 360° spin isn't possible from one photo, because there is nothing behind the head to learn from. The blink and small smile are hand-made warps of the painting, not learned.\n\n## Run it yourself\n\n### Just watch it (no install)\n\nThe repo includes a recorded run, so you can play the film straight away. It only needs Python's built-in web server:\n\n```bash\npython3 -m http.server 5793\n```\n\nThen open `http:\u002F\u002Flocalhost:5793\u002Findex.html` and drag the bar at the bottom to scrub. `graphic\u002Floop-reel.html` is the 9:16 explainer of the loop. Opening the files directly (file:\u002F\u002F) won't work, because the page has to fetch its data.\n\n### Train it yourself\n\nNeeds Python 3.10+. It picks the fastest device it finds: an NVIDIA GPU (CUDA), an Apple-silicon GPU (MPS), or the CPU. It was built and tested on an M3 Pro; the CUDA path has not been tested.\n\n```bash\npython3 -m venv .venv && .venv\u002Fbin\u002Fpip install -r requirements.txt\n```\n\nTrain. This **replaces the included recorded run** in `train_v2\u002F` (about an hour on an M3 Pro for the full 7,000 steps; add `--quick` for a 60-step smoke test):\n\n```bash\n.venv\u002Fbin\u002Fpython train_v2\u002Ftrain.py\n```\n\nA finished run writes `train_v2\u002Fmeta.json` and the film picks it up. If you stop early, write the playback data for what exists so far (same file):\n\n```bash\n.venv\u002Fbin\u002Fpython train_v2\u002Flive_meta.py\n```\n\nThe depth surface for the 3D turn is already included (`train\u002Fdepth-tex.f32`). To rebuild it, for example after changing the photo:\n\n```bash\n.venv\u002Fbin\u002Fpython train\u002Fdepth.py\n```\n\nTo use your own photo, replace `reference\u002Fsirio-portrait.webp` and adjust the crop near the top of `train_v2\u002Ftrain.py`.\n\n## What's in here\n\n| Path | What it is |\n|---|---|\n| `train_v2\u002Ftrain.py` | The trainer: a hand-written 2D Gaussian splat renderer in PyTorch, Adam, densification and coarse-to-fine crops |\n| `train_v2\u002Fsnapshots.bin`, `meta.json` | The recorded run the film replays (12 bytes per blob per snapshot) |\n| `train_v2\u002Flive_meta.py` | Writes the playback data for a run that stopped before the end |\n| `train\u002F` | An early 300-step test run, plus the depth files the 3D turn uses |\n| `train\u002Fdepth.py` | Depth estimate and background mask for the 3D turn |\n| `index.html` | The film: one WebGL page that replays the real run, then the zoom proof and the 3D turn |\n| `graphic\u002F` | The 9:16 explainer of the loop, built from frames of the real run |\n| `BRIEF.md` | The original build brief |\n\n## Limits\n\n- It learns one photo. It can copy a face perfectly, but it can't invent a new one.\n- The 3D is a depth guess from one photo, not real 3D.\n- The numbers on screen come from the recorded run. The included recorded run stops at step 3,960 of a planned 7,000 (58,800 blobs); the pictures above were captured at step 3,540.\n\n---\n\nInspired by \"Gradient Descent for Orchestra\", a piece that shows music being learned by gradient descent.\n","这是一个用纯前端代码（HTML\u002FCanvas）实现的单图逆向建模项目，通过梯度下降算法将数万个可参数化彩色圆斑（blobs）从随机噪声逐步优化为逼真的人脸图像，并支持3D视角渲染。核心采用自定义可微分渲染器、多尺度渐进训练、动态增殖机制（在误差大的区域新增圆斑）和局部细节聚焦策略，全程不依赖预训练模型或外部AI框架。适用于计算机图形学教学演示、可解释性AI原理可视化、轻量级图像拟合实验及创意编码艺术实践。","2026-11-24 04:50:17","CREATED_QUERY"]