dreamfinetune


Namedreamfinetune JSON
Version 1.5 PyPI version JSON
download
home_pagehttps://github.com/skillfi/fine-tuning
SummaryNone
upload_time2024-08-28 09:18:48
maintainerNone
docs_urlNone
authorAlex
requires_python>=3.8
licenseApache 2.0 License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            StableDiffusionInpaintingFineTune
=================================

This project provides a toolkit for fine-tuning the Stable Diffusion model for inpainting tasks (image restoration based on a mask) using PyTorch and Hugging Face Diffusers libraries.

Requirements
------------

Before starting, you need to install the following libraries:
 .. code-block:: python

  pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

- ``torch``
- ``diffusers``
- ``transformers``
- ``accelerate``
- ``huggingface_hub``
- ``PIL``
- ``numpy``
- ``tqdm``

Description
-----------

StableDiffusionInpaintingFineTune
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This class is responsible for fine-tuning the Stable Diffusion model for the inpainting task. It supports training both the text encoder and the UNet model and uses various settings to control the training process.

Constructor
^^^^^^^^^^^

.. code-block:: python

   __init__(self, pretrained_model_name_or_path, resolution, center_crop, ...)

- **pretrained_model_name_or_path**: The path or name of the pre-trained model.
- **resolution**: The resolution of the images.
- **center_crop**: Whether to apply center cropping during data preparation.
- **train_text_encoder**: Whether to train the text encoder.
- **dataset**: The dataset object.
- **learning_rate**: The initial learning rate.
- **max_training_steps**: The maximum number of training steps.
- **save_steps**: The number of steps between saving checkpoints.
- **train_batch_size**: The batch size.
- **gradient_accumulation_steps**: The number of steps to accumulate gradients.
- **mixed_precision**: Use of mixed precision ("fp16", "bf16", or None).
- **gradient_checkpointing**: Use of gradient checkpointing.
- **use_8bit_adam**: Use of the 8-bit Adam optimizer.
- **seed**: The random seed for reproducibility.
- **output_dir**: The directory for saving results.
- **push_to_hub**: Whether to upload the results to the Hugging Face Hub.
- **repo_id**: The repository ID on Hugging Face Hub.

Methods
^^^^^^^

- **prepare_mask_and_masked_image(image, mask)**: Prepares the mask and masked image.
- **random_mask(im_shape, ratio=1, mask_full_image=False)**: Generates a random mask.
- **load_args_for_training()**: Loads the necessary components of the model for training.
- **collate_fn(examples)**: Forms a batch of data for the model.
- **__call__(self, *args, **kwargs)**: The main method for running the training process.

Usage
-----

To start training, you should create an instance of the ``StableDiffusionInpaintingFineTune`` class and call its ``__call__`` method, passing the necessary arguments.

.. code-block:: python

   model = StableDiffusionInpaintingFineTune(
       pretrained_model_name_or_path="path_to_model",
       resolution=512,
       center_crop=True,
       ...
   )

   model()

License
-------

The project is distributed under the MIT License.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/skillfi/fine-tuning",
    "name": "dreamfinetune",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Alex",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/dc/a2/ff805d93aa609042d01a0e383c19a07172a3bc1345ea00dd3161a060c4bc/dreamfinetune-1.5.tar.gz",
    "platform": null,
    "description": "StableDiffusionInpaintingFineTune\r\n=================================\r\n\r\nThis project provides a toolkit for fine-tuning the Stable Diffusion model for inpainting tasks (image restoration based on a mask) using PyTorch and Hugging Face Diffusers libraries.\r\n\r\nRequirements\r\n------------\r\n\r\nBefore starting, you need to install the following libraries:\r\n .. code-block:: python\r\n\r\n  pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121\r\n\r\n- ``torch``\r\n- ``diffusers``\r\n- ``transformers``\r\n- ``accelerate``\r\n- ``huggingface_hub``\r\n- ``PIL``\r\n- ``numpy``\r\n- ``tqdm``\r\n\r\nDescription\r\n-----------\r\n\r\nStableDiffusionInpaintingFineTune\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nThis class is responsible for fine-tuning the Stable Diffusion model for the inpainting task. It supports training both the text encoder and the UNet model and uses various settings to control the training process.\r\n\r\nConstructor\r\n^^^^^^^^^^^\r\n\r\n.. code-block:: python\r\n\r\n   __init__(self, pretrained_model_name_or_path, resolution, center_crop, ...)\r\n\r\n- **pretrained_model_name_or_path**: The path or name of the pre-trained model.\r\n- **resolution**: The resolution of the images.\r\n- **center_crop**: Whether to apply center cropping during data preparation.\r\n- **train_text_encoder**: Whether to train the text encoder.\r\n- **dataset**: The dataset object.\r\n- **learning_rate**: The initial learning rate.\r\n- **max_training_steps**: The maximum number of training steps.\r\n- **save_steps**: The number of steps between saving checkpoints.\r\n- **train_batch_size**: The batch size.\r\n- **gradient_accumulation_steps**: The number of steps to accumulate gradients.\r\n- **mixed_precision**: Use of mixed precision (\"fp16\", \"bf16\", or None).\r\n- **gradient_checkpointing**: Use of gradient checkpointing.\r\n- **use_8bit_adam**: Use of the 8-bit Adam optimizer.\r\n- **seed**: The random seed for reproducibility.\r\n- **output_dir**: The directory for saving results.\r\n- **push_to_hub**: Whether to upload the results to the Hugging Face Hub.\r\n- **repo_id**: The repository ID on Hugging Face Hub.\r\n\r\nMethods\r\n^^^^^^^\r\n\r\n- **prepare_mask_and_masked_image(image, mask)**: Prepares the mask and masked image.\r\n- **random_mask(im_shape, ratio=1, mask_full_image=False)**: Generates a random mask.\r\n- **load_args_for_training()**: Loads the necessary components of the model for training.\r\n- **collate_fn(examples)**: Forms a batch of data for the model.\r\n- **__call__(self, *args, **kwargs)**: The main method for running the training process.\r\n\r\nUsage\r\n-----\r\n\r\nTo start training, you should create an instance of the ``StableDiffusionInpaintingFineTune`` class and call its ``__call__`` method, passing the necessary arguments.\r\n\r\n.. code-block:: python\r\n\r\n   model = StableDiffusionInpaintingFineTune(\r\n       pretrained_model_name_or_path=\"path_to_model\",\r\n       resolution=512,\r\n       center_crop=True,\r\n       ...\r\n   )\r\n\r\n   model()\r\n\r\nLicense\r\n-------\r\n\r\nThe project is distributed under the MIT License.\r\n",
    "bugtrack_url": null,
    "license": "Apache 2.0 License",
    "summary": null,
    "version": "1.5",
    "project_urls": {
        "Homepage": "https://github.com/skillfi/fine-tuning"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d84206e66a10af3d54f2a13c70e6347c71bc1f0c7266fcbb97cc965e84ee0a83",
                "md5": "c0a6c0d01414e7ee36d143070739a218",
                "sha256": "de14b16154a840b1aede4d9ecb9f9f5f2649f1d488c5d8a52d2a19a6de3cdf61"
            },
            "downloads": -1,
            "filename": "dreamfinetune-1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c0a6c0d01414e7ee36d143070739a218",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 19906,
            "upload_time": "2024-08-28T09:18:46",
            "upload_time_iso_8601": "2024-08-28T09:18:46.763877Z",
            "url": "https://files.pythonhosted.org/packages/d8/42/06e66a10af3d54f2a13c70e6347c71bc1f0c7266fcbb97cc965e84ee0a83/dreamfinetune-1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dca2ff805d93aa609042d01a0e383c19a07172a3bc1345ea00dd3161a060c4bc",
                "md5": "e4f8269f4c86f33708662c6d827f9773",
                "sha256": "350bef3fa10162a107295363cb32509122b253bdabf9481c7fbdb908d2811cf3"
            },
            "downloads": -1,
            "filename": "dreamfinetune-1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "e4f8269f4c86f33708662c6d827f9773",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 17000,
            "upload_time": "2024-08-28T09:18:48",
            "upload_time_iso_8601": "2024-08-28T09:18:48.369967Z",
            "url": "https://files.pythonhosted.org/packages/dc/a2/ff805d93aa609042d01a0e383c19a07172a3bc1345ea00dd3161a060c4bc/dreamfinetune-1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-28 09:18:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "skillfi",
    "github_project": "fine-tuning",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "dreamfinetune"
}
        
Elapsed time: 0.36222s