Skip to main content

A package to use the OstrisTraining

Project description

Libs-Ostris (TechTrash_OstrisTraining)

This package provides a small Python wrapper around an Ostris training workflow.

The main entrypoint is OstrisTraining.train().

What train() does

  • Download + prepare dataset from a public ZIP URL
    • ZIP root must contain image files + matching caption files (.txt)
    • Example pair: photobelle.png + photobelle.txt
    • Output: files are normalized to image_0.<ext>, image_0.txt, image_1.<ext>, image_1.txt, ...
  • Write config YAML from a string into a deterministic file:
    • {absolute_path_racine}/config-{user_name}.yaml
    • Before writing, we patch the YAML automatically:
      • config.name is forced to user_name
      • config.process[*].datasets[*].folder_path is forced to the prepared dataset folder
      • config.process[*].trigger_word is forced to:
        • "ohwx woman" if gender="woman"
        • "ohwx man" if gender="man"
  • Run training
    • Calls run.py inside absolute_path_ostris with the generated config path
  • Cleanup on success
    • Deletes the prepared dataset folder + generated config yaml
    • Keeps the produced .safetensors model file

Install (local dev)

From this folder:

pip install -e .

Usage (recommended)

The best reference is src/ostristraining/example.py.

You can run it directly after installing:

python3 -m ostristraining.example

Or copy/paste this minimal usage:

from ostristraining.main import OstrisTraining

trainer = OstrisTraining(
    user_name="demo_user",
    absolute_path_ostris="/tmp/ostris_project",
    absolute_path_racine="/tmp/ostris_runs",
    gender="woman",  # "woman" or "man"
    absolute_path_output="/tmp/ostris_output",
)

# Public ZIP URL containing images + captions at the ZIP root.
url_zip_dataset = "https://example.com/dataset.zip"

# YAML config must be a STRING. Newlines + indentation matter in YAML.
# Tip: start from `src/ostristraining/example_config.yaml` and customize it.
config_yaml_content = """
job: "extension"
config:
  name: "will_be_overwritten"
  process:
    - type: "diffusion_trainer"
      trigger_word: "will_be_overwritten"
      datasets:
        - folder_path: "will_be_overwritten"
"""

trained_model_path = trainer.train(
    url_zip_dataset=url_zip_dataset,
    config_yaml_content=config_yaml_content,
)

print(trained_model_path)

Logging

This library uses Python logging (logger name: ostristraining).

In your app/handler you typically enable logs like:

import logging
logging.basicConfig(level=logging.INFO)

Dataset ZIP format (important)

At the root of the ZIP, you must have:

  • images: .png, .jpg, .jpeg, .webp, .bmp, .gif
  • captions: .txt

And each image must have a caption with the same base name:

  • photo001.png + photo001.txt
  • photo002.jpg + photo002.txt

If an image has no matching .txt, it is skipped.

Config patching rules (quick recap)

If you send a config similar to src/ostristraining/example_config.yaml, the library will ensure:

  • config.name == user_name
  • config.process[*].datasets[*].folder_path == {absolute_path_ostris}/dataset/{user_name}
  • config.process[*].trigger_word == "ohwx woman" | "ohwx man" based on gender

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

techtrash_ostristraining-0.0.10.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

techtrash_ostristraining-0.0.10-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file techtrash_ostristraining-0.0.10.tar.gz.

File metadata

File hashes

Hashes for techtrash_ostristraining-0.0.10.tar.gz
Algorithm Hash digest
SHA256 e5910c1a4beb84fb79970c5358d68c7874151c3598880f7d06d36e5444c253e1
MD5 602006dff311e2fedf302077ffe4bbe6
BLAKE2b-256 11878ee9570845cb2f8698646cf19134597dc7f30764a8ce6405b9fb91fe0e05

See more details on using hashes here.

File details

Details for the file techtrash_ostristraining-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for techtrash_ostristraining-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 e35ab0bcaf8372dcf25f3f06a09c728064c1625f44f15b31ac5aacbbc240b539
MD5 2d179f33f0beea7330c2e155565ad98f
BLAKE2b-256 9d36f028ead13e1ad78845414ccf673183f19687aadb364998ae49c8b14790b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page