Skip to content

Generative vision

StyleAI Studio

Swaps garments onto a real photo with diffusion models and pixel-precise segmentation, entirely on a single consumer GPU.

Overview

StyleAI Studio is an AI outfit-transformation platform, built as an internal prototype. A user uploads a photo and builds a look layer by layer: shirt, jacket, trousers, accessories. The face, body and pose are preserved, and every generation runs on one on-premise GPU with no cloud AI calls and no data leaving the machine. It is positioned as a visual styling and outfit-simulation tool, not a size-accurate fitting engine.

Result

A real captured run detected a 478-point face mesh and body landmarks, then generated a new garment end to end in around 12 seconds per apply.

Infrastructure

100% on-premise inference on a single NVIDIA RTX 4060 Ti. GGUF Q8 quantization and dynamic VRAM management keep the full pipeline running on one consumer GPU.

Before, analysis, after

Original photo
Before
Face mesh and body landmarks detected
AI analysis
Generated outfit
After
~12 sper apply, photo to generated outfit
4 stepseuler sampling at CFG 1
4.1 GBFLUX.2 Klein 4B, GGUF Q8
1 GPURTX 4060 Ti, 16 GB, all on-premise
478 ptsface mesh from the analysis stage
0cloud AI calls, no data leaves the machine

Architecture

A photo is checked and analysed on the CPU. A session and prompt engine decide what to ask for, ComfyUI runs SAM3 and FLUX.2 Klein on one consumer GPU, and the result streams back to the browser as it is made. Nothing is sent to a cloud model.

StyleAI Studio: a photo is analysed on CPU, a session and prompt engine choose the instruction, ComfyUI runs SAM3 and FLUX.2 Klein on the GPU, and the result streams back Photo upload JPG · PNG · WEBPup to 10 MB Analysis OpenCV + MediaPipeon CPU, no GPU Session + prompts rules + outfit contextpicks the instruction ComfyUI workflow SAM3 · reference latentsFLUX.2 Klein 4B Q8 Result SSE progress streambefore / after slider Catalogue 47 items by body regionupper · lower · full · extras Face protection face + hair kept on the personlatent, except full outfits,glasses, caps and shoes
From upload to result. The dashed inputs are the catalogue choosing the garment and the face-protection mask.

Photo analysis

OpenCV layer

Instant, pure Python: resolution, orientation, brightness, contrast, sharpness, exposure, colour temperature, skin tone, background complexity and dominant colours.

MediaPipe layer

100 to 300 ms with no GPU: face detection, face landmarks (a 478-point mesh), a 33-landmark body pose, body visibility, shoulder width, torso ratio and standing or sitting.

Photo-type detection

Pose landmarks classify the photo as full body, half body or closeup. The type decides the prompt, the latent size and whether the face is masked.

Warm while you look

FLUX.2 and SAM3 load in the background during analysis (30 to 60 seconds), so the first apply does not wait on model loading.

Used twice

The checks reject bad photos before a generation is wasted, and the same data feeds the on-screen analysis while the model warms up.

Pre-checks before any generation

CheckMethodIf it fails
Face presentMediaPipe face detectionAsks for a photo with the face visible
Single personPose and detectionAsks for one person only
Front-facingFace landmark angleAsks for a front-facing photo
Body visibleShoulder and hip keypointsAsks for a half or full body photo
ResolutionImage size, 512 × 512 minimumAsks for a higher-quality image
LightingHistogram mean and spreadAsks for better light
SharpnessLaplacian varianceAsks for a clearer photo

The wardrobe engine

Outfits are built layer by layer. Each layer has its own prompt template, and the prompt, not extra masking, controls what changes.

StyleAI Studio wardrobe chain: each layer is applied to the previous result with its own prompt, and every step image is stored for instant back and forward back · forward · goto: stored step images, no new generation Original stored once,never overwritten Layer 0 · base shirt, tee, topreplace upper body Layer 1 · outer jacket, blazer, coat“open and unzipped” Layer 3 · lower jeans, trousers, skirtkeep upper exactly Layer 2 · extras muffler, tie, glasses,cap, watch, shoes
Layers, each applied to the previous result. A full outfit (layer 4) replaces everything. Every step image is kept, so navigation costs nothing.

The prompt is the controller

No composing images, no re-masking per step. The prompt says what to do, the person image says where to start, and a session chain records every result.

Rules in a JSON file

Garment types, layers and prompt templates live in prompt_rules.json, so behaviour changes without touching code.

Dynamic prompts

A session context fills placeholders from the real outfit: “keep the upper body exactly as the pink shirt and black blazer, replace only the lower body.”

Navigation is free

Back, forward and jump-to-step restore stored images instantly. Applying a new item from mid-chain drops the forward history.

The ComfyUI workflow

  1. 01
    Load models

    FLUX.2 Klein 4B (GGUF Q8), a Qwen 3 4B text encoder, the FLUX.2 VAE and SAM3.

  2. 02
    Segment the garment

    SAM3 grounding at 0.2 confidence finds the clothing, and a clothes-only mask with VITMatte edge detail isolates it on the CPU, keeping VRAM for FLUX.

  3. 03
    Scale

    Person and garment are scaled to about one megapixel.

  4. 04
    Encode the instruction

    The prompt is encoded. The negative path is a real negative prompt, not a zeroed one, which protects colours.

  5. 05
    Reference conditioning

    The person latent anchors identity and pose, then the garment latent is chained on top as the thing to transfer.

  6. 06
    Sample

    Euler, 4 steps (5 for jackets), CFG 1, a latent of 832 × 1216 (832 × 960 for closeups) and a fresh seed each run.

  7. 07
    Decode and clean

    VAE decode to PNG, then VRAM and RAM cleanup nodes run, so the next request starts clean.

Fitting on one GPU

The whole pipeline runs on a single RTX 4060 Ti with 16 GB. Quantisation, pre-warming, loading only what a request needs, and cleanup between runs keep it inside that budget.

ComponentSizeRole
FLUX.2 Klein 4B, GGUF Q84.1 GBThe generator. Quantised to Q8 so it fits beside everything else.
Qwen 3 4B text encoder7.5 GB on diskReads the editing instruction.
SAM33.3 GBSegments garments and, for closeups, the face and hair.
FLUX.2 VAE0.3 GBEncodes the person and garment, and decodes the result.
Clothes-mask mattingCPURuns on the CPU on purpose, to avoid VRAM contention.
Unused nodesnever loadedThe API client strips disconnected nodes from the workflow before queuing, so models a request does not need are not loaded.
Pre-warmingduring analysisModels load while the user is still reading the photo analysis.
Everything else on the GPUoffloadedSAM3 plus FLUX needs about 14 GB. A second resident model, such as a local LLM, has to be offloaded first.

ComfyUI runs with smart memory disabled and one FastAPI worker, so a request is never competing with another for the GPU. Extra requests queue in ComfyUI.

Garments and identity

Model-worn photos

SAM3 isolates the garment cleanly, so they work best.

Product shots on white

SAM3 crops these badly. The segmentation nodes are bypassed, or the background is removed first.

Upper-body pre-crop

For shirts and jackets, the reference is cropped to its top 55% before upload, which stops trouser pixels bleeding into the result.

Two-pass base swap

When a new base layer goes under an existing jacket, the base is replaced first and the jacket is then layered back on.

Shoes

A feet-only mask lets the model regenerate just the shoe area, and the garment image is not cropped.

Short prompts

Long, per-product descriptions made the model lose the inner clothing, so templates stay short.

Identity is protected with a mask, not a second model. SAM3 finds the face and hair, the mask is inverted and applied to the person latent as a noise mask, so those pixels are kept while the clothing changes. It is skipped when the face itself must change (glasses and caps) and for full outfits.

What did not work

PuLID-Flux for identity

Incompatible with the Klein 4B model. Face preservation comes from reference conditioning and a latent mask instead.

Pasting the original face back

A post-process composite had size mismatches and visible seams.

Horizontal lower-body mask

Arms below the waist got masked and sleeve colour bled.

Pre-composing garments

Overlaying garment images before generation did not work.

Higher CFG and more steps

CFG 3.5 with 8 steps gave better jacket detail but background artefacts, so CFG stays at 1.

Text-only lower-body protection

Without the garment pre-crop, the visual reference overpowered the text instruction.

Serving

MethodPathWhat it does
POST/analyse/Photo analysis with the face mesh and pose landmarks
POST/session/createUpload a photo and start a session
POST/session/{id}/apply/streamApply a catalogue item, streaming progress over SSE
POST/session/{id}/back · forward · gotoMove through stored steps with no GPU call
GET/catalogue/categories · /catalogue/Category tree and items by region
POST/swap/direct/streamOne-off swap from an uploaded person and garment

FastAPI fronts ComfyUI. Requests are authenticated with an API key, and progress is relayed from ComfyUI’s WebSocket to the browser as server-sent events.

The interface

Analysis panel

Shows 25+ checks with a face-mesh and body-zone overlay drawn on the photo.

Catalogue

Man, Woman and Child personas, hierarchical categories, tag filters and colour swatches.

Try-on studio

Live progress over SSE, a before and after slider, an applied-items strip with a running price, undo and back through the outfit history, add to cart and PNG download of the final look.

Plain web stack

A vanilla JavaScript single-page app, no framework and no build step, with a neo-brutalist design.

Limits and next steps

Works best for

Front-facing photos, standard proportions and clear lighting. It is a visual styling tool, not a size-accurate fitting engine.

Next

An add-layer mode and a single-item mode, both needing region-specific masking and inpainting, so the rest of the outfit is left untouched.