Finegrain Product Placement LoRA (experiment)
finegrain
β’ β’ 5How to use finegrain/finegrain-product-placement-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.1-Kontext-dev", dtype=torch.bfloat16, device_map="cuda")
pipe.load_lora_weights("finegrain/finegrain-product-placement-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]A lightweight LoRA (rank=8) for Flux Kontext, enabling realistic product placement in photos.
This is a Flux Kontext LoRA but it uses a non-standard formulation and requires specific input preparation.
For that reason, it cannot be used with the official Diffusers pipeline. Here is how you can use it with uv instead:
HF_TOKEN=hf_aBcD1234 \
uv run --with git+https://github.com/finegrain-ai/finegrain-toolbox \
python foo.py
from pathlib import Path
import torch
from finegrain_toolbox.flux import Model, TextEncoder
from finegrain_toolbox.processors import product_placement
from huggingface_hub import hf_hub_download
from PIL import Image
device = torch.device("cuda")
dtype = torch.bfloat16
model = Model.from_pretrained(
"black-forest-labs/FLUX.1-Kontext-dev",
device=device,
dtype=dtype,
)
text_encoder = TextEncoder.from_pretrained(
"black-forest-labs/FLUX.1-Kontext-dev",
device=device,
dtype=dtype,
)
lora_path = Path(
hf_hub_download(
repo_id="finegrain/finegrain-product-placement-lora",
filename="finegrain-placement-v1-rank8.safetensors",
)
)
prompt = text_encoder.encode("Add this in the box")
model.transformer.load_lora_adapter(lora_path, adapter_name="inserter")
scene_image = Image.open("scene.webp")
reference = Image.open("reference.webp")
bbox = (1085, 1337, 1737, 3077)
result = product_placement.process(
model=model,
scene=scene_image,
reference=reference,
bbox=bbox,
prompt=prompt,
)
result.output.save("output.webp")
@misc{fg2025pplace,
author = {The Finegrain Team},
title = {Finegrain Product Placement LoRA},
year = {2025},
publisher = {HuggingFace},
}
Base model
black-forest-labs/FLUX.1-Kontext-dev