How to Fine-Tune Your Model with Python and MyMoodAI

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:

  1. Create new models (training orders)
  2. Upload selfies (training images)
  3. Run the training process
  4. 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:

(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:

Authentication

You’ll need an API key from MyMoodAI to authenticate your requests. Place it in the constructor when instantiating the client:


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).

  • 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:


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.

  • 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:

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:

Possible statuses:

  • CREATED: The order was created but not yet started.
  • STARTED or IN_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:

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:

  1. Create a model
  2. Upload training images
  3. Run the training process
  4. 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!

More Articles & Posts