Stable Diffusion Quickstart with WSL2 and RTX3070

~Generate Boss Baby-ish Profile Image ~

Objective

To generate my profile image on Twitter.

Unlike LinkedIn or Facebook, Twitter is a bit anonymous service, so I don’t want to use my photo as a profile image. Therefore, I’ve sought a nice picture to use my SNS icon.

Pre-requisites

  • Windows 10 Home 21H2
  • WSL2 Ubuntu 20.04.5 LTS
# run on wsl to show the version
lsb_release -a
  • Kernel: Linux version 5.10.102.1-microsoft-standard-WSL2
# run on cmd to show the version
wsl cat /proc/version
  • CPU: Ryzen 5 5600X
  • GPU: GeForce RTX 3070
  • RAM: 32GB
  • VRAM: 8GB
  • Package management: Anaconda
  • Not using Docker
  • Use optimized stable diffusion due to VRAM limitation

Quick Guide

  1. Install WSL2 and update the latest version

https://learn.microsoft.com/ja-jp/windows/wsl/install

# run on cmd
wsl --install
wsl --update
wsl --install -d Ubuntu-20.04

2. Install CUDA Toolkit

https://learn.microsoft.com/ja-jp/windows/ai/directml/gpu-cuda-in-wsl

https://docs.nvidia.com/cuda/wsl-user-guide/index.html#getting-started-with-cuda-on-wsl

# run on wsl
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.7.0/local_installers/cuda-repo-wsl-ubuntu-11-7-local_11.7.0-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-11-7-local_11.7.0-1_amd64.deb
sudo apt-get update
sudo apt-get -y install cuda

3. Clone Stable Diffusion (Optimized one)

https://github.com/basujindal/stable-diffusion

# run on wsl
git clone git@github.com:basujindal/stable-diffusion.git
cd stable-diffusion

4. Download model “sd-v1–4.ckpt”

https://huggingface.co/CompVis/stable-diffusion-v-1-4-original

5. Rename and move the model

# run on wsl
mkdir -p models/ldm/stable-diffusion-v1
mv sd-v1–4.ckpt models/ldm/stable-diffusion-v1/model.ckpt

6. Install Anaconda

# run on wsl
wget https://repo.anaconda.com/miniconda/Miniconda3-py38_4.12.0-Linux-x86_64.sh
bash Miniconda3-py38_4.12.0-Linux-x86_64.sh

7. Install Python Packages

# run on wsl
conda env create -f environment.yaml
conda activate ldm

8. Prepare image

# run on wsl
mkdir img
mv [path to your image file] img/001.jpg
# image file name and path are depend on you. whatever is okay.

9. Run Script

# run on wsl
python optimizedSD/optimized_img2img.py --prompt "boss baby" --init-img img/001.jpg --strength 0.8 --n_iter 10 --n_samples 10 --H 512 --W 512

Parameters

  • prompt: text you want to combine
  • init-img: the image you want to combine
  • n_samples: number of images generated

Lastly, check the stable-diffusion/outputs/img2img-samples/boss_baby directory.

My new SNS icon

I hope this helps!

*2022/11/6: modify some commands according to a comment.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store