So you might have seen the things people have created with AI and thought "hmm i want to do that too". Understandable, it's pretty fun when you get the hang of it, and with the tech maturing a bit, there's now ample resources that make it "somewhat easy" if you have a good instinctive understanding of making the computer do what you want it to. The moral and legal questions behind AI art are something for another time... personally I find it can be a great tool for artists but that the models thrown in are akin to piracy. Playing with it, knowing a bit of how it works, and getting a grasp of the community behind it might help you form a more informed opinion on that, too, but this post is more an informative dump on how it works (a very general overview) and how to use it.
I'm by no means a pro, so if you're particularly interested, please look for guides beyond this post.
In essence, Stable Diffusion is an algorithm that allows you to combine noise and a prompt, and gain an image that visually resembles the prompt as we understand it as output. When you type a prompt and hit Generate, it:
The magic exists in the combining of networks. Normal image formats, can't be combined. You can overlap two images, or put them next to eachother, or cross-fade them, but it's impossible to combine the "concepts" of the images, the elements that make them what they are. Stable Diffusion makes this possible, allowing you to combine the concepts behinds images, to create new images. In a way, Stable Diffusion is a new type of collage tool, except instead of combining image data, you're combining concepts.
This post only covers rendering & training on your own device. There's great support for renting GPU time, including free GPU time, from things like Google Colab, but in this post I'll only talk about how to do it yourself. Here's what you'll need:
The program everyone uses is AUTOMATIC1111's WebUI: https://github.com/AUTOMATIC1111/stable-diffusion-webui#installation-and-running
In short (for Windows):
webui-user.bat. It should set up on its own.By default, WebUI downloads Stable Diffusion 1.5 for you. That's great, but I know you're all here for flat anime chests so you'll want to download anime models. There's many but the one I like using is Anything4.5. Here's how to get it:
anything-v4.5-pruned.safetensors and anything-v4.0.vae.pt from https://huggingface.co/andite/anything-v4.0/tree/mainmodels/Stable-diffusion folder in your WebUI directoryanything-v4.0.vae.pt to anything-v4.5-pruned.vae.pt (so WebUI picks it up automatically)You might be wondering what a .safetensors or a VAE are.... In short, there's a few words you want to know:
.pt and .ckpt files. They may contain malicious code. That's what .safetensors is for (it's safe by design).Type a prompt into the big Prompt box, then press the big Generate button. It's pretty simple to use all things considered. Keep an eye on the console for more information.
...OK, that might not be enough info, so let me ride you through the main controls:
(text) adds emphasis (about 1.1x). You can (((((stack))))) them too to add more and more emphasis.[text] similarly removes emphasis (about 0.9x).(text:1.25) sets emphasis (I prefer this, easier to tweak). Note this also stacks, so ((beans:2):2) has a weight of 4.[textA:textB:n] changes from textA to textB after n steps.[text::n] removes text from the prompt after n steps.[text:n] adds text to the prompt after n steps.a [fantasy:cyberpunk:16] landscape will first paint a fantasy landscape for 16 steps, then switch to painting a cyberpunk one.(best quality, masterpiece, detailed lighting:1.1), at the start!lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, (worst quality, low quality, normal quality:1.1), jpeg artifacts, signature, watermark, username, blurry, artist nameAI sucks at hands and other fine details. But, there's a trick: you can ask the AI to repaint a specific part of the image. Simply click "Sent to inpaint" and itll take you to the img2img tab. There, you can draw over the image and essentially select an area to redraw. Try it out, it's quite neat!
In general, play around with the settings! There's a billion things you can change, and I can't go over them all here. The AUTOMATIC1111 Wiki is a great resource.
LoRAs are the most fun part of Stable Diffusion to me. LoRAs essentially add extra data to the model, Combining them and creating things it's never seen before is amazing fun! CivitAI is a great source of both models and LoRAs, so give it a look. Using a LoRA is simple:
/models/Lora<lora:LORANAME:WEIGHT>. WEIGHT is preset to 1, but depending on the LoRA used, that weight may not be appropriate. Check the documentation for the LoRA to see what you should use. (Many sit a little lower than 1)<lora> tag isn't an actual part of the prompt, so its position doesn't matter, and it doesn't interact with any prompt syntax.Combining LoRAs comes at a slight performance cost, but it's very fun so you should do it anyway.
OK, so this is essentially an entire thing to study on its own, and something I am absolutely not pro at (I only made one Kagari LoRA) but I'll tell you how it works real quick...
You'll want to use https://github.com/bmaltais/kohya_ss, it comes with a GUI and is relatively easy to install. In short (for Windows again):
setup.bat in a command prompt.gui.bat --listen 127.0.0.1 --server_port 7861 --inbrowser --shareThe most important part about creating a LoRA is assembling a dataset. In my case, a bunch of Kagari pictures. Quality over quantity. Put in shit images, get shit images out. Get only the best images. You only technically need 5 images to start a LoRA, but anything between 10 and 250 will do well. More images does help, but please don't try to target a high number.
Once you have a bunch of images, create a folder for your LoRA. Inside of it, create another folder, with the name WEIGHT_Name. Generally, a weight of 5 or 10 is fine. The name is just visual and doesn't impact anything. In my case: 10_Kagari. Inside of that folder is where your images go, named sequentially. So 1.png, 2.png, 3.png, ...
You don't need to resize or reencode your images. Although, if your image has an extreme aspect ratio, consider cropping it to a more normal ratio or removing it from your dataset.
Your directory structure should look like this by now:
The second most important part of assembling a dataset is tagging it. How you need to tag your images depends on what model you are training against. In my case, I trained against Anything-v4.5, so I needed to tag with booru format.
When tagging, you essentially attach the things you do not tag, to the things you do tag. For example, take this image:
Here's a (very conservative) way to tag it: kagari, smile, looking at viewer, raised arm, closed hand, black dress, black choker, black criss-cross halterneck
The kagari tag is new and doesn't exist within the model yet, so it's very prone to picking up new information. This will become a trigger keyword. This trigger keyword will then associate itself with the picture, except for the things I tag.
What that means is: since I didn't tag white hair or purple eyes or white skin or hair ornament etc., those elements will become connected with the kagari tag. (Technically, they become connected with all the tags here, but since the other tags are already known to the model they won't have as much effect). However, I did tag black dress, black choker, etc. because I want to be able to change them later. I don't want to connect Kagari's outfit directly to Kagari herself, because else it will be very difficult to make the AI draw her in other clothing. (Note that by doing this, I do need to write these every time I want the AI to draw her in her own clothing.)
You want to write tags like that, and then save them in a .txt with the same number as the image file. So, your directory structure should now have 1.png, 1.txt, 2.png, 2.txt, etc.
By the way, the more tags the better, generally. Remember, anything you don't tag will become attached to your trigger words, so don't skimp on tags. My example here is very conservative, and I want to retry tagging with a bit more precision.
TIP!! If you are grabbing images from a booru to use as your input, why not use tags from said booru? They've already done the hard work for you! Just remember to remove all the tags you want to be inherent to the trigger keyword. For example, when training to draw a character, prune all the tags regarding say, her eye color, hair color, etc. (Also, make sure to convert underscores to spaces!)
If you can't do that, there's another way — in WebUI, under img2img, you can actually drop in an image and press Interrogate DeepBooru, and it will turn your image into booru tags. It's very neat, give it a try! (Once again, remove the underscores.) You can also do the same with Interrogate CLIP to turn an image into a standard StableDiffusion prompt. Note that this takes a moment to download models the first time you use it, so check the console. It's not stuck!
WARNING: parameter dump nobody understands, especially not me.
Open the kohya_ss GUI, and click to the second tab, Dreambooth LoRA. There's a bunch of tabs, so I'll go through them:
This is where you enter what model to train against. Set Pretrained model name or path to the model you want to train against. In my case, I trained against Anything-v4.5, so it has its .safetensors listed there.
If you're using a Stable Diffusion model, use the quick pick thingy I guess. Set output to safetensors because otherwise people won't trust you
Here you enter the important folders. For Image folder, select not the folder with the images in, but the one above it. So in my case not the 10_Kagari, but the one level above it. I know that name is confusing, but the training technically allows you to have multiple datasets and stuff in different folders so it has that extra folder.
It's easiest if you set the output folder to be within your WebUI, so you can use your created LoRAs right away. Again, the name doesn't matter beyond being a filename. It doesn't impact the prompt (that's what the tagging is for)
I don't know what most of these do, but these options gave good results for me. The options you want to pay special attention to are:
I'm pretty sure I left this all on defaults, but here they are anyway
This is optional, but very useful: it'll autogenerate some sample prompts every time it saves an epoch. This allows you to quickly glance which epoch makes the best results.
doesn't matter. As long as your inputs are sane everything will run on its own
Make sure you've got a LOT of spare RAM and ... start training! This will take a lot of time, you'll be wanting to run this overnight or something of the sort. You can keep track of the sample images it creates and see if it's degrading in quality and kill it earlier, if you need! The latest will always have the original filename, the others will have numbers after their names. Once you're happy with the result, you can start using it in WebUI and generate whatever you like!
Unsurprisingly, everything essentially runs fine under Windows 7 but there's a bunch of random fuckyous placed everywhere to try and get you to Become Inspired by the adware bloatware spyware shitware that is modern Windows. Anyway, here's what I had to do in addition to get things to run on Win7:
cudart64_110.dll that doesn't work on Win7, despite there being a version of it that does and that works absolutely fine. Grab this one and place it in place of the existing cudart64_110.dll:/venv/Lib/site-packages/torch/lib/venv/Lib/site-packages/torch/lib as well.This isn't a full guide, I'm super new to all this. If you're interested in really learning the nitty gritty, check out the Automatic1111 Wiki! It's a good resource.
also don't spam your generations to pixiv etc, and esp dont try to pass them off as your own. don't become the reason people hate AI, thankies
annoyingly originally StableDiffusion was supposed to add an invisible watermark to its outputs (that survives compression etc) but it was never added, despite there being a toggle iin the options and a script deep in the source that allows you to find the watermark wonder why ...