Skip to main content

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.

Metadata

Release files for dreamfinetune 1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dreamfinetune 1.5
File Size Uploaded
dreamfinetune-1.5.tar.gz 17.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dreamfinetune 1.5
File Interpreter ABI Platform
dreamfinetune-1.5-py3-none-any.whl Python 3 none any Details

Total release size: 36.9 kB

Release files / dreamfinetune-1.5.tar.gz

Download URL dreamfinetune-1.5.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
350bef3fa10162a107295363cb32509122b253bdabf9481c7fbdb908d2811cf3
BLAKE2b-256 checksum
How to use checksums
dca2ff805d93aa609042d01a0e383c19a07172a3bc1345ea00dd3161a060c4bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / dreamfinetune-1.5-py3-none-any.whl

Download URL dreamfinetune-1.5-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de14b16154a840b1aede4d9ecb9f9f5f2649f1d488c5d8a52d2a19a6de3cdf61
BLAKE2b-256 checksum
How to use checksums
d84206e66a10af3d54f2a13c70e6347c71bc1f0c7266fcbb97cc965e84ee0a83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.5 This release

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page