'Study 외/AI & machine learning' 카테고리의 글 목록 :: Horizontal Grays S2

* 완전 초보의 관점에서 하나씩 해보는 것이니 상세한 설명은 기대하지 마세요~

지난번의 xformers 관련 에러나 out of memory 관련 에러나 모두 argument로 해결이 되었다.

이 Argument에 대해서는 stable diffusion web-ui 를 다운받았던 github에 자세히 나와있었다.

Command Line Arguments and Settings · AUTOMATIC1111/stable-diffusion-webui Wiki · GitHub

 

Command Line Arguments and Settings

Stable Diffusion web UI. Contribute to AUTOMATIC1111/stable-diffusion-webui development by creating an account on GitHub.

github.com

지금은 봐도 뭔소린지 사실 잘 모르겠다.

 

여튼 argument 관련 셋팅에 대해 찾아보다 많이 쓰는 셋팅을 찾았는데 아래와 같았다.

set COMMANDLINE_ARGS= --xformers --opt-split-attention --autolaunch --enable-insecure-extension-access --medvram

 

하나씩 보면

--xformers : enable xformers for cross attention layers -

--opt-split-attention : force-enables Doggettx's cross-attention layer optimization. By default, it's on for cuda enabled systems.

--autolaunch : open the webui URL in the system's default browser upon launch

--enable-insecure-extension-access : enable extensions tab regardless of other options

--medvram : enable stable diffusion model optimizations for sacrificing a little speed for low VRM usage
해석해봐도 뭔소린지 알 수 있는건

autolaunch 는 CMD에서 webui-user.bat 실행하면 자동으로 브라우저로 webui 올라온다는거고

--medvram 은 속도는 조금 떨어질지언정 VRAM의 사용량을 줄이게 해준다는거 그래서 이게 out of memory 오류를 해결해준것이었다.

여튼 이렇게 일단 argument setting을 마치고 webui 설정들을 여기저기 사이트 찾아서 수정해보았다.

 

그리고 Model이라는게 그림체를 설정하는 역할을 하는데 애니메이션처럼 그릴것인지 실사처럼 그릴것인지 등등 을 결정한다. 이 model 관련 파일을 다운받아서 실행하는하는데 검색해보니 여러 종류가 있었다. 용량도 상당하다.

일단 몇가지 모델에 따른 예는 좀 있다가 만들어보고

 

Stable Diffusion으로 만든 그림을 보면 질문들에 프롬프트가 뭐냐는 질문이 많았다. 이게 그 이렇게 만들어라 하는 명령어 같은데

Positive Prompt : 이렇게 만들어라

Negative Prompt : 이렇게 만들진 말아라 

기본적으로 이렇게 두개가 있고 당연하겠지만 찾아보니 엄청나게 많은 종류가 있어 다 퍼오기도 힘들다.

 

간단한 예시가 있어 하나 가져오면

Positive Prompt : masterpiece, best quality, 1girl, black hair, golf course

 - 좋은 퀼러티의 검은머리 여자 한명이 골프장 배경으로 만들어라

 

Negative prompt: lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name

 - 안좋은 퀼리티나 일반으로 만들지 말고, 손 나쁘게 만들지 말고 사인이나 유저이름 나오게 하지 말고 등등)

 

Steps: 28, Sampler: DPM++ 2M Karras, CFG scale: 11, Seed: 2623692471, Face restoration: CodeFormer, Size: 512x768, Model hash: fc2511737a, Model: chilloutmix_NiPrunedFp32Fix, Denoising strength: 0.6, ENSD: 31337, Hires upscale: 1.5, Hires steps: 14, Hires upscaler: R-ESRGAN 4x+ Anime6B

 

샘플링 Step은 28로 - Step 수가 클수록 퀼리티가 좋아지고 속도는 느려진다.

CFG Scale 은 11로 - CFG Scale이 높을수록 프롬프트를 얼마나 따를지를 결정한다. 

Seed는 AI의 계산에 변수를 줘서 다양한 결과물이 나오도록 하는 값이다.

기타 등등...

 

우선 이걸 기본 프롬프트로 하고 아래 모델을 다운받아서 일단 만들어보자.

 

모델은 아래 두가지만 해보려고 한다.

 

1. orange mix : 애니메이션 같은 그림

 

WarriorMama777/OrangeMixs at main (huggingface.co)

 

* 여기 파일명을 보면 XXX_hard, XXX_nfsw, XXX_sfw 이렇게 뒤의 글자가 다른것을 알수 있다. 

hard : 글자 그대로 과격한 성행위 묘사

nsfw : not safe for work 일할때 안전하지 않아 즉 후방주의 정도 되겠고

sfw : safe for work 건전한 그림 이다.

 

2. ChilloutMix : 실사같은 그림

ChilloutMix | Stable Diffusion Checkpoint | Civitai

 

ChilloutMix | Stable Diffusion Checkpoint | Civitai

This model has been republished and its ownership transferred to Civitai with the full permissions of the model creator. They have asked that all i...

civitai.com

 

 

일단 orange mix로 만들어본거

masterpiece, best quality, 1girl, black hair, golf fieldNegative prompt: lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist nameSteps: 28, Sampler: DPM++ 2M Karras, CFG scale: 11, Seed: 918993248, Face restoration: CodeFormer, Size: 512x768, Model hash: 0873291ac5, Model: AbyssOrangeMix2_nsfw, Denoising strength: 0.6, Hires upscale: 1.5, Hires steps: 14, Hires upscaler: R-ESRGAN 4x+ Anime6B Time taken: 4m 6.20sTorch active/reserved: 1888/2456 MiB, Sys VRAM: 4096/4096 MiB (100.0%)

4분씩 걸리네.. 그나저나 뭘 들고 있는거냐? 이게 nfsw 로 만든거

 

masterpiece, best quality, 1girl, black hair, golf fieldNegative prompt: lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist nameSteps: 28, Sampler: DPM++ 2M Karras, CFG scale: 11, Seed: 602985742, Face restoration: CodeFormer, Size: 512x768, Model hash: 038ba203d8, Model: AbyssOrangeMix2_sfw, Denoising strength: 0.6, Hires upscale: 1.5, Hires steps: 14, Hires upscaler: R-ESRGAN 4x+ Anime6B Time taken: 3m 10.00sTorch active/reserved: 1888/2654 MiB, Sys VRAM: 4096/4096 MiB (100.0%)

이건 sfw로 만든거.. 대체 골프클럽을 장난감을 들고 있는 건가? 

 

 

자 이제 실사같은 그림을 만든다는 chilloutmix를 써서 해보자.

masterpiece, best quality, 1girl, black hair, golf fieldNegative prompt: lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist nameSteps: 28, Sampler: DPM++ 2M Karras, CFG scale: 11, Seed: 1393579719, Face restoration: CodeFormer, Size: 512x768, Model hash: fc2511737a, Model: chilloutmix_NiPrunedFp32Fix, Denoising strength: 0.6, Hires upscale: 1.5, Hires steps: 14, Hires upscaler: R-ESRGAN 4x+ Anime6B Saved: 00002-1393579719.png
masterpiece, best quality, 1girl, black hair, golf field Negative prompt: lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name Steps: 28, Sampler: DPM++ 2M Karras, CFG scale: 11, Seed: 2158228535, Size: 512x768, Model hash: fc2511737a, Model: chilloutmix_NiPrunedFp32Fix

face restoration 옵션과 hires.fix 옵션을 주지 않아 업스케일 되지않은 사이즈로 나왔다.

 

확실히 지난번에 비하면 꽤 좋아졌다!
다만 내 그래픽카드의 한계인지 그림 한장 만들면 반드시 하단의 reload ui를 해줘야 했다.

안그러면 또 out of memory...

 

 

어제에 이어 오늘은 프롬프트를 이래저래 해볼 요량으로 다시 webui-user.bat 를 실행시켰다.

어제 보단 확실히 빠르게 실행되긴 하는데 그래도 1분 정도는 걸리는것 같다.

그런데 가만히 보니 Error가 하나 있다.

No module 'xformers'. processding without it.

실행이 안되는건 아닌데 어제의 그 엉망인 결과물이 혹시 이때문은 아닌가 싶어 검색해보았다.

 

일단 xformers가 결과물의 퀄리티를 높여주는 것은 아니고

Nvidia GPU에서만 사용되는 기능으로 이미지의 생성속도를 높이고 VRAM 사용을 줄여 이미 생성시간을 단축시키는 역할을 한다고 한다.

 

비록 1050ti 지만 아니 그러니까 더욱 생성속도를 높이는게 맞지 않겠나 싶어 일단 시도해보기로 한다.

 

아래 방법은 실패했다 점선은 패스하고 일단 webui-user.bat 파일의 arg 옵션에 --xformers 해서 동작시켜보는게 좋다.

-------------------------------------------------------------------------------
Xformers · AUTOMATIC1111/stable-diffusion-webui Wiki · GitHub

 

Xformers

Stable Diffusion web UI. Contribute to AUTOMATIC1111/stable-diffusion-webui development by creating an account on GitHub.

github.com

 

여기에 자세히 나와이어 최대한 그대로 따라해보았지만 (이 과정에서도 우여곡절이 좀 있었다)

문제가 생겼다. T.T

그렇다고 실행이 안되는건 아니었는데

 

Generate를 해보니

안된다.. 그나마도 ㅠㅜ

일단 다시 처음부터 시작해보기로 한다.

 

파이썬과 git는 냅두고

webui 폴더 만 삭제해서 재설치 해보자.

 

-----------------------------------------------------------------

webui 재설치 후 webui-user.bat 실행

여전히 No module 'xofrmers' 나온다.

혹시나 전처럼 generate 자체가 안될까봐 실행해보니

그래도 이번엔 생성이 되었다. 걸린시간은 48.59초

 

자 이제 xformers 문제를 해결해보자.

검색해보니 webui-user.bat 파일 안에 argument에 --xformers 를 입력해주면 된다고 나온다.

이렇게 해주고 다시 실행

오오 이번엔 별문제 없이 잘 되었다.

처음에 한 삽질은 왜 한걸까? 아님 그 덕에 한번에 된건지 정확히 모르겠다.
뭐 vs studio 깔고 cuda 깔고 이런거 하기전에 --xformers 먼저 붙여보길 추천한다.

 

그럼 속도 향상은 있을까?

이런.. 이미지를 생성하다가 오류.. OutOfMemoryError. CUDA out of memory 

일단 내 GPU 메모리는 4G 인데 이미 2.27G 할당되어있고 pytoch에서 2.4G 예약되어 있어서 그렇다고 나온다.

이걸 또 해결해봐야지.

 

검색해보니 시스템 가상메모리 늘려보란다.

일단 넉넉하게 늘려보았다.

 

그리고 다시 실행하니 된다.

여기서 의문은 GPU 메모리 관련 오류인데 시스템 메모리를 늘려서 해결이 된게 맞는가 싶은데 여튼 된다.

* 2023.4.19 추가 argument, model 들을 추가해서 그림의 퀄리티를 높여가는 과정에서 동일하게 Out of Memory 증상이 나왔다. 즉 시스템메모리를 페이징으로 늘리는것은 해결책이 아니다.

argument에 --medvram 을 붙이면 해결되었다.

 

34초 걸림

 

34초

역시 34초 걸림 - 이게 골프치는 여자 맞어? ㅋㅋㅋ

 

일단 되는것 같다. 다른 명령어를 한번 넣어보자. "pretty girl who driving sports car"

이건 뭐 여자가 차를 친거 같다. 차가 사람을 치는게 아니고 --;

이건 좀 잘 나왔다.

모두 34초 걸렸다.

 

시간은 10여초 줄인것 같고 생성되는 이미지의 질은 별로 안변한것 같다.

여튼 동작을 하니 프롬프트 관련은 다음에 다시 해보자!

 

* Golf 관련 데이터가 적은가 Car에 비하면 이미지가 형편없다. ㅋ

요새 엄청 유행? 하고 있는 Stable Diffusion을 한번 해보기로 했다.

하필 가지고 있는 노트북들은 모두 내장그래픽에 CPU도 AMD이고

데스크탑이 그나마 AMD 3600에 Nvidia 1050ti, RAM 32G, SSD 1T 여서 여기다가 한번 해보려고 한다.
* 검색해보니 950ti로도 된다고 하는데 1050ti는 거의 최소사양 이다. 얼마나 걸리는지 궁금하다.

 

일단 나는 관련한 지식이 전혀 없고 호기심에 구글링 해가면서 진행해보려고 한다.

 

1. 우선 파이썬을 설치한다. 아래 링크에서 3.11.3을 설치했다. 

3.11 설치하면 나중에 에러 발생하여 3.11을 지우고 3.10.11을 다시 설치했다.

 

Download Python | Python.org

 

Download Python

The official home of the Python Programming Language

www.python.org

 

2. git을 설치한다. 아래 링크에서 2.40.0 standalone installer 버전으로 설치했다.

Git - Downloading Package (git-scm.com)

 

Git - Downloading Package

Download for Windows Click here to download the latest (2.40.0) 32-bit version of Git for Windows. This is the most recent maintained build. It was released about 1 month ago, on 2023-03-14. Other Git for Windows downloads Standalone Installer 32-bit Git f

git-scm.com

3. stable diffusion webui 설치

git의 설치가 완료되면 cmd로 명령프롬프트 창을 열어서 다운로드할 폴더로 이동한 다음

아래의 명령어로 webui를 다운로드 한다.
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

 

GitHub - AUTOMATIC1111/stable-diffusion-webui: Stable Diffusion web UI

Stable Diffusion web UI. Contribute to AUTOMATIC1111/stable-diffusion-webui development by creating an account on GitHub.

github.com

아래의 그림처럼 sd라는 폴더를 만들고 거기에 다운로드 했다.

 

stable-diffusion-webui 폴더로 이동하여 webui-user.bat 실행

아.. 그런데 error가 나왔다.

검색해보니 python 3.10 깔란다. 

[Bug]: ERROR: Could not find a version that satisfies the requirement torch==1.13.1+cu117 · Issue #7166 · AUTOMATIC1111/stable-diffusion-webui · GitHub

 

[Bug]: ERROR: Could not find a version that satisfies the requirement torch==1.13.1+cu117 · Issue #7166 · AUTOMATIC1111/stable

Is there an existing issue for this? I have searched the existing issues and checked the recent builds/commits What happened? When I run webui-user.bat I get error: stderr: ERROR: Could not find a ...

github.com

파이썬을 3.10.11을 다시 깔고 python을 찾을수 없다고 나오길래 venv 폴더에 들어가서 pyvenv.cfg 파일을 들어가보니

폴더가 기존의 3.11로 되어있어 새로 설치한 3.10에 맞춰 수정하고 저장했더니 된다.

 

다시 webui-user.bat 실행하니

처음에는 실행시 필요한 파일들 다운로드하느라 엄청 오래걸린다. (10분 넘게 걸린듯하다..)
자동으로 브라우저가 실행될 줄 알고 기다렸는데 메시지 보니 URL: http://127.0.0.1:7860 이 있길래

브라우저에 127.0.0.1:7860 을 치니 실행된다 ㅋ

cmd 명령프롬프트는 그대로 둬야한다.

 

일단 txt2img 에서 prompt에 "pretty girl who playing golf" 로 한번 시도해보았다.

그래픽카드 사용을 꽤 하긴하는데 그래도 잘 된다.

 

결과물은?

 

기본설정을 그대로두고 5번 했는데 한장당 40초 정도 걸리는듯하다.

여튼 결과물은.. 엉망이다 ㅋㅋㅋ

프롬프트도 그렇고 셋팅도 그렇고 좀 더 배워야겠다.

일단 오늘은 셋팅하고 되는거 확인한걸로 만족!

+ Recent posts