Instructions to use happyinhappy/klein-car-geometry-restore-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use happyinhappy/klein-car-geometry-restore-lora with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.2-klein", dtype=torch.bfloat16, device_map="cuda") pipe.load_lora_weights("happyinhappy/klein-car-geometry-restore-lora") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
Scene Geometry Fitted To The Car (FLUX.2 Klein 9B)
The name says geometry restore. What gets restored is the geometry of the room, not of the car. Given a car standing in a hall that does not agree with it, this LoRA bends the space: it re-proportions the walls, floor, ceiling line and lens feel of the surroundings until they are consistent with the object standing in them. The car is not reshaped.
The interesting part is how it knows what "consistent" means. Nothing measures the room. No depth map, no camera solve, no plane fitting, and the object's real millimetres are not what drives the warp — the model works from what a large image model already knows about how space behaves, and pulls the surroundings into a proportion that reads as true against this car.
This is the stage that makes a composite stop looking like a sticker on a photo.
Weights are not published. Model card only. This LoRA runs inside the mashinki pipeline in production.
The idea, in the dataset builder's own words
Goal of the LoRA: given (background + car), insert the car and adapt the background perspective to match the car's viewpoint. Ground truth is FREE — it is the real source photo, where car and background are already perspective-consistent.
That sentence is the whole design. A composite fails when the car was shot from one camera height and the background implies another: the car floats, or the floor runs away under it. You could try to warp the car to the background — and destroy the product you are selling. So you do the opposite, and you get the labels for nothing.
How it is driven in production
Read out of the live dispatcher on 2026-08-28 (/app/workflows/<hall>.json, identical across
all seven halls; /app/wf_patch.py; /app/showroom_process.py):
| when it runs | every time a dealer moves or resizes a car by hand and asks for the frame again |
| base | FLUX.2 Klein 9B, full weights (not the fp8 copy) |
| adapter | this LoRA at strength 0.7 |
| sampler | 6 steps, euler, beta scheduler, cfg 1.0, denoise 1.0 |
| latent | the encoded composite itself — there is no empty latent, which is why the delivered master keeps a 2048 long side |
| prompt | one fixed instruction with three slots filled per job: the hall's own hint, the car's body type, and the car's dimensions from the identity service |
Two honest notes about that prompt. It is written from the car's side — it asks the model to correct the vehicle's geometry and lens distortion while keeping the room untouched — which is the opposite wording from the training construction described above, where the room is the thing that was deliberately wrong. Both drive the same learned relation between an object and the space around it; the prompt simply names the end the operator cares about. And the dimension string is present in the prompt: the model is told what the car is, even though the warp it applies to the room is not computed from those numbers.
How the pairs are built
There is no dataset of "the same insertion, once mismatched and once correct". So the mismatch is manufactured, on the background, and the untouched original photograph is the target:
Per source photo, a four-part triplet in ai-toolkit layout:
| slot | content | how |
|---|---|---|
targets/ |
the real photo | ground truth, free |
control_2/ |
the car cutout, native viewpoint | BiRefNet segmentation, RGBA |
control_1/ |
the mismatched background | the plate, warped |
captions/ |
insert + adapt-perspective instruction | text |
The empty plate itself comes from a Klein masked-inpaint pass that removes the car from the real photo, so the background is genuinely the room the car stood in — then it is warped away from that truth on purpose:
tilt_up · tilt_side · zoom_in · zoom_out · tilt_zoom
Deterministic PIL homographies, reproducible from their parameters, with edge replication where the warp exposes new pixels. Each warp variant of one photo becomes its own triplet, so a single shoot frame yields several lessons — same car, same target, several wrong backgrounds to walk back from.
Training
| base | FLUX.2 Klein 9B (ss_base_model_version: flux2_klein_9b) |
| trainer | ai-toolkit 0.9.13 |
| adapter | 224 LoRA tensors, 158 MB |
| checkpoint | step 2,000 |
| continued from | the background-replace + relight run at step 2,750 |
| input | single image (singleinput in the run name) |
| run name | bgreplace_klein9b_geom_relight_singleinput_continue2750_l800 |
Continuing from the insertion checkpoint rather than starting fresh is deliberate: this model needs the same understanding of cars, halls and light that the insertion run built, and only then a different objective on top of it.
The other side of the same argument
A composite fails because the car and the room disagree. This model settles it by moving the room. A sibling run settles it by moving the car instead — same base, same pairs discipline, opposite direction, and it never shipped because it drifted on colour and identity. Worth reading next to this one: car corrected, background untouched.
Where it sits
segmentation ─► identity & dimensions ─► viewpoint
─► background replace + relight ─► THIS MODEL ─► plate ─► deliver
Pairs with the insertion model.
Limitations
- It works on the space, not the object. If the car cutout itself is wrong — a bad matte, a clipped wheel — nothing here fixes that.
- Trained on the warp family it was shown: tilt, zoom and their combination. A background wrong in some other way (wrong focal length feel, wrong horizon curvature) is out of distribution.
- Single frame. No memory of the other frames in the listing; cross-frame consistency is handled elsewhere.
- Generative. Pushed hard it will invent architecture in the background rather than merely re-project it.
Contact
Anastasiia Butova — ML engineer. https://happyin.work/mashinki/ · https://github.com/AnastasiyaW · https://t.me/happy_in_happy
- Downloads last month
- -
