# Qwen Image Layered Trainer

> Train LoRAs for the Qwen-Image-Layered model, customize how images are split into layers.


## Overview

- **Endpoint**: `https://fal.run/fal-ai/qwen-image-layered-trainer`
- **Model ID**: `fal-ai/qwen-image-layered-trainer`
- **Category**: training
- **Kind**: training
**Tags**: qwen, layer, trainer



## Pricing

The training cost depends on the number of steps and the number of layers. The formula is
**0.00425 × steps × num_of_layers**. Here, **num_of_layers** refers to the maximum number of layers per image in the dataset. For example, with 5 layers and 1,000 steps, the total cost will be **$21.25**.

For more details, see [fal.ai pricing](https://fal.ai/pricing).

## API Information

This model can be used via our HTTP API or more conveniently via our client libraries.
See the input and output schema below, as well as the usage examples.


### Input Schema

The API accepts the following input parameters:


- **`image_data_url`** (`string`, _required_):
  URL to the input data zip archive.
  
  The zip should contain groups of images. The images should be named:
  
  ROOT_start.EXT, ROOT_end.EXT, ROOT_end2.EXT, ..., ROOT_endN.EXT
  For example:
  photo_start.png, photo_end.png, photo_end2.png, ..., photo_endN.png
  
  The start image is the base image that will be decomposed into layers.
  The end images are the layers that will be added to the base image.  ROOT_end.EXT is the first layer, ROOT_end2.EXT is the second layer, and so on.
  You can have up to 8 layers.
  All image groups must have the same number of output layers.
  
  The end images can contain transparent regions. Only PNG and WebP images are supported since these are the only formats that support transparency.
  
  The zip can also contain a text file for each image group. The text file should be named:
  ROOT.txt
  For example:
  photo.txt
  
  This text file can be used to specify a description of the base image.
  
  If no text file is provided, the default_caption will be used.
  
  If no default_caption is provided, the training will fail.

- **`learning_rate`** (`float`, _optional_):
  Learning rate for LoRA parameters. Default value: `0.0001`
  - Default: `0.0001`

- **`steps`** (`integer`, _optional_):
  Number of steps to train for Default value: `1000`
  - Default: `1000`
  - Range: `100` to `10000`, step: `100`

- **`default_caption`** (`string`, _optional_):
  Default caption to use when caption files are missing. If None, missing captions will cause an error.



**Required Parameters Example**:

```json
{
  "image_data_url": ""
}
```

**Full Example**:

```json
{
  "image_data_url": "",
  "learning_rate": 0.0001,
  "steps": 1000
}
```


### Output Schema

The API returns the following output format:

- **`diffusers_lora_file`** (`File`, _required_):
  URL to the trained diffusers lora weights.

- **`config_file`** (`File`, _required_):
  URL to the configuration file for the trained model.



**Example Response**:

```json
{
  "diffusers_lora_file": {
    "url": "",
    "content_type": "image/png",
    "file_name": "z9RV14K95DvU.png",
    "file_size": 4404019
  },
  "config_file": {
    "url": "",
    "content_type": "image/png",
    "file_name": "z9RV14K95DvU.png",
    "file_size": 4404019
  }
}
```


## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://fal.run/fal-ai/qwen-image-layered-trainer \
  --header "Authorization: Key $FAL_KEY" \
  --header "Content-Type: application/json" \
  --data '{
     "image_data_url": ""
   }'
```

### Python

Ensure you have the Python client installed:

```bash
pip install fal-client
```

Then use the API client to make requests:

```python
import fal_client

def on_queue_update(update):
    if isinstance(update, fal_client.InProgress):
        for log in update.logs:
           print(log["message"])

result = fal_client.subscribe(
    "fal-ai/qwen-image-layered-trainer",
    arguments={
        "image_data_url": ""
    },
    with_logs=True,
    on_queue_update=on_queue_update,
)
print(result)
```

### JavaScript

Ensure you have the JavaScript client installed:

```bash
npm install --save @fal-ai/client
```

Then use the API client to make requests:

```javascript
import { fal } from "@fal-ai/client";

const result = await fal.subscribe("fal-ai/qwen-image-layered-trainer", {
  input: {
    image_data_url: ""
  },
  logs: true,
  onQueueUpdate: (update) => {
    if (update.status === "IN_PROGRESS") {
      update.logs.map((log) => log.message).forEach(console.log);
    }
  },
});
console.log(result.data);
console.log(result.requestId);
```


## Additional Resources

### Documentation

- [Model Playground](https://fal.ai/models/fal-ai/qwen-image-layered-trainer)
- [API Documentation](https://fal.ai/models/fal-ai/qwen-image-layered-trainer/api)
- [OpenAPI Schema](https://fal.ai/api/openapi/queue/openapi.json?endpoint_id=fal-ai/qwen-image-layered-trainer)

### fal.ai Platform

- [Platform Documentation](https://docs.fal.ai)
- [Python Client](https://docs.fal.ai/clients/python)
- [JavaScript Client](https://docs.fal.ai/clients/javascript)
