Skip to main content

Train a Lora Model with Custom Images

Overview

Using this endpoint you can train a Lora model with your own images. You can train a model on any object or person.

Request

--request POST 'https://stablediffusionapi.com/api/v3/lora_fine_tune' \

Make a POST request to https://stablediffusionapi.com/api/v3/lora_fine_tune endpoint and pass the required parameters as a request body.

For now, you can only train a model on normal lora models and sdxl and get its style.

Body Attributes

ParameterDescription
keyYour API Key used for request authorization
instance_promptText prompt with how you want to call your trained person/object
class_promptClassification of the trained person/object
base_model_typeThe type of lora base model you want to train on. It accepts normal or sdxl
negative_promptItems you don't want in the image
imagesPass accessible direct links to images, cropped to 512 x 512 px. A good number is about 7-8 images.
training_typeThe type of the object you are training on
lora_typeIt accepts lora or lycoris
max_train_stepsSet it at 2 times the number of images (Ni*2; maximum value 2000)
webhookGet a post call when training is complete

Training Types

The table below lists all the possible values for the training_type parameter.

ValueDescription
menTrain on faces of men.
femaleTrain on faces of females.
coupleTrain on couples of male and female; in images array pass images of couples, instead of images of a single person.
nullTrain on object or anything.

Webhook Post JSON

This is an example webhook post call in JSON format.

{
"status": "success",
"training_status": "deploying_gpu",
"logs": "it will take upto 25 minutes",
"model_id": "F5jvdzGnYi",
}

Training Status Values

The table below describes all possible training statuses.

StatusDescription
deploying_gpuDeploying GPU
training_startedTraining started
training_successTraining completed successfully
trained_model_compressingCompressing the trained model
trained_model_uploadingUploading the trained model
trained_model_uploadedTrained model uploaded
deploying_modelDeploying the trained model
model_readyThe trained model is ready for use

Example

Body

Body
{
"key":"",
"instance_prompt": "photo of ambika0 man",
"class_prompt": "photo of a man",
"base_model_type": "sdxl",
"negative_prompt":" lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry",
"images": [
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/1.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/2.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/3.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/4.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/5.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/6.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/7.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/8.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/9.png"
],
"seed": "0",
"training_type": "men",
"max_train_steps": "2",
"lora_type":"lora",
"webhook": null
}

Request

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
"key":"",
"instance_prompt": "photo of ambika0 man",
"class_prompt": "photo of a man",
"base_model_type": "sdxl",
"negative_prompt":" lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry",
"images": [
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/1.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/2.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/3.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/4.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/5.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/6.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/7.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/8.png",
"https://raw.githubusercontent.com/pnavitha/sampleImages/master/9.png"
],
"seed": "0",
"training_type": "men",
"max_train_steps": "2",
"lora_type":"lora",
"webhook": null
});

var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};

fetch("https://stablediffusionapi.com/api/v3/lora_fine_tune", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));

Response

{
"status": "success",
"messege": "deploying_gpu",
"data": "it will take upto 30 minutes.",
"training_id": "F5jvdzGnYi"
}