|
|
--- |
|
|
tags: |
|
|
- text-to-image |
|
|
- lora |
|
|
- diffusers |
|
|
- template:sd-lora |
|
|
- flux |
|
|
- consumer-products |
|
|
widget: |
|
|
- text: > |
|
|
Item name: alphonso mango milk shake tetra pack with labels |
|
|
output: |
|
|
url: images/mango.png |
|
|
- text: > |
|
|
Item Name: set of 6 different flavored lays pack |
|
|
output: |
|
|
url: images/lays.png |
|
|
- text: > |
|
|
Item Name: Bhuja Cracker Mix, 7-ounce Bags, vegan & vegetarian |
|
|
output: |
|
|
url: images/bhuja_mix.png |
|
|
- text: > |
|
|
Item Name: hotwheels car ratrod packed |
|
|
output: |
|
|
url: images/hotwheels.png |
|
|
base_model: black-forest-labs/FLUX.1-dev |
|
|
license: mit |
|
|
datasets: |
|
|
- SoumilB7/consumer-product-50 |
|
|
--- |
|
|
|
|
|
<Gallery /> |
|
|
|
|
|
# LoRA — Consumer Product Photography (FLUX) |
|
|
|
|
|
Hello guys I fine-tuned **FLUX.1-dev LoRA** to generate **high-quality consumer product photography**. |
|
|
|
|
|
Designed for: |
|
|
|
|
|
* Product ideation |
|
|
* Packaging & branding mocks |
|
|
* CPG & D2C marketing visuals |
|
|
* Studio-style commercial lighting |
|
|
* Sharp labels, accurate materials, clean backgrounds |
|
|
|
|
|
Optimized for **bottles, cans, tetra packs, cosmetics, beverages, food products**. |
|
|
Purpose-built for **product shoots & concept ideation**, not general art. |
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
## Usage |
|
|
|
|
|
**Load & fuse LoRA into FLUX.1-dev (4-bit NF4)** |
|
|
|
|
|
```python |
|
|
from diffusers import FluxPipeline, AutoPipelineForText2Image, FluxTransformer2DModel, BitsAndBytesConfig |
|
|
from transformers import T5EncoderModel |
|
|
from transformers import BitsAndBytesConfig as TransformersBitsAndBytesConfig |
|
|
import torch |
|
|
import gc |
|
|
|
|
|
ckpt_id = "black-forest-labs/FLUX.1-dev" |
|
|
lora_path = "SoumilB7/consumer-product-flux" |
|
|
fused_transformer_path = "fused_transformer" |
|
|
|
|
|
bnb_4bit_compute_dtype = torch.float16 |
|
|
|
|
|
nf4_config = BitsAndBytesConfig( |
|
|
load_in_4bit=True, |
|
|
bnb_4bit_quant_type="nf4", |
|
|
bnb_4bit_compute_dtype=bnb_4bit_compute_dtype, |
|
|
) |
|
|
|
|
|
transformer = FluxTransformer2DModel.from_pretrained( |
|
|
ckpt_id, subfolder="transformer", |
|
|
quantization_config=nf4_config, torch_dtype=torch.float16 |
|
|
) |
|
|
|
|
|
quant_config = TransformersBitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.float16) |
|
|
|
|
|
text_encoder = T5EncoderModel.from_pretrained( |
|
|
ckpt_id, subfolder="text_encoder_2", quantization_config=quant_config, torch_dtype=torch.float16, |
|
|
) |
|
|
|
|
|
pipeline = FluxPipeline.from_pretrained( |
|
|
ckpt_id, |
|
|
transformer=transformer, |
|
|
text_encoder_2=text_encoder, |
|
|
torch_dtype=bnb_4bit_compute_dtype, |
|
|
) |
|
|
|
|
|
pipeline.load_lora_weights(lora_path) |
|
|
pipeline.fuse_lora() |
|
|
pipeline.unload_lora_weights() |
|
|
|
|
|
del text_encoder |
|
|
del transformer |
|
|
gc.collect() |
|
|
torch.cuda.empty_cache() |
|
|
|
|
|
pipeline.to("cuda") |
|
|
``` |
|
|
|
|
|
### Generate image |
|
|
|
|
|
```python |
|
|
prompt = "alphonso mango milkshake tetra pack with label, studio softbox lighting, clean background" |
|
|
image = pipeline( |
|
|
prompt, |
|
|
num_inference_steps=28, |
|
|
guidance_scale=3.5, |
|
|
height=768, |
|
|
width=512, |
|
|
generator=torch.manual_seed(0) |
|
|
).images[0] |
|
|
|
|
|
print(f"Pipeline memory usage: {torch.cuda.max_memory_reserved() / 1024**3:.3f} GB") |
|
|
image.save("product_example.png") |
|
|
image |
|
|
``` |
|
|
|
|
|
--- |
|
|
|
|
|
## Notes |
|
|
|
|
|
* Best for **studio product shots**, minimal environments |
|
|
* Works extremely well with **simple, commercial descriptors** |
|
|
* Ideal for **brands, founders, designers, packaging artists** |
|
|
|
|
|
--- |
|
|
|
|
|
Would you like: |
|
|
|
|
|
1. a **“Prompt Guide”** section like Flux Realism models? |
|
|
2. a **Before → After grid** for the dataset vs model output? |
|
|
3. a **Colab notebook** link block? |
|
|
|
|
|
|
|
|
|