반업주부의 일상 배움사

Openjourney로 마음껏 그림 생성하기 :: 허깅페이스(HuggingFace) 모델 사용 예제 본문

IT 인터넷/GCP

Openjourney로 마음껏 그림 생성하기 :: 허깅페이스(HuggingFace) 모델 사용 예제

Banjubu 2023. 2. 13. 21:39
반응형

 

오픈저니(Openjourney)는 미드저니(Midjourney)의 오픈소스 버전이에요.

 

GCP에서 윈도우 서버를 생성했어요. (이게 거의 최저 사양, VSCode 띄우면 메모리 부족함)

2 vCPU + 7.5 GB memory
US$88.97
 
2 NVIDIA T4
US$540.20
 
 프리미엄 이미지 사용 수수료*
알 수 없음
 
250GB SSD 영구 디스크
US$55.25
 
사용 할인
-US$188.75
 
Total
US$495.67
 

 

일단 크롬과 VSCode 설치하고요.

 

CUDA 툴킷 설치하고 설치폴더/bin 폴더를 환경변수에 추가했어요.

https://developer.nvidia.com/cuda-downloads

 

CUDA Toolkit 11.7 Downloads

Get the latest feature updates to NVIDIA's proprietary compute stack.

developer.nvidia.com

 

확인

$ nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Fri_Jan__6_19:04:39_Pacific_Standard_Time_2023
Cuda compilation tools, release 12.0, V12.0.140
Build cuda_12.0.r12.0/compiler.32267302_0

 

아나콘다 설치

https://www.anaconda.com/

 

Anaconda | The World's Most Popular Data Science Platform

Anaconda is the birthplace of Python data science. We are a movement of data scientists, data-driven enterprises, and open source communities.

www.anaconda.com

 

윈도우 재부팅

 

pytorch 설치

$ conda create --name pytorch-env python=3.7
$ conda activate pytorch-env
$ pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117

 

확인

import torch
print(torch.__version__)

# 1.12.1

 

허깅페이스(HuggingFace) 로그인

$ pip install huggingface_hub
$ huggingface-cli login

 

허깅페이스 토큰

https://huggingface.co/settings/tokens

 

Hugging Face – The AI community building the future.

 

huggingface.co

 

diffusers 설치

$ pip install diffusers
$ pip install transformers
$ pip install accelerate

 

main.py

from diffusers import StableDiffusionPipeline
import torch
model_id = "prompthero/openjourney"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to("cuda")
prompt = "Elsa, d & d, fantasy, intricate, elegant, highly detailed, digital painting, artstation, concept art, matte, sharp focus, illustration, hearthstone, art by artgerm and greg rutkowski and alphonse mucha, hdr 4k, 8k, mdjrny-v4 style"
image = pipe(prompt).images[0]
image.save("./elsa.png")

 

실행

$ python main.py

 

결과

 

 

 

반응형
LIST
Comments