Stable Diffusion으로 Vector 이미지(SVG) 파일 자동 생성 방법

AI로 SVG를 생성하기 위해서는 오픈 소스 기반 이미지 생성 AI 툴인 Stable Diffusion과 SVG 생성 인스텐션인 Vector Studio를 이용할 수 있다.

Stabel Diffusion을 이용하는 가장 쉬운 방법인 stable diffusion webui와 Vector Studio를 설치하고 이용하는 방법을 가능한 쉽게 정리하였음

참고사이트

설치하기

💡 여기서 설명하는 extension(Vector Studio)은 현재 윈도우만 지원하므로 여기서 설명하는것은 윈도우10을 기준으로함

먼저 nvidia GPU를 사용하고 있다면 CUDA를 설치한다.

그리고 나서 다음을 순서대로 따라한다.

Stable Diffusion WebUI 설치

# 1. 기본 패키지 다운로드 및 압축풀기
https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases/download/v1.0.0-pre/sd.webui.zip

# 2. 업데이트
> update.bat

# 3. 실행
> run.bat

크롬 브라우저에서 아래 URL을 열었을때 다음과 같은 화면이 나오면 제대로 설치가 된것임

http://127.0.0.1:7860/

  • 아래 화면과 같이 디폴트 설정에서 “txt2img” 탭에서 “pretty girl”을 입력하고 Generate 버튼을 눌렀을 때 아래 화면이 나오는지 확인함

Vector Studio 익스텐션 설치

💡 Vector Studio는 다음과 같은 방법을 이용하여 단계적으로 SVG 벡터 이미지를 생성함

  1. SVG 벡터 이미지로 변환하기 좋은 형태의 흑백 이미지를 생성함
  2. POTRACE 툴을 이용하여 비트맵 이미지를 SVG 벡터 이미지로 변환함

위의 UI에서 “Extensions” > “Install From URL”을 차례대로 선택함

그리고 URL for extension’s git repository에 아래 GIT URL을 입력하고 “Install “ 버튼을 누름

https://github.com/GeorgLegato/stable-diffusion-webui-vectorstudio.git

설치가 완료되면 페이지 하단의 “Reload UI”를 클릭함

익스텐션이 정상적으로 설치되었다면 아래와 같이 Vector Studio 탭이 생기고 하단 Script 선택항목에도 “Vector Studio”가 추가됨

프롬프트에 “pretty girl”이라고 입력하고 생성해보면 아래와 같이 png 파일뿐만 아니라 svg 파일까지 생성된다.

만약 svg 파일이 생성되지 않고 command 창에 다음과 같은 에러가 보인다면 svg 변환 프로그램인 potrace 설치가 잘못 된 가능성이 크므로 다음과 같이 potrace를 수동 설치한다.

potract 수동 설치 방법

  • potrace 실행 에러 메시지
*** Error completing request
*** Arguments: ('task(q8w25so3l2awfa2)', 'pretty girl', '', [], 20, 0, False, False, 1, 1, 7, -1.0, -1.0, 0, 0, 0, False, 512, 512, False, 0.7, 2, 'Latent', 0, 0, 0, 0, '', '', [], <gradio.routes.Request object at 0x00000260D31A8310>, 4, False, False, 'positive', 'comma', 0, False, False, '', 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0, 'Illustration', 'svg', True, True, False, 0.5, False, 16, True, 16) {}
    Traceback (most recent call last):
      File "D:\sd_webui\sd.webui\webui\extensions\stable-diffusion-webui-vectorstudio\scripts\vectorstudio.py", line 215, in run
        self.doVector(poFormat, poOpaque, poTight, poKeepPnm, poThreshold, PO_TO_CALL, img, fullofpnm, fullof, mixedImages)
      File "D:\sd_webui\sd.webui\webui\extensions\stable-diffusion-webui-vectorstudio\scripts\vectorstudio.py", line 231, in doVector
        p2 = subprocess.Popen(args)
      File "subprocess.py", line 969, in __init__
      File "subprocess.py", line 1438, in _execute_child
    OSError: [WinError 216] %1의 버전이 실행 중인 Windows 버전과 호환되지 않습니다. 컴퓨터의 시스템 정보를 확인하고 소프트웨어 게시자에게 문의하십시오

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "D:\sd_webui\sd.webui\webui\modules\call_queue.py", line 58, in f
        res = list(func(*args, **kwargs))
      File "D:\sd_webui\sd.webui\webui\modules\call_queue.py", line 37, in f
        res = func(*args, **kwargs)
      File "D:\sd_webui\sd.webui\webui\modules\txt2img.py", line 59, in txt2img
        processed = modules.scripts.scripts_txt2img.run(p, *args)
      File "D:\sd_webui\sd.webui\webui\modules\scripts.py", line 501, in run
        processed = script.run(p, *script_args)
      File "D:\sd_webui\sd.webui\webui\extensions\stable-diffusion-webui-vectorstudio\scripts\vectorstudio.py", line 218, in run
        raise Exception("VectorStudio: Execution of Potrace failed, check filesystem, permissions, installation or settings (is image saving on?)")
    Exception: VectorStudio: Execution of Potrace failed, check filesystem, permissions, installation or settings (is image saving on?)

potract 수동 설치 방법

Line Art 모델 설치

위에서는 기본 모델을 이용했는데 이렇게 하면 SVG로 변환이 잘 되는 이미지를 얻기가 어렵기 때문에 다음 링크를 통해 Line Art 전용 모델을 다운로드 받는다. (아래 2개 파일 다운로드함)

이 2개의 파일을 아래 경로에 이동시킨다.

webui\models\Stable-diffusion

그리고 command 프로그램인 run.bat를 새로 실행후에 UI를 새로고침하면 아래와 같이 좌측 상단에서 새로운 모델을 선택할 수 있다.

그리고 prompt에 아래 명령을 입력해본다.

monochrome lineart, black on white of a happy cute tiger toon

그리고 아래 빨간색 박스로 표시한 옵션을 참고해서 생성해본다. 이미지와 svg가 모두 잘 생성되었다면 정상적으로 동작한 것이다.

Leave a Comment