Fine-tuning a model for AI-generated images can seem like a daunting task, but MyMoodAI makes it simple. In this quick guide, we’ll show you how to create a training order, upload selfies, and run the training using Python. By the end, you’ll have a personalized AI model ready to generate unique, custom images.
1. Introduction
MyMoodAI’s Python client library provides a convenient way to interact with the REST API without manually handling HTTP requests. You can:
- Create new models (training orders)
- Upload selfies (training images)
- Run the training process
- Check the status of each step
Let’s walk through these steps using the Python code snippet below.
2. Setting Up the Environment
Install the Python SDK
If you’re using a local environment, ensure you have the mymoodai
Python package installed. For demonstration, assume it’s available as:
1 2 |
Download the MyMoodAI SDK from Github. |
(If you have a custom installation, follow the specific instructions provided by MyMoodAI’s documentation or GitHub repo.)
Import the Client
In your Python script or notebook, make sure you import the MyMoodAIClient:
1 2 |
from mymoodai import MyMoodAIClient |
Authentication
You’ll need an API key from MyMoodAI to authenticate your requests. Place it in the constructor when instantiating the client:
1 2 |
client = MyMoodAIClient(base_url=“https://api.mymoodai.app/rest/api”, api_key=“YOUR_API_KEY”) |
3. Creating a New Model (Training Order)
A model in MyMoodAI terminology is essentially an order with parent=0
. This indicates you’re about to train a fresh model (as opposed to generating images from an existing model).
1 2 3 4 5 6 7 |
model_payload = { “styles”: [112, 5, 2572, 1421, 2214, 947, 2570, 94, 356, 43], “gender”: 1 # 1 for woman, 2 for man } model = client.create_model(model_payload) |
styles
: A list of numeric style IDs that define how your final images will look.gender
: An integer value;1
for woman,2
for man.
The response, stored in model
, will typically include an id
field you need for subsequent steps:
1 2 |
print(model[”id”]) |
4. Uploading a Selfie for Training
Now that the model order is created, you can upload selfies. These images help MyMoodAI learn how to generate images that resemble the person you’re training on.
1 2 |
client.upload_training_image(order_id=model[”id”], image_path=”selfie.jpg”, gender=1) |
order_id
: The ID returned by the create_model call.image_path
: The path to a local JPG/PNG image.gender
: 1 for woman, 2 for man. This helps categorize and fine-tune details in the training process.
Tip: You can upload multiple selfies by calling upload_training_image
multiple times with different image paths.
5. Running the Training Process
Once your images are uploaded, start the training by calling:
1 2 |
client.run_order(order_id=model[”id”]) |
This triggers the server to train on the newly provided images. The time it takes varies based on factors like the size and complexity of the images.
6. Checking the Training Status
Training can take a few minutes, so you can periodically poll the status to see if it’s finished or still in progress:
1 2 3 |
status = client.get_order_status(order_id=model[”id”]) print(“Order status:”, status) |
Possible statuses:
CREATED
: The order was created but not yet started.STARTED
orIN_PROGRESS
: Training is ongoing.DONE
: Training is complete and the model is ready for image generation.ERROR
: Something went wrong during processing.
7. Next Steps: Generating Images
Once your order’s status is DONE
, you can create a new order to generate images using the trained model. This involves specifying the parent
as the trained model’s ID, plus any new style IDs you want applied. A sample call might look like:
1 2 3 4 5 6 7 8 9 |
generation_payload = { “styles”: [112, 5], “gender”: 1, “parent”: model[”id”] # reference the trained model } new_order = client.create_order(generation_payload) # Optionally run and poll the new order until it is “DONE” |
Check the MyMoodAI docs for more details on retrieving the final images, listing styles, or creating variations of an existing model.
8. Conclusion
MyMoodAI offers a streamlined, developer-friendly approach to fine-tuning AI image models. With just a few lines of Python, you can:
- Create a model
- Upload training images
- Run the training process
- Check the status
Then, you’re all set to generate unique images that reflect the style and essence of your uploaded selfies.
Start Fine-Tuning Your Own AI Models Today!
Let us know if you have any questions or feedback, and happy coding!