본문 바로가기

Deep Learning/Diffusion

DiffStyler 써보기

DiffStyler 논문 리뷰, DiffStyler 코드 리뷰


이렇게 시간이 오래 걸릴 줄 몰랐는데 원본 코드가 그냥 코드뭉치라 정상적으로 돌아가게 만드는 데 한참이나 걸렸다. 다른 환경에서 돌려보지도 않고 코드를 공개하다니...(물론 공개해 준 것은 고맙지만)

치열한 사투의 흔적...

!git clone https://github.com/haha-lisa/Diffstyler
!git clone https://github.com/zyxElsa/CAST_pytorch
!git clone https://github.com/JunlinHan/DCLGAN
%cd /content/Diffstyler

!pip install -e ./CLIP
!pip install -r requirements.txt

import urllib
import os

os.replace('/content/CAST_pytorch/models/net.py', '/content/Diffstyler/net.py')
os.replace('/content/DCLGAN/models', '/content/Diffstyler/models')
urllib.request.urlretrieve('https://the-eye.eu/public/AI/models/v-diffusion/cc12m_1_cfg.pth',filename='/content/Diffstyler/checkpoints/cc12m_1_cfg.pth')
urllib.request.urlretrieve('https://the-eye.eu/public/AI/models/v-diffusion/wikiart_256.pth',filename='/content/Diffstyler/checkpoints/wikiart_256.pth')

#/content/Diffstyler/diffusion/models/models.py 이 파일에서 cc12m_1,wikiart_256 빼고 다 지우기

#main.py
#22행 from models import networks 로 바꾸기
#import easydict 추가
#184행 gpu_ids default값 '1' -> [0]으로 변경
#209행 define_F 인수에 opt = easydict.EasyDict({'netF_nc' : 256}) 추가
#326, 327행 feat_k.unsqueeze(0), feat_q.unsqueeze(0)

NCE loss가 문제가 많아서 이걸 해결하는 데만 대부분의 시간을 보냈다.

그리고 문제를 다 해결했는데도 논문의 성능을 100% 쓸 수 없는게, NCE loss를 구하는 데에 netF의 가중치가 필요한데 netF의 코드는 DCLGAN repository에서 가져온 것이고, 해당 모델은 추론에 netF의 가중치가 필요없어서 구할 수가 없고... DiffStyler 제작자도 확산 모델 가중치만 올려놔서... 그래도 없는 것 보단 있는 게 훨씬 낫다. (아래 그림 오른쪽이 없는 거)

Prompt : An oil painting of a dog in impressionism style.


Prompt :The wonderful painting shows a castle and garden in the sky on top of a hill with a waterfall and bright sunshine, which is a bit like heaven.


Prompt : This is a painting of teddy bear in the forest in the style of cubism


Prompt : A pencil drawing of the Statue of Liberty
고유명사 같은 건 잘 안되는 듯


Prompt : A pencil drawing of a city


Prompt : A small village between a lake and snow-covered mountains, expressed in ink and wash.


Prompt : A paint of a tiger half submerged in water in cubism style.


Prompt : A cartoon painting of a cat.


Prompt : A paint of a goat in fauvism style.


Prompt : An oil painting of a rooster in impressionism style.


총평 : Styler transfer 능력 자체는 매우 괜찮은 듯. 괜찮은 결과물을 뽑는 프롬프트 정하는 법도 익숙해지면 더 잘 뽑을 수 있을 듯. 근데 저해상도이고 Dual model architecture라서 조금 느린 것이 단점.

'Deep Learning > Diffusion' 카테고리의 다른 글

Stable Diffusion, SDXL U-Net Architecture 살펴보기  (2) 2023.10.05
Paint by Example 써보기  (1) 2023.01.13
DAAM 써보기  (1) 2023.01.13