Train Stunning Custom Image Models with zylim0702/sdxl-lora-customize-training

22 Apr 2025
Train Stunning Custom Image Models with zylim0702/sdxl-lora-customize-training

In the world of image generation, harnessing the power of custom models can significantly enhance the creative process. The zylim0702/sdxl-lora-customize-training API provides a streamlined way to train your own Lora models, enabling you to generate beautiful 1024x1024 visuals using your own image datasets. By utilizing Low-Rank Adaptation (LoRA), you can efficiently fine-tune models to create stunning images tailored to your specifications. In this blog post, we will explore how to leverage the "Train Custom Lora Image Model" action to achieve your image generation goals.

Prerequisites

Before you start using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic understanding of JSON and API interaction.
  • A dataset of images prepared in a .zip or .tar format, accessible via a URI.

Authentication typically involves passing your API key in the request headers, ensuring secure access to the service.

Cognitive Actions Overview

Train Custom Lora Image Model

The Train Custom Lora Image Model action allows you to train a custom Lora model using your image dataset. This action is particularly useful for developers looking to create unique visual content that aligns with specific requirements.

Input

The input for this action requires a structured JSON payload. Below are the essential fields:

  • inputImageFiles (required): A URI link to a .zip or .tar file containing images for fine-tuning purposes.
  • seed (optional): An integer for initializing the random number generator.
  • verbose (optional): Enables detailed logging output (default: true).
  • resolution (optional): The pixel resolution for training (default: 768).
  • loraRankValue (optional): Rank of LoRA embeddings (default: 32).
  • useLoraTraining (optional): Specifies whether to use LoRA training (default: true).
  • loraLearningRate (optional): Learning rate for LoRA embeddings (default: 0.0001).
  • trainingBatchSize (optional): Batch size for training (default: 4).
  • uniqueTokenString (optional): A distinct string for concept identification (default: "TOK").
  • maxTrainSteps (optional): Maximum number of training steps (default: 1000).
  • numberOfTrainingEpochs (optional): Number of epochs (default: 4000).
  • Additional fields for advanced configurations are available.

Here’s an example input payload:

{
  "verbose": true,
  "resolution": 768,
  "loraRankValue": 32,
  "inputImageFiles": "https://replicate.delivery/pbxt/JNkYrCKwBoZ1ZSs5JgkXJuKhSfmSIORzOwNFuVDn9pIMi8Xl/barbie.zip",
  "useLoraTraining": true,
  "loraLearningRate": 0.0001,
  "trainingBatchSize": 4,
  "uniqueTokenString": "TOK",
  "maximumTrainingSteps": 1000,
  "numberOfTrainingEpochs": 4000
}

Output

Upon successful execution, the action typically returns a URI link to the generated model or a tar file containing the training results. Here’s a sample output:

https://assets.cognitiveactions.com/invocations/8d50e6b5-3557-4048-9657-b14dc3a9a864/e2b792ba-aa4d-4b40-af62-a2f4dae7286a.tar

Conceptual Usage Example (Python)

Below is a conceptual Python snippet demonstrating how to invoke the Train Custom Lora Image Model action. Note that the endpoint and request structure are illustrative.

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"  # Hypothetical endpoint

action_id = "30c38a78-c8be-4f5c-ba36-47dd88d50683"  # Action ID for Train Custom Lora Image Model

# Construct the input payload based on the action's requirements
payload = {
    "verbose": true,
    "resolution": 768,
    "loraRankValue": 32,
    "inputImageFiles": "https://replicate.delivery/pbxt/JNkYrCKwBoZ1ZSs5JgkXJuKhSfmSIORzOwNFuVDn9pIMi8Xl/barbie.zip",
    "useLoraTraining": true,
    "loraLearningRate": 0.0001,
    "trainingBatchSize": 4,
    "uniqueTokenString": "TOK",
    "maximumTrainingSteps": 1000,
    "numberOfTrainingEpochs": 4000
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload}  # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and input payload should be structured as shown.

Conclusion

Utilizing the Train Custom Lora Image Model action from the zylim0702/sdxl-lora-customize-training API can empower your applications with advanced image generation capabilities. By leveraging your own datasets, you can create unique visuals tailored to your needs. Now that you have a clear understanding of how to implement this action, consider exploring additional configurations or integrating other functionalities as your next step in enhancing your image generation projects!