머신러닝AI2023. 9. 2. 20:15

생성형 이미지의 대표주자인 Stable Diffusion을 설치해서 실행해보자. 많은 것들이 그간 발전했고 easy diffusion이라는 멋진 웹인터페이스까지 만들어진 오픈소스가 존재한다.

 

모든 기본 환경은 ubuntu nvidia 4080 + anaconda 를 기준으로 한다 (  https://infoengineer.tistory.com/96 )

아래 사이트를 참조하자.

 

https://easydiffusion.github.io/docs/installation/

 

$ wget https://github.com/cmdr2/stable-diffusion-ui/releases/latest/download/Easy-Diffusion-Linux.zip

$ unzip Easy-Diffusion-Linux.zip

$ cd easy-diffusion

$ ./start.sh

/work/anaconda3/bin/curl
/usr/bin/tar
/work/anaconda3/bin/bzip2
Downloading micromamba from https://micro.mamba.pm/api/micromamba/linux-64/latest to /work2/easy-diffusion/installer_files/mamba/micromamba
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
100  4569    0  4569    0     0   1176      0 --:--:--  0:00:03 --:--:-- 4461k
  0 5096k    0     0    0     0      0      0 --:--:--  0:00:04 --:--:--     0bin/micromamba
100 5096k  100 5096k    0     0   811k      0  0:00:06  0:00:06 --:--:-- 3183k
Micromamba version:
1.5.0
Empty environment created at prefix: /work/easy-diffusion/installer_files/env
Packages to install: conda python=3.8.5
conda-forge/linux-64                                30.0MB @  41.3MB/s  0.7s
conda-forge/noarch                                  12.2MB @   3.5MB/s  3.5s

....

 

 

자동으로 서버가 뜬다. 내부 리눅스 브라우저를 이용해 아래를 실행한다.

 

http://localhost:9000/

 

적절한 영문 문구로 이미지 생성됨을 확인한다.

512*512 이미지가 수초만에 생성됨을 알 수 있었다. CPU/GPU 모드 등 변경하여 실험할 수 있다. 4080 GPU 카드로는 1280*768 정도 이미지를 만들 수 있는데, 1920*1280은 메모리 부족으로 오류가 난다.

 

 

이렇게 디폴트로 사용하는 방법도 있지만 custom model을 다운로드 받아 사용하는 방법도 있다. civit.ai 같은 사이트에서 model 파일을 다운로드 받아서 ./easy_diffusion/models/stable-diffusion/에 넣은 후 아래와 같이 특화된 이미지를 생성할 수도 있다.

 

stable diffusion model 다운로드 사이트(civit.ai), Models선택

 

Download를 선택하면 크기는 좀 크지만, 커스텀 모델 파일을 다운로드할 수 있다

 

왼쪽 메뉴의 Image Settings의 Model을 바꾸어서 생성해보면, 특화 모델 기반의 이미지 생성도 가능하다.

 

 

easy-diffusion외에 Stable Diffusion의 대명사인 AUTOMATIC1111이라는 웹인터페이스도 존재한다. 이 프로그램의 특징은 최신 기능의 빠른 적용이다. 이 툴을 설치하는 방법에 대해서도 잠깐 살펴보자.

 

$ conda create -n automatic python=3.10

$ conda activate automatic

$ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

$ cd stable-diffusion-webui/

$ ./webui.sh

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye), Fedora 34+ and openSUSE Leap 15.4 or newer.
################################################################
....

#모델다운로드 등 거치게 된다

#

 

모두 실행된 후 http://127.0.0.1:7861/ 에 접속하면 아래와 같이 AUTOMATIC1111이 구동된다. 시중의 메뉴얼을 참조하여 활용해보자. img2img 같은 기능은 이미지를 넣어 다른 이미지를 변환하는 기능이다. 그외에 Extras같은 플러그인 등 다채로운 기능을 제공한다. 이를 테면 Extensions에 https://github.com/toriato/stable-diffusion-webui-wd14-tagger 를 설치하면, 사진에서 스크립트를 뽑아주는 반대의 기능 활용도 가능하다.

Automatic1111 화면

 

반응형
Posted by 작동미학