LoRa in SD3.5 | Dataset Creation + Tools
LoRa Dataset Creation in SD3.5This is a walkthrough of my LoRa creation process for SD3.5. I am using a number of external tools which are listed in this article.Part 1: Find a good datasetFor this project I plan on creating a LoRa for a japanese magazine style cover-art for SD 3.5 Large modelThe first step is sourcing reference material for your LoRa. I used kimirano.jp to find a collection of imagesOther sources which find useful are DeviantArtPinterest: https://www.pinterest.com/And Sankaku Complex for the NSFW stuff (they have a phone app: https://apps.apple.com/us/app/sankaku-anime-ai-girlfriend/)These are the ones I selected. I compiled this collage using https://gandr.ioAbove is example of me using gandr.io on some robots. Here is what the output looks like:Note that the backgrounds for these robots have been edited using GIMP. For large datasets , the predominant color will oftentimes be white. Try to offset this whenever possible. Adding a black rim at the edges will teach the LoRa that high contrast = good. Green and Blue are rare colors. You want to use a unique color scheme. It will make the LoRa output image stand out in an AI art gallery.And here are the manga covers:Compiling the training images this way is a good way to showcase to people what "type" of image your LoRa can create.Some points when selecting the LoRa reference material:Use images where only 1 person existsUse different colors for backgroundsAvoid items that feature obscured bodypartsAvoid images with a lot of white , beige or gray in them.Judge the pictures based on color , clarity and composition. If you can't tell what the image is based on the thumbnail , the AI model won't understand it either.Understand the Stable Diffusion community. If you want it , others want it too. For example; the reason why I'm training this LoRa is to give people (and myself) the means to produce cool coverpage images for future models, articles , posts etc.Next , I edit the photos using a photoeditor tool such as GIMP : https://www.gimp.org/downloads/The goal is to remove anything which may confuse the AI model when trying to re-create the images.SD3.5 Large model will happily accept any LoRa content that features nudity. The base SD 3.5 Large model lacks any training for NSFW content, so it will happily gobble up such content to make the 'pieces within itself' fit together nicely.In this case , I've removed all English Text from the cover-art you see above. This is to avoid a concept blend between Kanji letters and English text for the T5 model. We still want to be able to write English text with the LoRa after all.The general rule of thumb from the LoRa community is having between 20-30 images for a character , and at least 30 images if the LoRa embodies something more abstract like a concept or style.In this case I use 24 images. My reasoning here is that the coverart is very "chaotic" so only a few images are required to represent a decent amount of variety. Plus we want to save the LoRa training costs since recreating this very densely packed artstyle will likely require a lot of epochs before it "stabilizes" so-to-speak.Part 2: Selecting a KeywordWhile a keyword can be anything you want it to be; this time I've decided to take the scientific appreach.This noteook can be used to search tokens in SD3.5 : https://huggingface.co/datasets/codeShare/text-to-image-prompts/blob/main/Google%20Colab%20Notebooks/token_vectors_math.ipynbWithin this notebook I made some random searches for tokens similar to "manga</w>" and "japan</w>" , and I stumbled upon the rarely used token "kei</w>" . I decided to include this into the keywordIf you want to see the concept representation of each token , you can try: https://benjamin-bertram.github.io/passive-illustration/index.html#token-libraryYou can also use this notebook to browse text_encodings: https://huggingface.co/datasets/codeShare/fusion-t2i-generator-data/blob/main/Google%20Colab%20Jupyter%20Notebooks/fusion_t2i_CLIP_interrogator.ipynbI used the text_encodings notebook to find the keyword for the robot lora.One of the similiar results according to CLIP model in the text_encoding notebook was "art by Brian Sum", so I googled that and behold "Brian Sum" was actually a guy who draws robots! You can find his creations here: https://www.artstation.com/sum . I did add 4 images of his works into the robot LoRa, bringing up the total from 26 images to 30.//----//For the mangacover art I decided the keyword for the LoRa should be "mangacover kei" . This allows me to hitch a ride on the training data which already exists within the SD3.5 model , saving epoch training time.To check the exact number of tokens used I use this online tokenizer : https://sd-tokenizer.rocker.boo/SD3.5 uses CLIP_L and CLIP_G , and has the same vocab as the previous SD models. The main difference is that it also uses the T5 model, which is an LLM model akin to chatGPT.To verify I run a prompt on a SD3.5 model as 'mangacover kei text "LORA" 'Good enough.Part 3: Writing the promptsWhen training T5 models , I prefer running the training images through JoyCaption Alpha One at 200 token length : https://huggingface.co/spaces/fancyfeast/joy-caption-alpha-oneWe want the prompts to be between 500-800 characters in length in order to keep it within the 256 token context length of the T5 model. To quote stability AI:While this model can handle long prompts, you may observe artifacts on the edge of generations when T5 tokens go over 256. Pay attention to the token limits when using this model in your workflow, and shortern prompts if artifacts becomes too obvious.Also note:The medium model (SD3.5M) has a different training data distribution than the large model (SD3.5 Large), so it may not respond to the same prompt similarly.Source: https://huggingface.co/stabilityai/stable-diffusion-3.5-mediumPart 4: Compiling the DatasetFinally I apply the selected images to Batchcropper : https://batchcropper.com/enI prefer using portrait size 768x1024 or 768x1150 for the dataset.Then I paste the JoyCaption prompts and add my selected keywords to somewhere close to the start of the prompts.The training set is now done! It can be downloaded as a zip file and kept in a Huggingface repository until it is time to train them: https://huggingface.co/datasets/codeShare/lora-training-dataShould you wish to store training data privately you can use https://mega.nz/ . They are a cloud storage website which encrypts their user data and by policy have 0 % knowledge of the content you store online as long as the repository is set to private.Note that due to recent legislation in California, more common hosting websites like Google drive may ban your account if you use their services to host certain type of content. This will include celebrity impersonation. This is something to keep in mind.//----//When you do your training , remember to document, document , document!Users wants to see your dataset , your prompts , your examples (including the bad ones) , the loss graph on the LoRa training , the epoch you choose to release , your methods, your sources. The sharing of information is the lifeblood of an open source community.This is the Loss graph of the Brain Sum LoRaWe see a dip in Loss rate past epoch 14. Thus , it is reasonable to post every epoch past epoch 14 to the LoRa. Then we can do some trial and error on the epochs 14-20 to find which of these has the "best looking" output.//----//LoRas I've made (so far)Brian Sum Lora : https://tensor.art/models/795501520574647074?source_id=njq1pFzjlEOwpPEpaXny-xcuNaytlayt NSFW training LoRa : https://tensor.art/models/793017079562442313?source_id=njq1pFzjlEOwpPEpaXny-xcuTsutomo Nihei LoRa : https://tensor.art/models/791213304967242613?source_id=njq1pFzjlEOwpPEpaXny-xcuTraining Data:Brain Sum Training data (imgur): https://imgur.com/a/blPjv6SI post my training data here , which you can download as a zip file: https://huggingface.co/datasets/codeShare/lora-training-data/tree/main//----//Thank you for reading this article. Hopefully it will be some help. Good luck on the Lora training for the SD3.5 model.