ostris / ai-toolkit

Various AI scripts. Mostly Stable Diffusion stuff.
MIT License
2.65k stars 255 forks source link

How to set the number of repetitions of images folder ? #140

Open BigPeng opened 2 weeks ago

BigPeng commented 2 weeks ago

Does ai-toolkit support setting the number of repetitions of images folder like koaya? The number of repetitions of multiple folders is different

Amit30swgoh commented 2 weeks ago

interesting and does it support GGUF ?

GXcells commented 2 weeks ago

Does one really need repetition number? ((number of image *number of epoch you need) = total number of steps to set in the config. So you don't need repetition and you don't need epoch in the config file, just set the number of steps to be in accordance wit the number of epoch yo would like to get.

If I a wrong please correct me so that I can learn.

diodiogod commented 2 weeks ago

Does one really need repetition number? ((number of image *number of epoch you need) = total number of steps to set in the config. So you don't need repetition and you don't need epoch in the config file, just set the number of steps to be in accordance wit the number of epoch yo would like to get.

If I a wrong please correct me so that I can learn.

Repetitions are needed to balance a dataset. You can balance it considering quality, or concepts, etc. Let's say one folder with 10 bad images one folder with 10 high quality images. I might want to set the repetition to: 3_good quality / 1_bad quality... Of course you could just do this manually by copy pasting the images in those proportions, but it would be a lot of trouble. You can do this with Ostris, but I didn't use it yet. In the Discord there are explanations.


Common training questions
Q: Can I train multiple concepts or characters in a single LoRA?
A: Yes! You can train a single LoRA on multiple concepts, characters, or styles. Here's how:

    Multiple Datasets: In your config.yml file, define multiple datasets under the datasets section. Each dataset can have its own folder_path and captions.
    Balancing Influence:
        num_repeats: Use this parameter to control how many times a dataset is repeated during training. If one dataset is smaller, you can set a higher num_repeats for it to balance its influence.
            reg_weight: If you are using a regularization dataset (is_reg: true), use reg_weight to control its impact on the training. A lower value gives it less influence.
NBSTpeterhill commented 2 weeks ago

Does one really need repetition number? ((number of image number of epoch you need) = total number of steps to set in the config.真的需要重复次数吗? ((图像数量 需要的纪元数) = 在配置中设置的总步骤数。 So you don't need repetition and you don't need epoch in the config file, just set the number of steps to be in accordance wit the number of epoch yo would like to get.因此,您不需要重复,也不需要配置文件中的纪元,只需将​​步骤数设置为与您想要获得的纪元数一致即可。 If I a wrong please correct me so that I can learn.如果我说得不对请指正,以便我学习。

Repetitions are needed to balance a dataset. You can balance it considering quality, or concepts, etc.需要重复来平衡数据集。您可以考虑质量或概念等来平衡它。 Let's say one folder with 10 bad images one folder with 10 high quality images. I might want to set the repetition to: 3_good quality / 1_bad quality...假设一个文件夹包含 10 张不良图像,一个文件夹包含 10 张高质量图像。我可能想将重复设置为:3_好质量/1_坏质量... Of course you could just do this manually by copy pasting the images in those proportions, but it would be a lot of trouble.当然,你也可以按照这些比例手动复制粘贴图像,但这会很麻烦。 You can do this with Ostris, but I didn't use it yet. In the Discord there are explanations.你可以用 Ostris 做到这一点,但我还没有使用它。 Discord 中有解释。


Common training questions
Q: Can I train multiple concepts or characters in a single LoRA?
A: Yes! You can train a single LoRA on multiple concepts, characters, or styles. Here's how:

    Multiple Datasets: In your config.yml file, define multiple datasets under the datasets section. Each dataset can have its own folder_path and captions.
    Balancing Influence:
        num_repeats: Use this parameter to control how many times a dataset is repeated during training. If one dataset is smaller, you can set a higher num_repeats for it to balance its influence.
            reg_weight: If you are using a regularization dataset (is_reg: true), use reg_weight to control its impact on the training. A lower value gives it less influence.

excuse me, how to set reg folder path? is that [reg_path: "..."] or some thing else? where can I see the details of other commenders?

diodiogod commented 2 weeks ago

excuse me, how to set reg folder path? is that [reg_path: "..."] or some thing else? where can I see the details of other commenders?

On the discord channel > Help_me > pinned messages

I had some trouble setting the reg arguments because of the yaml file structure, but using notepad++ and setting language to yaml makes it easier to see.

This is how I set up my last training with reg:


job: extension
config:
  name: sweaty_shirt_flux_v5
  process:
  - type: sd_trainer
    training_folder: output/sweatyFlux5
    device: cuda:0
    network:
      type: lora
      linear: 2
      linear_alpha: 16
    save:
      dtype: float16
      save_every: 760
      max_step_saves_to_keep: 24
    datasets:
    - folder_path: J:/train/sweatpit/img/2_s3t shirt
      caption_ext: txt
      caption_dropout_rate: 0.0
      shuffle_tokens: false
      cache_latents_to_disk: true
      resolution:
      - 512
      - 768
      - 1024
    - folder_path: J:/train/sweatpit/img/reg
      caption_ext: txt
      is_reg: true
      caption_dropout_rate: 0.0
      shuffle_tokens: false
      cache_latents_to_disk: true
      resolution:
      - 512
    train:
      reg_weight: 0.25
      batch_size: 1
      steps: 7800
      gradient_accumulation_steps: 1
      train_unet: true
      train_text_encoder: false
      content_or_style: content
      gradient_checkpointing: true
      noise_scheduler: flowmatch
      optimizer: adamw8bit
      linear_timesteps: true
      lr: 0.0005
      skip_first_sample: true
      ema_config:
        use_ema: true
        ema_decay: 0.99
      dtype: bf16
    model:
      name_or_path: black-forest-labs/FLUX.1-dev
      is_flux: true
      quantize: true
    sample:
      sampler: flowmatch
      sample_every: 760
      width: 1024
      height: 1024
      prompts:
      - photo, Prince Harry is wearing a light blue shirt with sweat and has his arms
        raised in the air holding a sign that says 'SMELL MY ARMPITS!'. He is surrounded
        by a group of people some of whom are wearing military uniforms. There is
        a woman with blonde hair in the foreground looking up at the man with her
        arms raised as well. In the background there are more people with their arms
        raised cheering and clapping., small s3t on armpit, ginger, bad quality, blurry
        image, jpeg artifacts, low-res, shirt, multiple boys, brown hair, wristwatch,
        realistic, camouflage, white shirt, facial hair, arms up, collared shirt,
        watch, pants, jewelry, bracelet, open mouth
      - photo, A man with a tattoo on his left arm is wearing a gray t-shirt that
        is soaked with sweat. The t-shirt is dripping with sweat and there are measurement
        markings on the shirt that show the amount of sweat dripping from it. The
        man's face is serious and he is looking directly at the camera. The background
        is black and the man is standing in the center of the frame., s3t on chest,
        cropped face, s3t on armpit, caucasian, tattoo on his arm, 1boy, solo, male
        focus, shirt, head out of frame, simple background, tattoo, upper body, black
        background, short sleeves, grey shirt, white shirt, facial hair, facing viewer,
        t-shirt, closed mouth, realistic
      neg: ''
      seed: 42
      walk_seed: true
      guidance_scale: 4
      sample_steps: 20
meta:
  name: '[Diogod]'
  version: '4.0'
  notes: reg-smudges-IncreasedTR-2/16-nodrop-reg0.25-lr0.0005
NBSTpeterhill commented 2 weeks ago

thanks, that is very useful.

Deathawaits4 commented 1 week ago

Does one really need repetition number? ((number of image *number of epoch you need) = total number of steps to set in the config. So you don't need repetition and you don't need epoch in the config file, just set the number of steps to be in accordance wit the number of epoch yo would like to get. If I a wrong please correct me so that I can learn.

Repetitions are needed to balance a dataset. You can balance it considering quality, or concepts, etc. Let's say one folder with 10 bad images one folder with 10 high quality images. I might want to set the repetition to: 3_good quality / 1_bad quality... Of course you could just do this manually by copy pasting the images in those proportions, but it would be a lot of trouble. You can do this with Ostris, but I didn't use it yet. In the Discord there are explanations.


Common training questions
Q: Can I train multiple concepts or characters in a single LoRA?
A: Yes! You can train a single LoRA on multiple concepts, characters, or styles. Here's how:

    Multiple Datasets: In your config.yml file, define multiple datasets under the datasets section. Each dataset can have its own folder_path and captions.
    Balancing Influence:
        num_repeats: Use this parameter to control how many times a dataset is repeated during training. If one dataset is smaller, you can set a higher num_repeats for it to balance its influence.
            reg_weight: If you are using a regularization dataset (is_reg: true), use reg_weight to control its impact on the training. A lower value gives it less influence.

You actually dont need to have multiple datasets. Reg images are nothing more than images that are trained with your normal images. So just add them to your main dataset and train. If you need more repetitions on specific images, just add them twice (that is basically the whole math behind it) yes setting repetitions looks cleaner, but it is no special feature.

diodiogod commented 1 week ago

... Of course you could just do this manually by copy pasting the images in those proportions, but it would be a lot of trouble...

You actually dont need to have multiple datasets. Reg images are nothing more than images that are trained with your normal images. So just add them to your main dataset and train. If you need more repetitions on specific images, just add them twice (that is basically the whole math behind it) yes setting repetitions looks cleaner, but it is no special feature.

That is exactly what I said. I never said you need repetition or that reg are special in any way.

It can be a big mess to have repeated dataset for balancing (i've been there). Specially if you are mixturing that with regularization images. Also, there are options specially for regularization images weight like "reg_weight".

AfterHAL commented 1 day ago

Hi there. Does the regularization files for Flux training needs captioning ?