Skip to main content

API Reference

Complete API reference for OpenTryOn modules. Current package: v0.0.5.

Models are also available through the unified CLI, MCP server, and (for upstream media HTTP) OpenAPI / Postman snapshots:

Preprocessing API​

segment_garment​

Segment garments from images using U2Net model.

from tryon.preprocessing import segment_garment

segment_garment(
inputs_dir: str,
outputs_dir: str,
cls: str = "all"
)

Parameters:

  • inputs_dir (str): Directory containing input garment images
  • outputs_dir (str): Directory to save segmented masks
  • cls (str): Garment class. Options: "upper", "lower", "dress", "all"

Returns: None (saves masks to output directory)


extract_garment​

Extract garments from images and prepare for virtual try-on.

from tryon.preprocessing import extract_garment

extract_garment(
inputs_dir: str,
outputs_dir: str,
cls: str = "all",
resize_to_width: Optional[int] = None
)

Parameters:

  • inputs_dir (str): Directory containing input garment images
  • outputs_dir (str): Directory to save extracted garments
  • cls (str): Garment class
  • resize_to_width (int, optional): Resize output width

Returns: None (saves extracted garments)


segment_human​

Segment human subjects from images.

from tryon.preprocessing import segment_human

segment_human(
image_path: str,
output_dir: str
)

Parameters:

  • image_path (str): Path to input human image
  • output_dir (str): Directory to save segmented mask

Returns: None (saves mask as PNG)


extract_garment (Single Image)​

Extract garment from a single PIL Image object.

from tryon.preprocessing.extract_garment_new import extract_garment
from PIL import Image

garments = extract_garment(
image: Image.Image,
cls: str = "all",
resize_to_width: Optional[int] = None,
net: Optional[torch.nn.Module] = None,
device: Optional[torch.device] = None
)

Parameters:

  • image (PIL.Image): Input image object
  • cls (str): Garment class
  • resize_to_width (int, optional): Resize output width
  • net (torch.nn.Module, optional): Pre-loaded U2Net model
  • device (torch.device, optional): Device to run inference on

Returns: Dict[str, PIL.Image] - Dictionary mapping garment class names to PIL Image objects


TryOnDiffusion API​

Diffusion​

Main diffusion model class.

from tryondiffusion.diffusion import Diffusion

diffusion = Diffusion(
device: torch.device,
pose_embed_dim: int,
time_steps: int = 256,
beta_start: float = 1e-4,
beta_end: float = 0.02,
unet_dim: int = 64,
noise_input_channel: int = 3,
beta_ema: float = 0.995
)

Methods:

  • sample(use_ema: bool, conditional_inputs: tuple) -> torch.Tensor
  • fit(args) - Start training
  • prepare(args) - Prepare data and optimizer

See TryOnDiffusion Documentation for details.


Virtual Try-On API Adapters​

SegmindVTONAdapter​

Adapter for Segmind Try-On Diffusion API for virtual try-on generation.

from tryon.api import SegmindVTONAdapter

adapter = SegmindVTONAdapter(api_key="your_api_key")

images = adapter.generate_and_decode(
model_image="person.jpg",
cloth_image="garment.jpg",
category="Upper body"
)

Parameters:

  • api_key (str, optional): Segmind API key. Defaults to SEGMIND_API_KEY environment variable

Methods:

  • generate(model_image, cloth_image, category, ...) - Generate virtual try-on images
  • generate_and_decode(model_image, cloth_image, category, ...) - Generate and decode to PIL Images

See Segmind API Documentation for complete details.


KlingAIVTONAdapter​

Adapter for Kling AI Kolors Virtual Try-On API with asynchronous processing.

from tryon.api import KlingAIVTONAdapter

adapter = KlingAIVTONAdapter(api_key="your_api_key", secret_key="your_secret_key")

images = adapter.generate_and_decode(
source_image="person.jpg",
reference_image="garment.jpg",
model="kolors-virtual-try-on-v1-5"
)

Parameters:

  • api_key (str, optional): Kling AI API key. Defaults to KLING_AI_API_KEY environment variable
  • secret_key (str, optional): Kling AI secret key. Defaults to KLING_AI_SECRET_KEY environment variable
  • base_url (str, optional): Base URL for API. Defaults to KLING_AI_BASE_URL or Singapore endpoint

Methods:

  • generate(source_image, reference_image, model, ...) - Generate virtual try-on images (returns URLs)
  • generate_and_decode(source_image, reference_image, model, ...) - Generate and decode to PIL Images
  • query_task_status(task_id) - Query task status
  • poll_task_until_complete(task_id, ...) - Poll task until completion

See Kling AI API Documentation for complete details.


GoogleVTONAdapter​

Dedicated Vertex AI Virtual Try-On (virtual-try-on-001). Person + product images; not Gemini API / Nano Banana.

from tryon.api import GoogleVTONAdapter

adapter = GoogleVTONAdapter() # GOOGLE_CLOUD_PROJECT + ADC

images = adapter.generate_and_decode(
person="person.jpg",
garment="sweater.jpg",
number_of_images=1,
)

Parameters:

  • project (str, optional): GCP project. Defaults to GOOGLE_CLOUD_PROJECT
  • location (str, optional): Vertex location. Defaults to GOOGLE_CLOUD_LOCATION or global

Methods:

  • generate_and_decode(person, garment, ...) - Generate and decode to PIL Images

See Google Virtual Try-On for auth, CLI, and MCP.


OutfitAnyonePlusAdapter​

Dedicated Alibaba DashScope try-on (aitryon-plus). Beijing-region key. Not Qwen-Image composition.

from tryon.api import OutfitAnyonePlusAdapter

adapter = OutfitAnyonePlusAdapter() # DASHSCOPE_API_KEY (Beijing)

images = adapter.generate_and_decode(
person="person.jpg",
garment="top.jpeg",
)

Parameters:

  • api_key (str, optional): Defaults to DASHSCOPE_API_KEY
  • base_url (str, optional): Defaults to OUTFITANYONE_BASE_URL or China DashScope

Methods:

  • generate_and_decode(person, garment, top_garment=..., bottom_garment=..., restore_face=True, resolution=-1)

See OutfitAnyone-Plus for auth, CLI, and MCP.


PhotoroomVTONAdapter​

Photoroom Image Editing API — shopper Virtual Try-On and catalog Virtual Model (POST /v2/edit).

from tryon.api import PhotoroomVTONAdapter

adapter = PhotoroomVTONAdapter() # PHOTOROOM_API_KEY
worn = adapter.generate_and_decode(person="selfie.jpg", garment="dress.jpg")
catalog = adapter.generate_virtual_model(garment="flatlay.jpg", preset_model="avery")

Parameters:

  • api_key (str, optional): Defaults to PHOTOROOM_API_KEY
  • base_url (str, optional): Defaults to PHOTOROOM_BASE_URL or https://image-api.photoroom.com

Methods:

  • generate_and_decode(person, garment, mode="try-on", ...)
  • generate_virtual_model(garment, ...)

See Photoroom for auth, CLI, and MCP.


LeffaAdapter / CatVTONAdapter​

Dedicated local virtual try-on (GPU, pip install opentryon[local]). Not composition I2I.

from tryon.models import LeffaAdapter, CatVTONAdapter

LeffaAdapter().generate_and_decode("person.jpg", "garment.jpg")
CatVTONAdapter().generate_and_decode("person.jpg", "garment.jpg")

See Leffa and CatVTON. CatVTON weights are CC BY-NC-SA 4.0.


AmazonNovaCanvasVTONAdapter​

Adapter for Amazon Nova Canvas Virtual Try-On through AWS Bedrock.

from tryon.api import AmazonNovaCanvasVTONAdapter

adapter = AmazonNovaCanvasVTONAdapter(region="us-east-1")

images = adapter.generate_and_decode(
source_image="person.jpg",
reference_image="garment.jpg",
mask_type="GARMENT",
garment_class="UPPER_BODY"
)

Parameters:

  • region (str, optional): AWS region. Defaults to AMAZON_NOVA_REGION or 'us-east-1'

Methods:

  • generate(source_image, reference_image, mask_type, garment_class, ...) - Generate virtual try-on images
  • generate_and_decode(source_image, reference_image, mask_type, garment_class, ...) - Generate and decode to PIL Images

See Nova Canvas API Documentation for complete details.


PImageTryOnAdapter​

Adapter for Pruna AI's P-Image-Try-On API -- multi-garment virtual try-on (up to 11 garment reference images in one call). Lives under tryon.api.vton and shares tryon.api.pruna.client.PrunaClient with the newer P-Image / P-Video adapters in tryon.api.pruna.

from tryon.api.vton import PImageTryOnAdapter

adapter = PImageTryOnAdapter(api_key="your_api_key")

images = adapter.generate_and_decode(
person_image="person.jpg",
garment_images=["top.jpg", "bottoms.jpg"],
)

Parameters:

  • api_key (str, optional): Pruna API key. Defaults to PRUNA_API_KEY environment variable

Methods:

  • generate(person_image, garment_images, ...) - Generate a virtual try-on result (returns a URL)
  • generate_and_decode(person_image, garment_images, ...) - Generate and decode to PIL Images

See Pruna AI Documentation for complete details (also covers PImageAdapter, PImageIdeogramAdapter, PImageEditAdapter, PImageUpscaleAdapter, PVideoAdapter, PVideo2ProAdapter, PVideoReplaceAdapter, PVideoAvatarAdapter, PVideoAnimateAdapter). Dedicated page: P-Image-Ideogram.


FashnVTONAdapter​

Adapter for FASHN AI virtual try-on (tryon-max and tryon-v1.6). Lives under tryon.api.vton (use-case directory) rather than a dedicated tryon.api.fashn package.

from tryon.api.vton import FashnVTONAdapter

adapter = FashnVTONAdapter(api_key="your_api_key")

images = adapter.generate_and_decode(
model_image="person.jpg",
product_image="garment.jpg",
model_name="tryon-max",
resolution="2k",
)

Parameters:

  • api_key (str, optional): FASHN API key. Defaults to FASHN_API_KEY

Methods:

  • generate(model_image, product_image, model_name, ...) - Run try-on (returns URLs / data URIs)
  • generate_and_decode(model_image, product_image, model_name, ...) - Generate and decode to PIL Images

See FASHN AI Virtual Try-On Documentation for complete details.


Image Generation API Adapters​

NanoBananaAdapter​

Adapter for Gemini 2.5 Flash Image (Nano Banana) - fast and efficient image generation.

from tryon.api.nano_banana import NanoBananaAdapter

adapter = NanoBananaAdapter(api_key="your_api_key")

images = adapter.generate_text_to_image(
prompt="A nano banana dish in a fancy restaurant",
aspect_ratio="16:9"
)

Parameters:

  • api_key (str, optional): Google Gemini API key. Defaults to GEMINI_API_KEY environment variable

Methods:

  • generate_text_to_image(prompt, aspect_ratio, ...) - Generate images from text
  • generate_image_edit(image, prompt, aspect_ratio, ...) - Edit images with text prompts
  • generate_multi_image(images, prompt, aspect_ratio, ...) - Compose multiple images
  • generate_batch(prompts, aspect_ratio, ...) - Batch generation

See Nano Banana API Documentation for complete details.


NanoBananaProAdapter​

Adapter for Gemini 3 Pro Image Preview (Nano Banana Pro) - advanced image generation with 4K support.

from tryon.api.nano_banana import NanoBananaProAdapter

adapter = NanoBananaProAdapter(api_key="your_api_key")

images = adapter.generate_text_to_image(
prompt="A professional nano banana dish",
resolution="4K",
aspect_ratio="16:9",
use_search_grounding=True
)

Parameters:

  • api_key (str, optional): Google Gemini API key. Defaults to GEMINI_API_KEY environment variable

Methods:

  • generate_text_to_image(prompt, resolution, aspect_ratio, use_search_grounding, ...) - Generate images from text
  • generate_image_edit(image, prompt, resolution, aspect_ratio, ...) - Edit images with text prompts
  • generate_multi_image(images, prompt, resolution, aspect_ratio, ...) - Compose multiple images
  • generate_batch(prompts, resolution, aspect_ratio, ...) - Batch generation

See Nano Banana API Documentation for complete details.


NanoBanana2LiteAdapter​

Adapter for Gemini 3.1 Flash-Lite Image (Nano Banana 2 Lite) -- Google's fastest and cheapest Gemini image tier (1K resolution only). Also exposes generate_virtual_tryon(), a lightweight try-on convenience method built on multi-image composition (not the highest-fidelity option -- see the note in Nano Banana API Documentation).

from tryon.api.nano_banana import NanoBanana2LiteAdapter

adapter = NanoBanana2LiteAdapter(api_key="your_api_key")

images = adapter.generate_text_to_image(
prompt="A fashion model wearing a summer collection",
aspect_ratio="16:9",
)

# Lightweight virtual try-on
images = adapter.generate_virtual_tryon(
person="person.jpg",
garment="jacket.jpg",
garment_description="olive green bomber jacket",
)

Parameters:

  • api_key (str, optional): Google Gemini API key. Defaults to GEMINI_API_KEY environment variable

Methods:

  • generate_text_to_image(prompt, aspect_ratio, ...) - Generate images from text (1K only)
  • generate_image_edit(image, prompt, aspect_ratio, ...) - Edit images with text prompts
  • generate_multi_image(images, prompt, aspect_ratio, ...) - Compose multiple images
  • generate_virtual_tryon(person, garment, garment_description, ...) - Lightweight virtual try-on
  • generate_batch(prompts, aspect_ratio, ...) - Batch generation

See Nano Banana API Documentation for complete details.


Flux2ProAdapter​

Adapter for FLUX.2 [PRO] - high-quality image generation with standard controls.

from tryon.api import Flux2ProAdapter

adapter = Flux2ProAdapter(api_key="your_api_key")

images = adapter.generate_text_to_image(
prompt="A professional fashion model wearing elegant evening wear",
width=1024,
height=1024,
seed=42
)

Parameters:

  • api_key (str, optional): BFL API key. Defaults to BFL_API_KEY environment variable

Methods:

  • generate_text_to_image(prompt, width, height, seed, safety_tolerance, output_format, ...) - Generate images from text
  • generate_image_edit(prompt, input_image, width, height, seed, ...) - Edit images with text prompts
  • generate_multi_image(prompt, images, width, height, seed, ...) - Compose multiple images (up to 8)

See FLUX.2 API Documentation for complete details.


Flux2FlexAdapter​

Adapter for FLUX.2 [FLEX] - flexible image generation with advanced controls.

from tryon.api import Flux2FlexAdapter

adapter = Flux2FlexAdapter(api_key="your_api_key")

images = adapter.generate_text_to_image(
prompt="A stylish fashion model wearing elegant evening wear",
width=1024,
height=1024,
guidance=7.5, # Higher = more adherence to prompt (1.5-10)
steps=50, # More steps = higher quality
prompt_upsampling=True,
seed=42
)

Parameters:

  • api_key (str, optional): BFL API key. Defaults to BFL_API_KEY environment variable

Methods:

  • generate_text_to_image(prompt, width, height, seed, guidance, steps, prompt_upsampling, ...) - Generate images from text with advanced controls
  • generate_image_edit(prompt, input_image, width, height, seed, guidance, steps, ...) - Edit images with advanced controls
  • generate_multi_image(prompt, images, width, height, seed, guidance, steps, ...) - Compose multiple images with advanced controls

See FLUX.2 API Documentation for complete details.


GPTImageAdapter​

OpenAI Images API. Constructor / --model gpt-image default is GPT-Image-1.5. ChatGPT Images 2.5 is --model gpt-image-2.5 (Flare) and --model gpt-image-2.5-sunburst. Same OPENAI_API_KEY.

from tryon.api.openAI.image_adapter import GPTImageAdapter

adapter = GPTImageAdapter(model_version="gpt-image-2.5") # Flare
images = adapter.generate_text_to_image("editorial still, linen trench")

See GPT Image for sizes, quality (xhigh / max on 2.5), and edit / mask usage.


Video Generation API Adapters​

Also available via the CLI/MCP registry:

AdapterCLI modelDocs
SeedanceAdapterseedanceSeedance & Seedream
LumaRay32Adapterluma-ray-3.2Luma Ray 3.2
KlingVideoAdapterkling-v3 / kling-v3-omni / kling-v2-5-turboKling Video
GrokImagineVideoAdaptergrok-imagine-videoGrok Imagine
LTXVideoAdapterltx-2.5-apiLTX-2.5 API
HailuoVideoAdapterhailuo-2.3Hailuo
MiniMaxH3Adapterminimax-h3 / minimax-h3-maxMiniMax H3
FalH3MaxAdapterfal-h3-max / fal-h3-max-lipsyncMiniMax H3 Max (Fal)
PVideo2ProAdapterp-video-2-proPruna AI
WanVideoAdapterwan-api / wan-3.0Wan
RunwayVideoAdapterrunway-gen4.5Runway Gen-4.5
Cosmos3VideoAdaptercosmos3NVIDIA NIM
SoraVideoAdapter / VeoAdapter / LumaAIVideoAdaptersora / veo / luma-videoexisting pages

Local twins: LTX25Adapter (ltx-2.5), MiniMaxH3LocalAdapter (minimax-h3-local), Wan22Adapter (wan-2.2). Wan 3.0 is API-only.

Image counterparts: SeedreamAdapter (seedream), IdeogramAdapter (ideogram), PImageIdeogramAdapter (p-image-ideogram), GrokImagineImageAdapter (grok-imagine-image), MuseImageAdapter (muse-image). Muse Video has no API yet — see Muse Video.

GeminiOmniAdapter​

Adapter for Gemini Omni Flash (gemini-omni-flash-preview) -- multimodal video generation and conversational editing via the Interactions API.

from tryon.api.omni import GeminiOmniAdapter

adapter = GeminiOmniAdapter(api_key="your_api_key")

video = adapter.generate_text_to_video(
prompt="A fashion model walking a runway",
aspect_ratio="9:16",
)

Parameters:

  • api_key (str, optional): Google Gemini API key. Defaults to GEMINI_API_KEY

Methods:

  • generate_text_to_video(prompt, aspect_ratio, previous_interaction_id, ...) - Text-to-video (or edit turn)
  • generate_image_to_video(image, prompt, aspect_ratio, reference_images, ...) - Image-to-video
  • edit_video(prompt, previous_interaction_id, ...) - Conversational edit of a prior clip

See Gemini Omni Flash Documentation for complete details.


Multimodal Understanding API Adapters​

KimiUnderstandAdapter​

Adapter for Moonshot AI's Kimi K2.6, K2.7 Code, and K3 models -- general-purpose, natively multimodal image and video understanding (not limited to fashion).

from tryon.api import KimiUnderstandAdapter

adapter = KimiUnderstandAdapter() # kimi-k2.6 by default

result = adapter.understand_image(
"garment.jpg",
prompt="Describe this outfit: color, pattern, style, fit, and material."
)
print(result["text"])

Parameters:

  • api_key (str, optional): Moonshot API key. Defaults to MOONSHOT_API_KEY environment variable
  • model (str, optional): "kimi-k2.6" (default), "kimi-k2.7-code", "kimi-k2.7-code-highspeed", "kimi-k3", or "kimi-k2.5"

Methods:

  • understand_image(image, prompt, ...) - Understand one or more images
  • understand_video(video, prompt, ...) - Understand video content
  • understand(image=None, video=None, prompt=...) - Single entry point accepting either/both
  • chat(messages, tools=None, ...) - Multi-turn/tool-calling escape hatch

See Kimi API Documentation for complete details, or the open-weight Kimi-VL local model for GPU-only deployment.


GLMUnderstandAdapter​

Adapter for Zhipu's GLM-5.3-FlashX via Z.ai — general-purpose, natively multimodal image and video understanding (200 tok/s serving tier of GLM-5.3-Flash).

from tryon.api import GLMUnderstandAdapter

adapter = GLMUnderstandAdapter() # glm-5.3-flashx by default

result = adapter.understand_image(
"garment.jpg",
prompt="Describe this outfit: color, pattern, style, fit, and material."
)
print(result["text"])

Parameters:

  • api_key (str, optional): Z.ai key. Defaults to ZAI_API_KEY environment variable
  • model (str, optional): "glm-5.3-flashx" (default)
  • base_url (str, optional): Defaults to ZAI_BASE_URL or the Z.ai default

Methods:

  • understand_image(image, prompt, ...) - Understand one or more images
  • understand_video(video, prompt, ...) - Understand video content
  • understand(image=None, video=None, prompt=...) - Single entry point accepting either/both

Thinking is always on (thinking.type only supports enabled); use reasoning_effort (low / high / max) to control depth.

See GLM-5.3-FlashX Documentation for complete details.


QwenUnderstandAdapter​

Adapter for Alibaba DashScope Qwen3.8-Max and Qwen3.8-Omni-Flash — native multimodal understanding (text + image + video → text on Max; text + image + audio + video → text on Omni-Flash) with thinking / reasoning_effort. OpenTryOn exposes the understand path (plus chat() for multi-turn/tools on Max).

from tryon.api import QwenUnderstandAdapter

adapter = QwenUnderstandAdapter() # qwen3.8-max by default

result = adapter.understand_image(
"garment.jpg",
prompt="Describe this outfit: color, pattern, style, fit, and material."
)
print(result["text"])

Parameters:

  • api_key (str, optional): Defaults to DASHSCOPE_API_KEY
  • model (str, optional): "qwen3.8-max" (default) or "qwen3.8-omni-flash"
  • base_url (str, optional): Defaults to QWEN_BASE_URL or the international DashScope compatible-mode URL

Methods:

  • understand_image(image, prompt, ...) - Understand one or more images
  • understand_video(video, prompt, ...) - Understand video content
  • understand(image=None, video=None, audio=None, prompt=...) - Single entry point; audio requires model="qwen3.8-omni-flash"
  • chat(messages, tools=None, ...) - Multi-turn/tool-calling escape hatch

Series capabilities (vendor): ~1M context on Max, long video, coding/agent strengths, structured output and built-in tools on DashScope. Local open counterpart: qwen3.8 (Qwen/Qwen3.8-27B).

See Qwen3.8-Max API Documentation for complete details, or the open-weight Qwen3.8 local model for GPU-only deployment.


Hy4Adapter​

Tencent Hy4 preview (770B MoE LLM) via TokenHub or a local vLLM/SGLang OpenAI server. Same class for --model hy4-preview and hy4-preview-local.

from tryon.api import Hy4Adapter

adapter = Hy4Adapter() # TOKENHUB_API_KEY
result = adapter.understand(prompt="Write a lookbook caption for a linen trench.")
print(result["text"])

See Hy4 TokenHub and Hy4 local.


NemotronOmniUnderstandAdapter / Cosmos3ReasonerAdapter / Cosmos3VideoAdapter​

NVIDIA NIM Path A (NVIDIA_API_KEY). Omni and Reasoner are OpenAI-compatible chat understand models; Cosmos 3 Generator is T2V/I2V infer (b64_video).

from tryon.api.nvidia import NemotronOmniUnderstandAdapter, Cosmos3VideoAdapter

print(NemotronOmniUnderstandAdapter().understand(image="garment.jpg")["text"])
mp4 = Cosmos3VideoAdapter().generate_text_to_video("runway walk at dusk")

See NVIDIA NIM.


QwenImageAdapter​

Adapter for Alibaba DashScope Qwen-Image 3.0 — text-to-image, image editing (1–3 refs), and person+garment virtual try-on. Same DASHSCOPE_API_KEY as QwenUnderstandAdapter.

from tryon.api import QwenImageAdapter

adapter = QwenImageAdapter() # qwen-image-3.0-pro by default
images = adapter.generate_text_to_image("editorial lookbook, linen trench")
tryon = adapter.generate_virtual_tryon("person.jpg", "garment.jpg")

Parameters:

  • api_key (str, optional): Defaults to DASHSCOPE_API_KEY
  • model (str, optional): "qwen-image-3.0-pro" (default), "qwen-image-3.0", "qwen-image-2.0-pro", "qwen-image-2.0"
  • base_url (str, optional): Defaults to QWEN_IMAGE_BASE_URL or the international DashScope /api/v1 host

Methods:

  • generate_text_to_image(prompt, size=None, n=1, ...) — T2I
  • generate_image_edit(image, prompt, ...) — I2I (one image or a list of 1–3)
  • generate_multi_image(images, prompt, ...) — I2I composition
  • generate_virtual_tryon(person, garment, garment_description=None, ...) — VTON wrapper

CLI: opentryon generate|edit|vton --model qwen-image. Pair with understand --model qwen3.8-max to caption a garment first. Local twin: QwenImageLocalAdapter / --model qwen-image-local (local docs).

See Qwen-Image API Documentation for complete details.


Background Removal API​

BEN2BackgroundRemoverAdapter​

Adapter for BEN2 (Background Erase Network 2) - state-of-the-art background removal for fashion and product images.

from tryon.api.ben2 import BEN2BackgroundRemoverAdapter

adapter = BEN2BackgroundRemoverAdapter()

# Single image background removal
result = adapter.remove_background("model.jpg", refine=True)
result[0].save("model_no_bg.png")

# Batch processing
results = adapter.remove_background_batch(
["model1.jpg", "model2.jpg", "model3.jpg"],
refine=True
)

Parameters:

  • weights_path (str, optional): Custom weights path. Auto-downloads from Hugging Face if not specified
  • device (str, optional): Device to use ("cuda" or "cpu"). Auto-detected if not specified

Methods:

  • remove_background(image, refine=False) - Remove background from single image
  • remove_background_batch(images, refine=False) - Remove background from multiple images
  • load_image(input_data) - Load image from path, URL, or BytesIO

Features:

  • Automatic weight download from Hugging Face
  • GPU acceleration with CUDA support
  • Foreground refinement for higher quality edges
  • Batch processing for multiple images
  • Supports file paths, URLs, BytesIO, and PIL Images

See BEN2 API Documentation for complete details.


Utility Functions​

convert_to_jpg​

Convert image to JPG format.

from tryon.preprocessing import convert_to_jpg

convert_to_jpg(
image_path: str,
output_dir: str,
size: Optional[tuple] = None
)

Parameters:

  • image_path (str): Path to input image
  • output_dir (str): Directory to save converted JPG
  • size (tuple, optional): Desired output size (width, height)

For complete API documentation, see individual module documentation.