API Reference
Complete API reference for OpenTryOn modules.
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 imagesoutputs_dir(str): Directory to save segmented maskscls(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 imagesoutputs_dir(str): Directory to save extracted garmentscls(str): Garment classresize_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 imageoutput_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 objectcls(str): Garment classresize_to_width(int, optional): Resize output widthnet(torch.nn.Module, optional): Pre-loaded U2Net modeldevice(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.Tensorfit(args)- Start trainingprepare(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 toSEGMIND_API_KEYenvironment variable
Methods:
generate(model_image, cloth_image, category, ...)- Generate virtual try-on imagesgenerate_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 toKLING_AI_API_KEYenvironment variablesecret_key(str, optional): Kling AI secret key. Defaults toKLING_AI_SECRET_KEYenvironment variablebase_url(str, optional): Base URL for API. Defaults toKLING_AI_BASE_URLor 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 Imagesquery_task_status(task_id)- Query task statuspoll_task_until_complete(task_id, ...)- Poll task until completion
See Kling AI API Documentation for complete details.
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 toAMAZON_NOVA_REGIONor'us-east-1'
Methods:
generate(source_image, reference_image, mask_type, garment_class, ...)- Generate virtual try-on imagesgenerate_and_decode(source_image, reference_image, mask_type, garment_class, ...)- Generate and decode to PIL Images
See Nova Canvas API 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 toGEMINI_API_KEYenvironment variable
Methods:
generate_text_to_image(prompt, aspect_ratio, ...)- Generate images from textgenerate_image_edit(image, prompt, aspect_ratio, ...)- Edit images with text promptsgenerate_multi_image(images, prompt, aspect_ratio, ...)- Compose multiple imagesgenerate_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 toGEMINI_API_KEYenvironment variable
Methods:
generate_text_to_image(prompt, resolution, aspect_ratio, use_search_grounding, ...)- Generate images from textgenerate_image_edit(image, prompt, resolution, aspect_ratio, ...)- Edit images with text promptsgenerate_multi_image(images, prompt, resolution, aspect_ratio, ...)- Compose multiple imagesgenerate_batch(prompts, resolution, aspect_ratio, ...)- Batch generation
See Nano Banana 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 imageoutput_dir(str): Directory to save converted JPGsize(tuple, optional): Desired output size (width, height)
For complete API documentation, see individual module documentation.