3d-trainer
Train an adapter that makes an image-to-3D model take a sketch and a text
prompt, and export it as the GGUF the ggk engine applies with --adapter.
One recipe so far, triposr_scribble: a scribble adapter for
TripoSR.
ggk -m triposr-nvfp4.gguf --adapter pig_triposr_scribble_adapter-f16.gguf --ref-image sheep.png -p "a sheep" -o out.glb
TripoSG-scribble already takes a sketch and a prompt, but its mesh is bare
geometry. TripoSR's comes out of a radiance field, so the result here is
coloured, and the prompt decides the colours a line drawing cannot show
(-p "a black sheep").
What it does
TripoSR is a feed-forward model: a DINO ViT turns the picture into 1025 tokens, a transformer cross-attends to them and writes a triplane, a small NeRF MLP reads density and colour off it. It was trained on renders, and has no text input.
The adapter changes two things and adds no layers to the transformer:
- LoRA (rank 32) on the linears of the image encoder and of the triplane transformer, so the two learn to read a line drawing;
- the prompt goes through a CLIP text encoder (ViT-L/14's, frozen — the one TripoSG-scribble uses) and a small projector, and its 77 tokens are appended to the image tokens the transformer already attends to.
The NeRF decoder is not touched: what comes out is a TripoSR triplane like any other.
It is trained by distillation from TripoSR itself, which needs pictures and captions but no 3D data:
| sees | makes | |
|---|---|---|
| teacher: plain TripoSR | a render of an object, cut out over grey | a triplane |
| student: TripoSR + adapter | a scribble of that render, and its caption | the same triplane |
The loss compares the triplanes, and the density and colour fields at points sampled in the scene, half of them next to the teacher's surface. A scribble has no colours, so the student can only get them from the caption — that is what makes the prompt count. One row in five shows the render itself on white, in colour or in grey, so a photo still works; one in ten drops the caption, so a sketch alone does too.
The scribbles are drawn from the render (sketch.py): the silhouette of its
alpha mask, inner lines from an extended difference of Gaussians or Sobel
edges, a pen of varying width and darkness, and a wobble, framed the way the
engine frames the picture. python -m 3d_trainer sketch --image cutout.png
shows one.
The renders and captions are Cap3D's
of Objaverse — the kind of picture TripoSR was trained on. Each object is a
small zip inside a 42 GB archive; the select stage reads the ones it wants
over HTTP ranges (about 1 MB an object), keeps the views taken from a sensible
height, and never downloads the archive. Your own pictures work as well: a
folder of RGBA cut-outs, <name>.png with the caption in <name>.txt
(new --folder).
Running it
The package folder is 3d_trainer, which is not a name Python can import
by statement, so it is run as a module:
pip install 3d-trainer # or: cd 3d_trainer/src
python -m 3d_trainer new --project ~/3d-trainer/projects/triposr_scribble
python -m 3d_trainer download --project ~/3d-trainer/projects/triposr_scribble
python -m 3d_trainer run --project ~/3d-trainer/projects/triposr_scribble
run goes through the stages and skips what is done; interrupt it (Ctrl-C, or
stop from another terminal) and run it again to resume. start runs the
same thing detached, logging to pipeline.log.
| stage | on an RTX 5090 | |
|---|---|---|
select |
8000 captioned objects, two views each, from Cap3D | 30 min (network) |
teacher |
plain TripoSR's triplane of every render (1 MB each) | 21 min |
train |
6000 steps at batch 8: 232 LoRA pairs + the projector, 22.4M parameters | 1 h 20 min |
export |
export/adapter.safetensors, and <name>-f16.gguf next to the project |
seconds |
eval |
eval/sheet.png and eval/eval.json on held-out objects |
under a minute |
Training uses gradient checkpointing and takes about 6 GB of VRAM at batch 8
(train.grad_checkpoint, train.batch_size in project.json).
python -m 3d_trainer status --project <folder> what is done, and the ggk command line
python -m 3d_trainer set --project <folder> --steps 12k train longer (then `run` again)
python -m 3d_trainer preview --project <folder> --image sketch.png -p "a sheep" -p "a black sheep" --out preview.png
python -m 3d_trainer sketch --image cutout.png --out scribble.png
python -m 3d_trainer convert-adapter --input <folder>/export --output adapter-f16.gguf
preview renders what the adapter makes of a picture, one row per prompt,
with the PyTorch model — a quick look without the engine.
The adapter GGUF
<name>-f16.gguf (278 MB) holds, under the names the engine looks them up by:
| tensors | |
|---|---|
image_tokenizer.<linear>.lora_down.weight, .lora_up.weight, .alpha |
72 LoRA pairs for the DINO ViT, named after the TripoSR weight they sit beside |
backbone.<linear>.lora_down.weight, .lora_up.weight, .alpha |
160 pairs for the triplane transformer |
text_proj.net.0, text_proj.net.2, text_proj.norm |
the prompt projector: Linear, GELU, Linear, LayerNorm |
text_encoder.text_model.* |
the CLIP text model, unchanged (most of the file) |
and pig.adapter.kind = triposr-scribble with the rest of its description in
the metadata. The base model is not in it and is not modified: the engine adds
the low-rank branches at run time, so the one adapter serves every
quantization of TripoSR (q8_0, q4_k, nvfp4).
In the engine (a ggk build whose TripoSR accepts --adapter), --adapter-scale scales the LoRA and
--scribble-conf / --prompt-conf weigh the picture against the prompt
(1.0 each). The picture's subject is found as for plain TripoSR — its alpha
channel, a --mask, or a plain backdrop removed — and put on white paper.
A photo shows its own colours, and the adapter then has nothing to ask the
prompt. So when a prompt is given and the picture is not already a line
drawing, the engine traces it into one (the silhouette and the inner
lines, as sketch.py draws them) and runs twice: the mesh is the one plain
TripoSR makes of the photo, and its colours are read from the field the
adapter makes of the tracing and the prompt. Without -p, or with GGK_TRIPOSR_NO_TRACE=1, the
picture is used as it is. The prompt colours what is drawn; it does not add
parts that are not in the drawing (sunglasses have to be sketched in).
Results
The run described above (8000 objects, 6000 steps), on 48 held-out objects, scribble + caption against the teacher's field:
| with the caption | without | |
|---|---|---|
| inside/outside agreement | 0.968 | 0.967 |
| colour error (L1 on the teacher's solid) | 0.087 | 0.097 |
| triplane error (relative MSE) | 0.171 | 0.190 |
The shape comes from the drawing and the colour from the prompt: the same
hand-drawn pig gives a pink mesh with -p "a pink pig", a green one with
-p "a green pig", and a grey-brown one with no prompt. Surfaces are softer
than plain TripoSR's on a photo, and fine texture (a chessboard's squares, a
face) is not recovered from a caption. A colour picture is traced into a sketch by the engine
when a prompt comes with it; untraced, the picture decides and the prompt is ignored. The engine adds about
half a second to a TripoSR run (3.7 s against 3.1 s on an RTX 5090).
Materials
| id | what | size |
|---|---|---|
triposr |
stabilityai/TripoSR model.ckpt — the teacher and the model trained over (a TripoSR GGUF works too: materials.triposr.path) |
1.7 GB |
clip |
openai/clip-vit-large-patch14 — the text encoder the adapter carries |
1.7 GB |
captions |
tiange/Cap3D Cap3D_automated_Objaverse_full.csv |
255 MB |
They go to the Hugging Face cache and are shared between projects. Set
HF_TOKEN (or hf_token in project.json) for faster, unthrottled reads.
Project layout
project.json the configuration; everything has a default (project.py)
pipeline.log what the stages printed
data/index.jsonl the selected renders: id, caption, split
data/images/<id>.png the renders, RGBA
teacher/<id>.npy the teacher's triplanes, f16
checkpoints/last.pt the adapter being trained (resumable), log.csv beside it
export/ adapter.safetensors, adapter_config.json
eval/ sheet.png, eval.json
../<name>-f16.gguf the adapter for ggk (export.output_dir / export.copy_to)
Notes
- The student can be no better than its teacher: where TripoSR gives a flat or blurry back to a render, so does the adapter to its scribble.
- A scribble is drawn from a render here, not by a hand. The wobble and the varied pen cover a good part of the gap; drawings far from a clean outline (hatching, text, several objects) are outside what it was shown.
- The model licences apply to what you train: TripoSR is MIT, CLIP is MIT, Cap3D's captions are ODC-By and Objaverse's objects carry their own Creative Commons licences.
Metadata
Release files for 3d-trainer 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| 3d_trainer-0.0.2.tar.gz | 41.1 kB | Without provenance | Details for 3d_trainer-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| 3d_trainer-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for 3d_trainer-0.0.2-py3-none-any.whl |
Total release size: 85.4 kB
Release files / 3d_trainer-0.0.2.tar.gz
| Download URL | 3d_trainer-0.0.2.tar.gz |
|---|---|
| Size | 41.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f431fa574d27df2c3147ccda3c7bdb695805f1a638ef87b7a6b21928fd2f20e
|
|
BLAKE2b-256 checksum How to use checksums |
5edf6ad506b65d4060893d4bcb5afc11ef9ec21167c621ccf28cfd609fd48f93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / 3d_trainer-0.0.2-py3-none-any.whl
| Download URL | 3d_trainer-0.0.2-py3-none-any.whl |
|---|---|
| Size | 44.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
65a117770a3806fc10f5f74bedcbabbe0a33310cbc14ecd16e3d643e8619c250
|
|
BLAKE2b-256 checksum How to use checksums |
af6c97b3b3f1af4662e0001a55b4fb0c5f20bd1dbd1f80fe32afb1c2ef8ac2eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for 3d-trainer 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.