글 작성일: 2024년 9월 12일 (목)
안녕하세요. 요거트 @yoghurty 입니다!
오늘 개발이야기는 약간 옆길로 샜습니다. 😆
나의 로컬 PC에서 인공지능(AI)을 이용한 고품질 이미지를 생성할 수 있다는 @anpigon 님의 포스팅을 보고,
재미있을 것 같아 바로 따라해봤습니다!
👉 M2 맥북 Pro에서 Flux Schnell 로컬 모델로 고품질 이미지 생성하기
따라하기
1. Flux Schnell 실습을 위한 conda 환경을 설정하고 활성화 시킵니다.
conda create -n flux python=3.11
conda activate flux
2. AI 그림을 그리는데 필요한 패키지 들을 설치합니다.
pip install torch==2.3.1
pip install git+https://github.com/huggingface/[email protected]
pip install transformers==4.43.3 sentencepiece==0.2.0 accelerate==0.33.0 protobuf==5.27.3
3. python 코드를 작성합니다.
- M2 맥북용 코드입니다^^
import torch
from diffusers import FluxPipeline
import diffusers
_flux_rope = diffusers.models.transformers.transformer_flux.rope
def new_flux_rope(pos: torch.Tensor, dim: int, theta: int) -> torch.Tensor:
assert dim % 2 == 0, "The dimension must be even."
if pos.device.type == "mps":
return _flux_rope(pos.to("cpu"), dim, theta).to(device=pos.device)
else:
return _flux_rope(pos, dim, theta)
diffusers.models.transformers.transformer_flux.rope = new_flux_rope
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", revision="refs/pr/1", torch_dtype=torch.bfloat16).to("mps")
prompt = "A cat holding a sign that says hello world"
out = pipe(prompt=prompt, guidance_scale=0.0, height=1024, width=1024, num_inference_steps=4, max_sequence_length=256,).images[0]
out.save("flux_image.png")
Hello World!
prompt = "A cat holding a sign that says hello world"
prompt 변경하여 다른 그림 그려보기
Flux Schnell 모델을 로딩하여 그림을 그려주는 python 코드의 prompt 를 변경해 보았습니다.
prompt = "Santa Claus holding a sign that says Merry Christmas, snowy background, Christmas atmosphere"
ChatGPT (Dall-e)로 그린 그림
ChatGPT로 그리면 어떤 그림이 나올까 갑자기 궁금해졌습니다. ^^
같은 prompt를 이용해서 ChatGPT가 그린 그림입니다.
마무리
첫 그림을 그릴때는 시간이 꽤 많이 걸렸는데,
두 번째 그림 부터는 왠지 그림 그리는 속도가 많이 단축된 느낌이 들었습니다.
다양한 prompt를 사용해 보지 않았고,
그림을 많이 그려본 것은 아니지만,
ChatGPT와 견주어도 손색없을 만큼 정말 고품질의 이미지 같은 생각이 드네요! ^^
AI그림 그려주는 다른 구독 서비스 받지 않고,
나의 로컬 PC 에서 내가 직접 AI를 이용해 그림을 그려냈다니~ 신기했습니다! ^^
좋은 기회를 주신 @anpigon 님께 감사드립니다! ^^
이상 요거트 였습니다!
고맙습니다. ^^
Upvoted! Thank you for supporting witness @jswit.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
대단하시네요~ 저는 한 달 3만원 chatGPT로 그리는데 부럽습니다~
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
아~ 저도 이번에 처음으로 Flux Schnell 이란 것을 사용해봤습니다. ^^
ChatGPT는 그림 생성 뿐만아니라 다른 용도로도 충분히 활용 가능하니 그림만 그리는 Flux Schnell 하고 비교하기는 좀~ 아무래도 체급이... ^^;
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
저도 피곤님 글보고 해봐야지 했는데
못해봤는데 잘 따라 하셨네요.
저는 맥이 아니라서 T.T NPU는 없습니다.
CPU 밖에 없는데 T.T
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
저도 처음에 Virtual Box에 설치한 우분투로 따라했었는데... 잘 안되었습니다. ㅠㅠ
그래서~ 결국 맥으로... ^^;
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
가야태자님은 맥북이 아니시군요. ㅠㅠ
그렇다면 Google Colab 에서 무료 GPU를 할당받아서 생성해볼 수 있어요.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
한참 그림그리는 재미에 빠져있었는데... 이제 흥미가 없어졌네요 ㅎㅎ
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
흥미는 종종 바뀌는 것 같습니다!
지금은 재미있게 AI로 그림도 그려보고 있지만... 나중에 또 다른데 흥미가 생길지도 모를 것 같아요~ ^^
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
요거트님도 맥북을 사용 중이시군요. AI 분야에서는 맥북이 여러모로 유용하죠. ㅎㅎ
첫 번째 그림을 그릴 때는 모델을 다운로드하는 시간이 필요해서, 아마 시간이 오래 걸렸을 거예요.
저는 글 작성할 때 대문 이미지를 Flux로 생성해보려고 해요. ㅎㅎ
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
대문이미지를 flux로 생성하여 활용 할수 있다면 로컬 PC의 활용을 극대화하는 좋은 방법 중의 하나가 될 것 같습니다~ 저도 한번 그렇게 시도해봐야 겠네요~^^
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit