* ๋กœ๊ทธ์ธ์„ ํ•˜๊ณ  ํฌ๋กค๋ง์„ ํ•˜๋Š” ์ด์œ 

  1. ๊ตฌ๊ธ€์˜ ๊ฒฝ์šฐ ๋กœ๊ทธ์ธํ•˜๊ณ  ๋‚˜์˜ค๋Š” ์ด๋ฏธ์ง€์™€ ๋กœ๊ทธ์ธ์„ ํ•˜์ง€ ์•Š๊ณ  ๋‚˜์˜ค๋Š” ์ด๋ฏธ์ง€ ๋ชฉ๋ก์ด ๋‹ค๋ฅผ๋•Œ๊ฐ€ ๋งŽ๋‹ค.
  2. ์„ฑ์ธ์ธ์ฆ์ด ํ•„์š”ํ•œ ์ด๋ฏธ์ง€๋“ค์€ ๋กœ๊ทธ์ธ์„ ํ•ด์•ผ๋งŒ ๊ฐ€์ ธ์˜ฌ์ˆ˜ ์žˆ๋‹ค.

 

* ์‚ฌ์šฉ๋ฒ•

  1. ์ •์ƒ์ ์œผ๋กœ ํฌ๋กค๋ง๋˜๋Š”์ง€ ํ™•์ธ์™„๋ฃŒ [23.06.20]
  2. ๋ชจ๋“ˆ ์„ค์น˜ - pip install undetected_chromedriver selenium
  3. ์ฃผ์„ 1๋ฒˆ์— ์ด๋ฏธ์ง€๋ฅผ ์›ํ•˜๋Š” ๊ฒ€์ƒ‰์–ด ๋ชฉ๋ก ์ž…๋ ฅ
  4. ์ฃผ์„ 2๋ฒˆ์— ํด๋”์ด๋ฆ„ ์ž…๋ ฅ. ์ด๋ฏธ์ง€๋Š” data\google\ ์•„๋ž˜ ์ €์žฅ๋จ
  5. ์ฃผ์„ 3๋ฒˆ์— ์ƒ์„ธ์ด๋ฏธ์ง€์˜ xPath ์ž…๋ ฅ. ๊ตฌ๊ธ€์˜ ๊ฒฝ์šฐ ์ž์ฃผ ๋ฐ”๋€Œ๋Š” ๊ฒƒ ๊ฐ™๋‹ค.
  6. ์ฃผ์„ 4๋ฒˆ์— ๊ตฌ๊ธ€ ID์ž…๋ ฅ
  7. ์ฃผ์„ 5๋ฒˆ์— ๊ตฌ๊ธ€ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ. ์ดํ›„ ์ถ”๊ฐ€๋กœ ์Šค๋งˆํŠธํฐ ์ธ์ฆํ™”๋ฉด์ด ๋œฐ ๊ฒฝ์šฐ์— ๋Œ€๋น„ํ•ด 20์ดˆ๊ฐ„ ๊ธฐ๋‹ค๋ฆฐ๋‹ค.
'''
* ๊ตฌ๊ธ€ ์ด๋ฏธ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ (23.06.20)
'''

import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import undetected_chromedriver as uc

import urllib
import time, datetime

ITEM_LIST = [ "Keith Thompson", "Zdzislaw Beksinski", "dariusz zawadzki"] # 1๋ฒˆ
FOLDER = 'google' # 2๋ฒˆ
IMG_XPATH = '//*[@id="Sva75c"]/div[2]/div/div[2]/div[2]/div[2]/c-wiz/div/div/div/div[3]/div[1]/a/img[1]' # 3๋ฒˆ
SIGNINURL = 'https://accounts.google.com/signin/v2/identifier?hl=ko&passive=true&continue=https%3A%2F%2Fwww.google.com%2F&ec=GAZAmgQ&flowName=GlifWebSignIn&flowEntry=ServiceLogin'
ID = 'xxxx@gmail.com' # 4๋ฒˆ
PASSWORD = 'xxxx' # 5๋ฒˆ

def main():
  start = check_start() # ์‹œ๊ฐ„ ์ธก์ • ์‹œ์ž‘
  driver = uc.Chrome()# ๊ตฌ๊ธ€๋กœ๊ทธ์ธ์„ ์œ„ํ•œ ๋ชจ๋“ˆ์„ ์ผœ๊ณ 
  driver.get(SIGNINURL)
  googleSignIn(driver)# ๊ตฌ๊ธ€๋กœ๊ทธ์ธํ•˜๊ณ 
  
  for searchItem in ITEM_LIST:
    saveDir = makeFolder(searchItem)
    
    url = makeUrl(searchItem)# ๊ฒ€์ƒ‰ํ•  url ๊ฐ€์ ธ์™€์„œ
    driver.get(url)# ์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰์œผ๋กœ ๊ฐ€์„œ
    maximizeWindow(driver)# ์ฐฝ์ตœ๋Œ€ํ™”
    scrollToEnd(driver)

    forbiddenCount = saveImgs(driver, saveDir, start)# ๋ชจ๋“  ์ƒ์„ธ ์ด๋ฏธ์ง€ src๋“ค์„ ๊ฐ€์ ธ์˜จ๋‹ค
    sec = check_time(start)
    print(f'์‹คํŒจ์ˆ˜{str(forbiddenCount)}, {sec}, {datetime.datetime.now().time()}')
  time.sleep(10)
  driver.quit() 
  
# ๊ตฌ๊ธ€ ๋กœ๊ทธ์ธ
def googleSignIn(driver):
  idBtn = driver.find_element(By.XPATH,'//*[@id="identifierId"]')# id ์ž…๋ ฅ์นธ
  idBtn.send_keys(ID)
  nextBtn = driver.find_element(By.XPATH,'//*[@id="identifierNext"]/div/button')
  nextBtn.click()# ๋‹ค์Œ ๋ฒ„ํŠผ ํด๋ฆญ

  # ์•„๋ž˜ ์ฝ”๋“œ๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ ์š”์†Œ๊ฐ€ ํ™”๋ฉด์— ๋‚˜ํƒ€๋‚ ๋•Œ๊ฐ€์ง€ 10์ดˆ๊ฐ„ ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ฝ”๋“œ์ด๋‚˜
  # ๋น„๋ฒˆ์˜ ๊ฒฝ์šฐ not interactive elem๋ผ์„œ ์—๋Ÿฌ๊ฐ€ ๋œฌ๋‹ค. ํ•˜์ง€๋งŒ ๋Œ์•„๊ฐ€๋Š” ์ฝ”๋“œ์ด๋‹ˆ ๊ธฐ๋‹ค๋ฆผ์ด ํ•„์š”ํ• ๋•Œ ์“ฐ์ž.
  try:
    passwordBtn = WebDriverWait(driver, timeout=10).until(EC.presence_of_element_located( (By.XPATH,'//*[@id="password"]/div[1]/div/div[1]/input') ))
    time.sleep(4)
    passwordBtn = driver.find_element(By.XPATH,'//*[@id="password"]/div[1]/div/div[1]/input')# ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ์นธ
    passwordBtn.send_keys(PASSWORD)
    passwordNextBtn = driver.find_element(By.XPATH,'//*[@id="passwordNext"]/div/button')
    passwordNextBtn.click()# ๋น„๋ฐ€๋ฒˆํ˜ธ ๋‹ค์Œ ๋ฒ„ํŠผ
    print('๊ตฌ๊ธ€ ๋กœ๊ทธ์ธ ์„ฑ๊ณต')
    # driver.implicitly_wait(10)
  except OSError as e:
    print(e)
    
  time.sleep(20)# ํœด๋Œ€ํฐ ๋ณธ์ธ ์ธ์ฆ๋“ฑ์˜ ์‹œ๊ฐ„์ด ์ถฉ๋ถ„ํžˆ ํ•„์š”ํ•˜๋‹ค


# ๊ตฌ๊ธ€ ์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰ url ๋งŒ๋“ค๊ธฐ
def makeUrl(searchItem):
  url = 'https://www.google.com/search'
  params ={# q์™€ tbm์ด ํ•„์ˆ˜
    'q'     : searchItem,
    'tbm'   : 'isch',
  }
  url = url + '?' + urllib.parse.urlencode(params)
  return url


# ํด๋” ์ƒ์„ฑ
def makeFolder(searchItem):
  saveDir = os.path.join(os.getcwd(), 'data', f'{FOLDER}_{searchItem}')
  try:
    if not(os.path.isdir(saveDir)): # ํ•ด๋‹น ํด๋”๊ฐ€ ์—†๋‹ค๋ฉด
      os.makedirs(os.path.join(saveDir)) # ๋งŒ๋“ค์–ด๋ผ
    return saveDir
  except OSError as e:
    print(e+'ํด๋” ์ƒ์„ฑ ์‹คํŒจ')

# ์ฐฝ ์ตœ๋Œ€ํ™”
def maximizeWindow(driver):
  driver.maximize_window()

# ๋ชจ๋“  ์ด๋ฏธ์ง€ ๋ชฉ๋ก์„ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด ๋ฌดํ•œ ์Šคํฌ๋กค ๋‹ค์šด
def scrollToEnd(driver):
  prev_height = driver.execute_script('return document.body.scrollHeight')
  print(f'prev_height: {prev_height}')
  
  while True:
    time.sleep(1) #๋„ค์ด๋ฒ„๋Š” sleep์—†์ด ์ด๋™ํ•  ๊ฒฝ์šฐ ๋ฌดํ•œ๋กœ๋”ฉ์— ๊ฑธ๋ฆฐ๋‹ค.
    driver.execute_script('window.scrollTo(0, document.body.scrollHeight)')
    time.sleep(3)
    
    cur_height = driver.execute_script('return document.body.scrollHeight')
    print(f'cur_height: {cur_height}')
    if cur_height == prev_height:
      print('๋†’์ด๊ฐ€ ๊ฐ™์•„์ง')
      break
    prev_height = cur_height
  # ํŽ˜์ด์ง€๋ฅผ ๋ชจ๋‘ ๋กœ๋”ฉํ•œ ํ›„์—๋Š” ์ตœ์ƒ๋‹จ์œผ๋กœ ๋‹ค์‹œ ์˜ฌ๋ผ๊ฐ€๊ธฐ
  driver.execute_script('window.scrollTo(0, 0)')

# ๋ชจ๋“  ์ด๋ฏธ์ง€๋“ค์„ ์ €์žฅํ•œ๋‹ค
def saveImgs(driver, saveDir, start):
  time.sleep(1)
  forbiddenCount = 0
  imgs = driver.find_elements(By.CSS_SELECTOR, '.rg_i.Q4LuWd')
  img_count = len(imgs)
  print(f'์ „์ฒด ์ด๋ฏธ์ง€์ˆ˜ : {img_count}')
  # ํ•˜๋‚˜์”ฉ ํด๋ฆญํ•ด๊ฐ€๋ฉฐ ์ €์žฅ
  for imgNum, img in enumerate(imgs): # imgNum์— ์ด๋ฏธ์ง€๋ฒˆํ˜ธ๊ฐ€ 0๋ถ€ํ„ฐ ๋“ค์–ด๊ฐ„๋‹ค
    try:
      img.click()
      time.sleep(3)
      
      # ์•„๋ž˜์˜ xPath๋Š” ์ž์ฃผ ๋ฐ”๋€Œ๋Š” ๊ฒƒ ๊ฐ™๋‹ค. ๋‚˜๋จธ์ง€๋Š” ๊ณ ์ •์ธ๊ฑฐ ๊ฐ™์œผ๋‹ˆ ์ด๊ฒƒ๋งŒ ๊ฐ€๋” ํ™•์ธํ•ด์ฃผ์ž
      bigImg = driver.find_element(By.XPATH, IMG_XPATH)
      src = bigImg.get_attribute('src')
      urllib.request.urlretrieve(src, saveDir + '/' + str(imgNum) + '.jpg')
      sec = check_time(start)
      print(f'{imgNum+1}/{img_count} saved {sec}')

    except Exception as e:
      print(e)
      forbiddenCount += 1# ์ €์žฅ ์‹คํŒจํ•œ ๊ฐœ์ˆ˜. forbidden์ด๋‚˜ ํŒŒ์ผ์—๋Ÿฌ๋„ ๊ฝค ๋งŽ๋‹ค
      continue
  return forbiddenCount


# ์‹œ๊ฐ„ ์ธก์ •
def check_start():
    start_time = time.time()
    print("Start! now.." + str(start_time))
    return start_time
def check_time(start):
    end = time.time()
    during = end - start
    sec = str(datetime.timedelta(seconds=during)).split('.')[0]
    return sec
main()

* ์ƒ์„ธ ์ด๋ฏธ์ง€์˜ xPath ์•Œ์•„๋‚ด๋Š” ๋ฐฉ๋ฒ•

- ํฌ๋กฌ์˜ ์ด๋ฏธ์ง€ ํด๋ฆญ ํ›„ ๋œจ๋Š” ์ƒ์„ธ์ด๋ฏธ์ง€ ํ™”๋ฉด์—์„œ ํ•ด๋‹น elements์˜ xPath๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ๋ณต์‚ฌํ•จ

 

๋‹ค์Œ์—๋Š” headless ํฌ๋กค๋ง์— ๋Œ€ํ•ด ์ •๋ฆฌํ•˜๊ฒ ๋‹ค

- headless ํฌ๋กค๋ง์€ ํ™”๋ฉด์— ๋ธŒ๋ผ์šฐ์ € ์ฐฝ์„ ๋„์šฐ์ง€ ์•Š๊ณ  ๋ฉ”๋ชจ๋ฆฌ์—์„œ๋งŒ ์ž‘๋™ํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค.

๋„ค์ด๋ฒ„ ์ด๋ฏธ์ง€ ํฌ๋กค๋งํ•˜๊ธฐ

๋™๊ธฐ

1. ์ข‹์€ ๋กœ๋ผ๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ด๋ฏธ์ง€ ํŒŒ์ผ๋“ค์ด ๋งŽ์„์ˆ˜๋ก ์ข‹๋‹ค.
2. ๊ฒฝํ—˜์ƒ ์ด๋ฏธ์ง€ ํ€„๋Ÿฌํ‹ฐ๋Š” ๊ตฌ๊ธ€๋ณด๋‹ค ๋„ค์ด๋ฒ„๊ฐ€ ๋” ์ข‹์•˜๋‹ค - ๋ฌผ๋ก  ๊ตฌ๊ธ€ ์ด๋ฏธ์ง€ ํฌ๋กค๋ง ์ฝ”๋“œ๋„ ๊ณต์œ ํ•  ์˜ˆ์ •
3. ๋„ค์ด๋ฒ„๋Š” ๊ตฌ๊ธ€์— ๋น„ํ•ด ํฌ๋กค๋ง์— ๊ด€๋Œ€ํ•˜๋‹ค. ๊ทธ๋ž˜์„œ ์ฝ”๋“œ๊ฐ€ ๊ฐ„๊ฒฐํ•ด์ง„๋‹ค - ๊ตฌ๊ธ€์€ undetected_chromedriver ๋“ฑ์„ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค.

 

์‚ฌ์šฉ๋ฒ•

1. 2023๋…„ 6์›” 19์ผ ํ˜„์žฌ ์•„๋ž˜ ์ฝ”๋“œ๋Š” ์ž˜ ๋Œ์•„๊ฐ„๋‹ค. ์‚ฌ์šฉํ•˜๊ธฐ ์‰ฝ๊ฒŒ ์ฃผ์„์„ ๋งŽ์ด ๋‹ฌ์•„๋†“์•˜๋‹ค.
2. ์…€๋ฆฌ๋‹ˆ์›€์ด๋‚˜ urllib๋“ฑ์˜ ๋ชจ๋“ˆ ์„ค์น˜๊ฐ€ ์šฐ์„ ์ด๋‹ค.
pip install selenium
3. ์‹คํ–‰ ํ›„ ํฌ๋กฌ์ฐฝ์ด ๋œจ๊ณ  ์ฐฝ์ด ์ตœ๋Œ€ํ™” ๋œ๋‹ค. 
4. ์ž๋™์œผ๋กœ ์Šคํฌ๋กค๋˜๋ฉฐ ์ด๋ฏธ์ง€ ๋ชฉ๋ก์„ ๊ฐ€์ ธ์˜จ๋‹ค. ์ด๋•Œ๋Š” ์ฐฝ์„ ๋‚ด๋ฆฌ์ง€๋ง๊ณ  ์Šคํฌ๋กค์ด ๋๊นŒ์ง€ ๋‚ด๋ ค๊ฐ€ ๋” ์ด์ƒ ๊ฐ€์ ธ์˜ฌ ์ด๋ฏธ์ง€๊ฐ€ ์—†์„๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ ค์ฃผ์ž. ์ด๋ฏธ์ง€ ๋ชฉ๋ก์„ ๋‹ค ๊ฐ€์ ธ์˜จ ํ›„ ์ž๋™์œผ๋กœ ์Šคํฌ๋กค์ด ๋งจ์œ„๋กœ ์˜ฌ๋ผ๊ฐ„๋‹ค. ์ด ๋‹ค์Œ๋ถ€ํ„ฐ๋Š” ์ฐฝ์„ ๋‚ด๋ ค๋„ ๋œ๋‹ค. 
5. ๊ฐ€์ ธ์˜ค๊ธธ ์›ํ•˜๋Š” ์ด๋ฏธ์ง€ ์ด๋ฆ„์„ ์•„๋ž˜ ์ฝ”๋“œ์˜ item_list ์•ˆ์— ๋„ฃ๋Š”๋‹ค. ์ฃผ์„ #1๋ฒˆ
6. ํด๋” ์ด๋ฆ„์„ ์ฃผ์„#2๋ฒˆ์— ๋„ฃ๋Š”๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ์ฒ˜๋Ÿผ naver๋กœ ํ•  ๊ฒฝ์šฐ ์ด๋ฏธ์ง€๋Š” data\naver\ ์•ˆ์— ์ €์žฅ๋œ๋‹ค. ํ•ด๋‹น ํด๋”๋ฅผ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด ๋†“์ง€ ์•Š์•„๋„ ์•Œ์•„์„œ ๋งŒ๋“ค๊ณ  ์ €์žฅํ•œ๋‹ค.
7. ์ƒ์„ธ ์ด๋ฏธ์ง€์˜ xpath๋ฅผ ๋„ฃ๋Š”๋‹ค. ์ฃผ์„#3๋ฒˆ. ํฌ๋กค๋ง์„ ํ•ด๋ณด๋‹ˆ xpath๊ฐ€ ์•„~์ฃผ ๊ฐ€๋” ๋ฐ”๋€”๋•Œ๊ฐ€ ์žˆ๋‹ค. ์•„๋งˆ ๊ทธ๋Œ€๋กœ  ๋†”๋‘ฌ๋„ ํฐ ๋ฌธ์ œ์—†์„ ๊ฒƒ์ด๋‹ค.

 

์ตœ์‹  ํด๋ž˜์Šค์™€ xPath๋กœ ์žฌ์„ค์ • ํ•จ - 24.07.26

'''
* ๋„ค์ด๋ฒ„ ์ด๋ฏธ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ (24.07.26)
'''

import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
import urllib
import time, datetime

item_list = [ "๋„๋‹ค๋ฆฌ"] # 1๋ฒˆ
FOLDER = 'naver' # 2๋ฒˆ
IMG_XPATH = '/html/body/div[4]/div/div/div[1]/div[2]/div[1]/img'

def main():
    start = check_start() # ์‹œ๊ฐ„ ์ธก์ • ์‹œ์ž‘
    driver = webdriver.Chrome()
    
    for searchItem in item_list:
        saveDir = makeFolder(searchItem)
        
        url = makeUrl(searchItem)# ๊ฒ€์ƒ‰ํ•  url ๊ฐ€์ ธ์™€์„œ
        driver.get(url)# ์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰์œผ๋กœ ๊ฐ€์„œ
        maximizeWindow(driver)# ์ฐฝ์ตœ๋Œ€ํ™”
        scrollToEnd(driver)

        forbiddenCount = saveImgs(driver, saveDir, start)# ๋ชจ๋“  ์ƒ์„ธ ์ด๋ฏธ์ง€ src๋“ค์„ ๊ฐ€์ ธ์˜จ๋‹ค
        sec = check_time(start)
        print(f'์‹คํŒจ์ˆ˜{str(forbiddenCount)}, {sec}, {datetime.datetime.now().time()}')
    time.sleep(10)
    driver.quit() 

# ์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰ url ๋งŒ๋“ค๊ธฐ
def makeUrl(searchItem):
    url = 'https://search.naver.com/search.naver'
    params ={
        'where' : 'image',
        'sm'    : 'tab_jum',
        'query' : searchItem
    }
    url = url + '?' + urllib.parse.urlencode(params)
    return url

# ํด๋” ์ƒ์„ฑ
def makeFolder(searchItem):
    saveDir = os.path.join(os.getcwd(), 'data', f'{FOLDER}_{searchItem}')
    try:
        if not(os.path.isdir(saveDir)): # ํ•ด๋‹น ํด๋”๊ฐ€ ์—†๋‹ค๋ฉด
            os.makedirs(os.path.join(saveDir)) # ๋งŒ๋“ค์–ด๋ผ
        return saveDir
    except OSError as e:
        print(e+'ํด๋” ์ƒ์„ฑ ์‹คํŒจ')

# ์ฐฝ ์ตœ๋Œ€ํ™”
def maximizeWindow(driver):
    driver.maximize_window()

# ๋ชจ๋“  ์ด๋ฏธ์ง€ ๋ชฉ๋ก์„ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด ๋ฌดํ•œ ์Šคํฌ๋กค ๋‹ค์šด
def scrollToEnd(driver):
    prev_height = driver.execute_script('return document.body.scrollHeight')
    print(f'prev_height: {prev_height}')
    
    while True:
        time.sleep(1) #๋„ค์ด๋ฒ„๋Š” sleep์—†์ด ์ด๋™ํ•  ๊ฒฝ์šฐ ๋ฌดํ•œ๋กœ๋”ฉ์— ๊ฑธ๋ฆฐ๋‹ค.
        driver.execute_script('window.scrollTo(0, document.body.scrollHeight)')
        time.sleep(3)
        
        cur_height = driver.execute_script('return document.body.scrollHeight')
        print(f'cur_height: {cur_height}')
        if cur_height == prev_height:
            print('๋†’์ด๊ฐ€ ๊ฐ™์•„์ง')
            break
        prev_height = cur_height
    
    # ํŽ˜์ด์ง€๋ฅผ ๋ชจ๋‘ ๋กœ๋”ฉํ•œ ํ›„์—๋Š” ์ตœ์ƒ๋‹จ์œผ๋กœ ๋‹ค์‹œ ์˜ฌ๋ผ๊ฐ€๊ธฐ
    driver.execute_script('window.scrollTo(0, 0)')

# ๋ชจ๋“  ์ด๋ฏธ์ง€๋“ค์„ ์ €์žฅํ•œ๋‹ค
def saveImgs(driver, saveDir, start):
    time.sleep(1)
    forbiddenCount = 0
    imgs = driver.find_elements(By.CSS_SELECTOR, '._fe_image_tab_content_thumbnail_image')
    
    print('imgs')
    print(imgs)
    srcList = []
    img_count = len(imgs)
    print(f'์ „์ฒด ์ด๋ฏธ์ง€์ˆ˜ : {img_count}')
    # ํ•˜๋‚˜์”ฉ ํด๋ฆญํ•ด๊ฐ€๋ฉฐ ์ €์žฅ
    for imgNum, img in enumerate(imgs): # imgNum์— ์ด๋ฏธ์ง€๋ฒˆํ˜ธ๊ฐ€ 0๋ถ€ํ„ฐ ๋“ค์–ด๊ฐ„๋‹ค
        try:
            img.click()
            time.sleep(3)
            
            # ์•„๋ž˜์˜ xPath๋Š” ์ž์ฃผ ๋ฐ”๋€Œ๋Š” ๊ฒƒ ๊ฐ™๋‹ค. ๋‚˜๋จธ์ง€๋Š” ๊ณ ์ •์ธ๊ฑฐ ๊ฐ™์œผ๋‹ˆ ์ด๊ฒƒ๋งŒ ๊ฐ€๋” ํ™•์ธํ•ด์ฃผ์ž
            bigImg = driver.find_element(By.XPATH, IMG_XPATH)
            src = bigImg.get_attribute('src')
            urllib.request.urlretrieve(src, saveDir + '/' + str(imgNum) + '.jpg')
            sec = check_time(start)
            print(f'{imgNum+1}/{img_count} saved {sec}')

        except Exception as e:
            print(e)
            forbiddenCount += 1# ์ €์žฅ ์‹คํŒจํ•œ ๊ฐœ์ˆ˜. forbidden์ด๋‚˜ ํŒŒ์ผ์—๋Ÿฌ๋„ ๊ฝค ๋งŽ๋‹ค
            continue
    return forbiddenCount


# ์‹œ๊ฐ„ ์ธก์ •
def check_start():
    start_time = time.time()
    print("Start! now.." + str(start_time))
    return start_time
def check_time(start):
    end = time.time()
    during = end - start
    sec = str(datetime.timedelta(seconds=during)).split('.')[0]
    return sec
main()

 

์ด์ œ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•ด๋ณด์ž. ์ž˜ ์‹คํ–‰๋  ๊ฒƒ์ด๋‹ค.

์ผ๋ฐ˜์ ์œผ๋กœ ๋„ค์ด๋ฒ„๋Š” ์ตœ๋Œ€ 500๊ฐœ์˜ ์ด๋ฏธ์ง€๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.

1. ๋จผ์ € ์šฐ๋ถ„ํˆฌ 22.04๋ฅผ ์„ค์น˜ํ•œ๋‹ค

wsl -l -o

์„ค์น˜ ๊ฐ€๋Šฅํ•œ ๋ฒ„์ „๋“ค์ด ๋œฌ๋‹ค

wsl --install -d Ubuntu-22.04

22.04๋ฅผ ์„ค์น˜ํ•œ๋‹ค.
2. ์ปดํ“จํ„ฐ๋ฅผ ์žฌ๋ถ€ํŒ…ํ•˜๋ฉด ๋‹ค์‹œ ์ผœ์ž๋งˆ์ž ์ž๋™์œผ๋กœ ์•Œ์•„์„œ ์„ค์ • ์™„๋ฃŒํ•œ๋‹ค.

3. ์„ค์น˜ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์œˆ๋„์šฐ ๊ธฐ๋Šฅ์ผœ๊ธฐ/๋„๊ธฐ๋ฅผ ๊ฒ€์ƒ‰ํ•œ ํ›„ Hyper-X์™€ Linux์šฉ ๋จธ์‹œ๊ธฐ๋ฅผ ์ฒดํฌํ•ด์ค€๋‹ค.

4. ์žฌ๋ถ€ํŒ… ํ›„ ๋‹ค์‹œ ์‹œ๋„ํ•˜๋ฉด ๋œ๋‹ค.

5. ๊ทธ๋ž˜๋„ ์ปค๋„์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ• ๋•Œ๊ฐ€ ์žˆ๋‹ค
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
์œ„ ํŒŒ์ผ์„ ์„ค์น˜ํ•œ ํ›„ ์ปค๋„์„ ์—…๋ฐ์ดํŠธํ•˜๋ฉด ์ •์ƒ์ ์œผ๋กœ ๋Œ์•„๊ฐ„๋‹ค.

 

6. ์ด์ œ ์—…๋ฐ์ดํŠธ ๋ชจ๋‘ ํ•˜์ž

sudo apt-get update
sudo apt-get upgrade

7. ์ด์ œ ์ €์žฅ ๊ฒฝ๋กœ๋ฅผ c:์—์„œ e:๋กœ ๋ฐ”๊ฟ”๋ณด์ž
์•„๋ž˜ ๊ฒฝ๋กœ์— ext4.vhdx ๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋‹ค. 
C:\Users\ufo\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx
์œ„ ํŒŒ์ผ์•ˆ์— ์šฐ๋ถ„ํˆฌ์™€ ๋ชจ๋“ ๊ฒƒ๋“ค์ด ๋“ค์–ด๊ฐ„๋‹ค. ์ฆ‰ ์ €๊ฑธ e:๋กœ ์˜ฎ๊ธฐ๋ฉด ๋˜๋Š”๊ฑฐ๋‹ค.

8. ๋จผ์ € ์šฐ๋ถ„ํˆฌ ํ”„๋กœ์„ธ์„œ๋ฅผ terminate์‹œ์ผœ์•ผํ•œ๋‹ค

wsl -l -v

๋ฅผ ์‹คํ–‰์‹œํ‚ค๋ฉด ์„ค์น˜๋œ ๋ฆฌ๋ˆ…์Šค ๋ฒ„์ „๋“ค์ด ๋ณด์ธ๋‹ค. ์ด ์ค‘์—์„œ ์ข…๋ฃŒ์‹œํ‚ฌ ๋ฒ„์ „์„ ์„ ํƒํ•˜๋Š” ๊ฑฐ๋‹ค.

wsl -t Ubuntu-22.04


9. ์ด์ œ ์˜ฎ๊ธฐ์ž.
๊ทธ๋ƒฅ ์˜ฎ๊ธฐ๋ฉด ์˜์กด์„ฑ ์ฒ˜๋ฆฌ๊ฐ€ ๊ณจ์น˜์•„ํ”„๋‹ค. ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ™œ์šฉํ•˜์ž
https://github.com/pxlrbt/move-wsl
git clone https://github.com/pxlrbt/move-wsl.git
์œ„ ๊นƒํ—™์—์„œ ๊ฐ€์ ธ์˜จ move-wsl.ps1 ํŒŒ์ผ์„ ํŒŒ์›Œ์‰˜์—์„œ ์‹คํ–‰์‹œ์ผœ์•ผ ํ•œ๋‹ค. - ๊นƒํ—™์—์„œ ์ € ํŒŒ์ผ ํ•˜๋‚˜๋งŒ ๊ฐ€์ ธ์˜ค๋ฉด ๋œ๋‹ค
๊ทธ๋Ÿฐ๋ฐ ์•„๋ž˜๊ฐ™์€ ์˜ค๋ฅ˜๊ฐ€ ๋œฌ๋‹ค.

10. ๊ด€๋ฆฌ์ž ๋ชจ๋“œ๋กœ ํŒŒ์›Œ์…€์„ ์‹คํ–‰ ์‹œํ‚จ ํ›„์— ๊ถŒํ•œ์„ ์ฃผ์ž. ์•„๋ž˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค

Set-ExecutionPolicy RemoteSigned

11. ๋๋‹ค. ์ด์ œ ์ค€๋น„๊ฐ€ ๋๋‚ฌ๋‹ค. ์˜ฎ๊ธด๋‹ค
.\move-wsl.ps1 
์‹คํ–‰ํ•˜๋ฉด ์˜ฎ๊ธธ ๋ฆฌ๋ˆ…์Šค ๋ฒ„์ „์ด ๋œฌ๋‹ค. ์•„๋ž˜ ์Šค์ƒท์ฒ˜๋Ÿผ 1๋ฒˆ ์„ ํƒ.
๋‹ค์Œ์—๋Š” ์ด๋™์‹œํ‚ฌ ๊ฒฝ๋กœ๋ฅผ ๋„ฃ์–ด์ค€๋‹ค. ๋‚˜๋Š” E:\WSL

12. ํ•œ์ฐธ๋™์•ˆ ๋ณต์‚ฌ๊ฐ€ ๋œ๋‹ค. Done!

๋ฃจํŠธ ์ ‘์†์ด ์•„๋‹Œ ์ผ๋ฐ˜๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธํ•˜๊ธฐ ์œ„ํ•ด  /etc/wsl.conf ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  ์•„๋ž˜ ๋ฌธ๊ตฌ๋ฅผ ๋„ฃ์–ด์ค€๋‹ค. ๋‚ด์•„์ด๋”” ์œ„์น˜์— ์›ํ•˜๋Š” ์ด๋ฆ„์„ ๋„ฃ์œผ๋ฉด ๋œ๋‹ค. ๋‚˜๋Š” ufo๋กœ ๋„ฃ์—ˆ๋‹ค

[user]
default=๋‚ด์•„์ด๋””

๋‹ซ๊ณ  ์žฌ์‹คํ–‰ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๋ณ€๊ฒฝ๋œ๊ฒƒ์„ ์•Œ์ˆ˜์žˆ๋‹ค.

 

 

 

ddetailer๋‚˜ ๊ทธ๊ฑธ ์ˆ˜์ •ํ•œ ๋ฒ„์ „๊นŒ์ง€ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฒ„์ „์„ ์„ค์น˜ํ•˜๊ณ  ์‹คํ–‰ํ•ด ๋ณด์•˜์œผ๋‚˜ ๊ฒฐ๊ตญ ์—๋Ÿฌ๊ฐ€ ๋‚ฌ๋‹ค.

๊ทธ๋Ÿฌ๋‹ค ๋ฐœ๊ฒฌํ•œ ๊ฒƒ์ด Adetailer๋‹ค. ์„ค์น˜๋„ ์•„์ฃผ ๊ฐ„๋‹จํ•˜๋‹ค.

https://github.com/Bing-su/adetailer

 

GitHub - Bing-su/adetailer: Auto detecting, masking and inpainting with detection model.

Auto detecting, masking and inpainting with detection model. - GitHub - Bing-su/adetailer: Auto detecting, masking and inpainting with detection model.

github.com

1. Extensions ํƒญ์„ ์ด๋™

2. Install from URL ์•ˆ์— https://github.com/Bing-su/adetailer.git ๋ฅผ ๋„ฃ๊ณ  install ๋ฒ„ํŠผ ํด๋ฆญ

3. ์ธ์Šคํ†จ ์™„๋ฃŒ ํ›„ Apply and restart UI

4. ํ„ฐ๋ฏธ๋„์„ ์žฌ์‹คํ–‰

5. ์‹คํ–‰ ์ค‘ ๋ชจ๋“ˆ์ด ์—†๋‹ค๊ณ  ์—๋Ÿฌ๊ฐ€ ๋œจ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ๊ทธ ์ด๋ฆ„์„ ์ฐพ์•„์„œ ์ธ์Šคํ†จ ํ•ด์ฃผ๋ฉด๋œ๋‹ค.

pip install ๋ชจ๋“ˆ์ด๋ฆ„

6. ์ด์ œ ์Šคํ…Œ์ด๋ธ” ๋””ํ“จ์ „์„ ์‹คํ–‰ํ•ด๋ณด์ž.

txt2img ํƒญ์— ๊ธฐ๋ณธ์œผ๋กœ ADetailer๊ฐ€ ์„ ํƒ๋˜์–ด ์žˆ๋‹ค. ํด๋ฆญํ•˜๋ฉด ์ƒ์„ธ์ฐฝ์ด ๋œฌ๋‹ค. 

Enable ADetailer๋ฅผ on ์‹œํ‚ค๊ณ 

์•„๋ž˜์™€ ๊ฐ™์€ ๊ธฐ์ค€์œผ๋กœ ๋ชจ๋ธ์„ ์„ ํƒํ•œ๋‹ค. ๊ฐœ์ธ์ ์œผ๋กœ๋Š” ์ฐจ์ด๋Š” ์ž˜ ๋ชจ๋ฅด๊ฒ ๊ณ  ๋ญ˜ํ•ด๋„ ์ž˜๋‚˜์˜ค๋”๋ผ.

face_yolov8n.pt 2D / realistic face 0.660 0.366
face_yolov8s.pt 2D / realistic face 0.713 0.404
hand_yolov8n.pt 2D / realistic hand 0.767 0.505
person_yolov8n-seg.pt 2D / realistic person 0.782 (bbox)
0.761 (mask)
0.555 (bbox)
0.460 (mask)
person_yolov8s-seg.pt 2D / realistic person 0.824 (bbox)
0.809 (mask)
0.605 (bbox)
0.508 (mask)
mediapipe_face_full realistic face - -
mediapipe_face_short realistic face - -
mediapipe_face_mesh realistic face - -

์ด์ œ generateํ•˜๋ฉด ๋œ๋‹ค. ํ™•์‹คํžˆ ์–ผ๊ตด์ด ์ž˜๋‚˜์˜จ๋‹ค. 

  1. ์ฝ˜๋‹ค๋กœ ์ƒˆ๋กœ์šด ๊ฐ€์ƒํ™˜๊ฒฝ ๋งŒ๋“ค์–ด์ค€๋‹ค
  • conda create -n textgen python=3.10
  • ์ด ํ™˜๊ฒฝ ์•„๋ž˜์— ์„ค์น˜ํ•œ ํ›„ ํ™œ์„ฑํ™”ํ•˜๊ธฐ
  • conda activate textgen

 

  1. ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์„ ์„ค์น˜ํ•œ๋‹ค
  • conda install cuda pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia/label/cuda-11.7.0

 

  1. ์ด์ œ ๊นƒํ—™์—์„œ ๋ฐ›์•„์˜ค์ž

  • ์œ„์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋œฌ๋‹ค. ํ•œ๋ฒˆ ์žก์•„๋ณด์ž.
  • https://github.com/oobabooga/one-click-installers/issues/30#issuecomment-1518040167
  • ํ•œ์‹œ๊ฐ„์ด ๋„˜๊ฒŒ ๊ณ ์ƒํ•˜๋ฉด ์•Œ์•„๋ณธ ๊ฒฐ๊ณผ C complier๊ฐ€ ์—†์–ด์„œ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์˜€๋‹ค. ์–ด๋””์—๋„ ์ •๋ฆฌ๋œ ๋ฌธ์„œ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์—ˆ๋‹ค
  • sudo apt install build-essential
  • ์ด๊ฑธ๋กœ c์ปดํŒŒ์ผ๋Ÿฌ๋ฅผ ๊น”๊ณ  ๋‹ค์‹œ ์‹œ๋„ํ•ด๋ณด์ž
  • pip install -r requirements.txt
  • ์ž˜๋œ๋‹ค.
  • python server.py
  • http://127.0.0.1:7860 ์— ์ ‘์†ํ•˜๋ฉด ์œˆ๋„์šฐ์—์„œ ์ฐฝ์ด ์—ด๋ฆฐ๋‹ค. ์šฐ๋ถ„ํˆฌ์™€ ๋ฆฌ๋ˆ…์Šค๊ฐ€ ์ด๋ ‡๊ฒŒ ์—ฐ๊ฒฐ๋œ๋‹ค๋‹ˆ ์‹ ๋น„๋กœ์šด ๊ธฐ๋ถ„์ด๋‹ค.
  • ์„ฑ๊ณต
  • ์ด์ œ ๋ชจ๋ธ๋“ค์„ ๋ชจ๋‘ ํ…Œ์ŠคํŠธํ•ด๋ณด์ž.
  • ์•ˆ๋œ๋‹ค. ๋ชจ๋ธ์„ ๋กœ๋“œํ•˜๋ฉด ModuleNotFoundError: No module named 'llama_inference_offload' ์ด๋Ÿฐ ์—๋Ÿฌ๊ฐ€ ๋œฌ๋‹ค
  • https://github.com/qwopqwop200/GPTQ-for-LLaMa/issues/161

 

  • ์œ„์™€ ๊ฐ™์€ GPTQ๋ฅผ ๋Œ๋ฆฌ๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ถ”๊ฐ€ ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ค
  • ์•Œ์•„๋ณด๋‹ˆ ์ด๊ฑด ์•„๋ž˜์— ์œˆ๋„์šฐ ์„ค์น˜ํ• ๋•Œ์™€ ๊ฐ™์€ ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ค.
  • git clone https://github.com/oobabooga/GPTQ-for-LLaMa.git -b cuda
  • cd GPTQ-for-LLaMa && python setup_cuda.py install

 

  • ๋งˆ์ง€๋ง‰์œผ๋กœ GPTQ-for-LLaMa ํด๋”์•ˆ์˜ ๋ชจ๋“  ํŒŒ์ผ์„ ํ†ต์ฑ„๋กœ ์ž˜๋ผ๋‚ด๊ธฐ ํ•œํ›„
  • text-generation-webui ํด๋” ์•ˆ์œผ๋กœ ์ด๋™ํ•˜๊ณ  
  • ์—ฌ๊ธฐ์— ํ†ต์ฑ„๋กœ ๋ถ™์—ฌ๋„ฃ๊ธฐํ•œ๋‹ค. ๋ฎ์–ด์“ฐ๊ธฐ๋Š” ํ•˜์ง€ ์•Š๋Š”๋‹ค. explore.exe๋ฅผ ์ด์šฉํ•ด ์•ˆ์ „ํ•˜๊ฒŒ ์ด๋™์‹œํ‚ค์ž
  • python server.py --listen --listen-port 8001 --chat --auto-devices
  • ๋ชจ๋ธ๋“ค์„ ๋กœ๋”ฉํ•ด๋ณธ๋‹ค. ์„ธํŒ…๋งŒ ๋งž์œผ๋ฉด GPTQ ๋ชจ๋ธ๋“ค๋„ ๋กœ๋”ฉ์ด ์ž˜๋œ๋‹ค.

 

  1. ์™ธ๋ถ€์—์„œ wsl๋กœ ๋ถ™๊ธฐ์œ„ํ•ด ํฌํŠธ ์—ฐ๊ฒฐํ•˜๊ธฐ
  • ๊ด€๋ฆฌ์ž ํŒŒ์›Œ์‰˜์—์„œ 
  • netsh interface portproxy add v4tov4 listenport=8001 listenaddress=0.0.0.0 connectport=8001 connectaddress=172.28.51.232
  • 0.0.0.0์€ ์™ธ๋ถ€์—์„œ ๋ถ™์„ ์ˆ˜ ์žˆ๊ฒŒ ์—ด์–ด์ค€๋‹ค๋Š” ๋œป์ด๊ณ  8001ํฌํŠธ๋Š” ์™ธ๋ถ€์— ์—ด๋ฆฐ ํฌํŠธ์ด๋‹ค. 172.23.81.58์€ wsl2 ํฌํŠธ์ด๋‹ค
  • ํ•ต์‹ฌ์€ connectaddress ์— ํ˜„์žฌ ์šฐ๋ถ„ํˆฌ์˜ ip๋ฅผ ์ ์–ด์ฃผ๋Š” ๊ฒƒ์ด๋‹ค. ์—ฌ๊ธฐ์— localhost๊ฐ€ ๋“ค์–ด๊ฐ€ ์žˆ์œผ๋‹ˆ ์ ‘์†์ด ๊ณ„์† ์•ˆ๋˜์—ˆ๋˜ ๊ฑฐ๋‹ค.
  • ๋งŒ์•ฝ์— ์œ„ ๋‚ด๋ถ€ ํฌํŠธ๊ฐ€ ๋ฐ”๋€”๋•Œ๋ฅผ ๋Œ€๋น„ํ•ด ์Šค์ผ€์ฅด๋Ÿฌ๋ฅผ ์ด์šฉํ•˜๋Š”๋ฐ ์ด๊ฑด
  • https://velog.io/@popcorn_kim93/WSL2%EC%97%90-ssh-%EC%84%9C%EB%B2%84%EC%99%80-%EC%99%B8%EB%B6%80%EC%97%B0%EA%B2%B0-%ED%99%98%EA%B2%BD-%EA%B5%AC%EC%B6%95
  • ๋ฅผ ๋ณด์ž. ์—ฌ๋Ÿฌ๋ฒˆ ์žฌ๋ถ€ํŒ…ํ•ด๋ดค๋Š”๋ฐ ์•„์ง์€ ๋ณ„ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค

 

  • ๋ฌธ์ œ ๋ฐœ์ƒ์‹œ ์•„๋ž˜๋Š” ํ•ด๋‹น ํฌํŠธ๋ฅผ ์‚ญ์ œํ•˜๊ธฐ
  • netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=8001

 

  • wsl์—์„œ ์™ธ๋ถ€๋กœ ์—ด๋ฆฐ ํฌํŠธ ํ™•์ธ. ์•„๋ž˜์˜ ํŒŒ์›Œ์‰˜ ํฌํŠธ์™€ ๋‹ค๋ฅด๋‹ค
  • netsh interface portproxy show v4tov4

 

outpainting ์—๋Š” ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•์ด ์žˆ์—ˆ๋‹ค.

1. ์ฒ˜์Œ์‹œ๋„ํ•œ ๋ฐฉ๋ฒ•์€ https://github.com/lkwq007/stablediffusion-infinity.git

 

GitHub - lkwq007/stablediffusion-infinity: Outpainting with Stable Diffusion on an infinite canvas

Outpainting with Stable Diffusion on an infinite canvas - GitHub - lkwq007/stablediffusion-infinity: Outpainting with Stable Diffusion on an infinite canvas

github.com

์„ค์น˜๋Š” ๊ฐ„๋‹จํ•˜๋‹ค. ๊นƒํ—™ํŽ˜์ด์ง€๋กœ ๊ฐ€์„œ ์œˆ๋„์šฐ ์„ค์น˜๋ถ€๋ถ„์„ ๊ทธ๋Œ€๋กœ ๋”ฐ๋ผํ•˜๋ฉด ๋œ๋‹ค. ๋‹ค๋งŒ ์„ค์น˜ํ•˜๋Š”๋ฐ ์‹œ๊ฐ„์ด ๋งŽ์ด ๊ฑธ๋ฆฐ๋‹ค.

๋‚˜๋Š” conda๋กœ outpaint๋ผ๋Š” ๊ฐ€์ƒํ™˜๊ฒฝ์„ ๋งŒ๋“ค๊ณ  ์—ฌ๊ธฐ์— ์„ค์น˜ํ–ˆ๋‹ค.

git clone --recurse-submodules https://github.com/lkwq007/stablediffusion-infinity
cd stablediffusion-infinity
conda create -n outpaint python=3.10
conda activate outpaint
conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia
conda install scipy scikit-image
conda install -c conda-forge diffusers transformers ftfy accelerate
pip install opencv-python
pip install -U gradio
pip install pytorch-lightning==1.7.7 einops==0.4.1 omegaconf==2.2.3
pip install timm

infinity๋ฅผ ์‚ฌ์šฉํ•ด ์•„๋ž˜์˜ ์›๋ณธ ์ด๋ฏธ์ง€๋ฅผ ๊ทธ ์•„๋ž˜์˜ ์ด๋ฏธ์ฒ˜๋Ÿผ ํ™•์žฅ์‹œํ‚ฌ์ˆ˜ ์žˆ๋‹ค. ์—„์ฒญ๋‚˜๋‹ค. 

์‚ฌ์šฉ๋ฒ•์€ ํ˜ผ์ž ๊ทธ๋ƒฅ ๋งŒ์ง€๋ฉฐ ์ตํ˜”๋‹ค. ๋‚˜์ค‘์— ์œ ํŠœ๋ธŒ๋ฅผ ์ฐพ์•„๋ณด๋‹ˆ ๋‚˜์™€ ๋‹ค๋ฅผ๋ฐ” ์—†์—ˆ๋‹ค. 

๋งŒ๋“ค๋•Œ ๊ผญ ์ฒ˜์Œ ์ € ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ• ๋•Œ์˜ ํ”„๋กฌํ”„ํŠธ๋„ ๊ฐ™์ด ๋„ฃ์–ด์•ผ ์–ด์ƒ‰ํ•˜๊ฒŒ ์•ˆ๋‚˜์˜จ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ๊ธฐ์กด ์ด๋ฏธ์ง€ ์ •๋ณด๋„ ํ•จ๊ป˜ ๋งŽ์ด ํฌํ•จํ•ด์ค˜์•ผ(์„ ํƒํ•ด์ค˜์•ผ) ์ž์—ฐ์Šค๋Ÿฌ์›Œ์ง„๋‹ค.

ํ•˜์ง€๋งŒ ์‹œ๊ฐ„์ด ์•„์ฃผ ์˜ค๋ž˜ ๊ฑธ๋ฆฐ๋‹ค. ๋งˆ์Œ์— ๋“ค์ง€ ์•Š๋Š” ๊ทธ๋ฆผ์ด ๋‚˜์˜ฌ๋•Œ๋„ ๋งŽ๋‹ค. ๊ทธ๋ž˜์„œ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ดค๋‹ค.

 

2. ๊ธฐ์กด ์ด๋ฏธ์ง€์˜ canvas๋ฅผ ๋Š˜๋ฆฌ๊ณ  ๊ทธ ๋ถ€๋ถ„์„ ์ƒ‰์น ํ•œ ๋‹ค์Œ ์ด ๋ถ€๋ถ„๋งŒ img2img์—์„œ ๋‹ค์‹œ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

์ด์ œ ์ œ์ผ ์ข‹์„ ๊ฑฐ๋ผ ์ƒ๊ฐํ–ˆ๋Š”๋ฐ ๋” ์ข‹์€ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ƒˆ๋‹ค.

 

3. ์ถ”๊ฐ€ ์„ค์น˜ํ•  ๊ฒƒ๋„ ์—†๋‹ค. ๋ฐ”๋กœ stable diffusion > img2img ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ™˜์ƒ์ ์ด๋‹ค. ์†๋„๋„ ๋น ๋ฅด๋‹ค.

img2img๋ฅผ ๊ฐ€๋ฉด ๋งจ ์•„๋ž˜์— Script๋ฅผ ์„ ํƒํ•˜๋Š” ๋ถ€๋ถ„์ด ์žˆ๋‹ค.

์—ฌ๊ธฐ์„œ Outpaing mk2๋กœ ์„ ํƒํ•œ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์€ ์„ ํƒ์ฐฝ์ด ๋œจ๋Š”๋ฐ ๋ฐ”๊พธ ์•Š๋Š”๊ฒŒ ๊ฐ€์žฅ ์ข‹๋”๋ผ.
๋‹จ ๋ฐฉํ–ฅ์€ ํ•œ ๋ฐฉํ–ฅ์”ฉ ๋Š˜๋ ค๊ฐ€๋ฉด์„œ ํ…Œ์ŠคํŠธํ•˜๋Š”๊ฒŒ ์ข‹๋‹ค. ์•„๋ž˜์ฒ˜๋Ÿผ left ๋จผ์ €ํ•˜๊ณ  ๋‹ค์Œ right ๋Œ๋ ค๋ณด๋Š” ๋ฐฉ์‹์ด๋‹ค.

๋‹ค ๋œ๊ฑฐ๋‹ค. ๊ทธ๋ƒฅ ์ƒ์„ฑํ•˜๋ฉด ๋œ๋‹ค. ์™ผ์ชฝ์œผ๋กœ ๋” ๋Š˜๋ฆฌ๊ณ  ์‹ถ๋‹ค๋ฉด ๊ฒฐ๊ณผ์ฐฝ์—์„œ ๋‹ค์‹œํ•œ๋ฒˆ send to img2img ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ๋ณด๋‚ธํ›„ ๊ฑฐ๊ธฐ์„œ ๋‹ค์‹œ ์ƒ์„ฑํ•˜๋ฉด ๋œ๋‹ค.
๊ฐ€์žฅ ์ข‹์€ ์ ์€ ๊ธฐ์กด๊ณผ ์™„์ „ํžˆ ๋˜‘๊ฐ™์€ ํ”„๋กฌํ”„ํŠธ์™€ ์ฒดํฌํฌ์ธํŠธ, ๋กœ๋ผ ๋ฐ ๊ฐ์ข… ์„ค์ •์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ธฐ์กด ์ด๋ฏธ์˜ ๋Š๋‚Œ์„ ์‚ด๋ฆฌ๊ธฐ ์‰ฝ๋‹ค๋Š” ๊ฑฐ๋‹ค.
๊ทธ๋ฆฌ๊ณ  infinity๋ณด๋‹ค ์†๋„๊ฐ€ ์›”๋“ฑํžˆ ๋น ๋ฅด๋‹ค. ๊ณ„์† ๋งŒ๋“ค๋ฉฐ ์‹คํ—˜ํ•˜๋ฉด ๋œ๋‹ค.

์˜์ƒ๋Œ€๋กœ ํ•˜๋ฉด ๋œ๋‹ค. ๋‹จ ๊ต์œก์‹œ๊ฐ„์ด ๊ฝค ๊ธธ๊ณ  ๋‚ด ๋ˆˆ์œผ๋กœ ๋ณด๊ธฐ์— ํ€„์ด ๋ณ„๋กœ๋‹ค.

์ด๊ฒƒ๋ณด๋‹จ ์ฐจ๋ผ๋ฆฌ Dreambooth๊ฐ€ ๋‚˜์•˜๋‹ค. ์˜์ƒ์—์„œ๋„ ๋งˆ์ง€๋ง‰์— ๋“œ๋ฆผ๋ถ€์Šค๊ฐ€ ๋‚ซ๋‹ค๊ณ  ํ‰๊ฐ€ํ•˜๊ณ  ์žˆ๋‹ค;;

 

์•„๋ž˜ 4๋Œ€ ํ›ˆ๋ จ๋ฒ• ์ค‘ Textual Inversion์„ ์ œ์™ธํ•˜๊ณ  ๋ชจ๋‘ ๋Œ๋ ค๋ดค๋Š”๋ฐ ์ด์ œ ๋” ์ด์ƒ ๊ณ ๋ฏผํ•˜์ง€ ์•Š๊ฒ ๋‹ค.

๊ทธ๋ƒฅ ๋กœ๋ผ๋ฅผ ์“ฐ์ž.

 

Extensions > Available > Load from > Dreambooth ๊ฒ€์ƒ‰

https://www.youtube.com/watch?v=tuSlUqmlZuc 

ํ”Œ๋Ÿฌ๊ทธ์ธ ๋‹ค์šด๋ฐ›์€ ํ›„ ํ”„๋กœ๊ทธ๋žจ ์žฌ์‹œ์ž‘ํ•˜๊ณ  ์œ„ ๋งํฌ๋Œ€๋กœ ๋”ฐ๋ผํ•˜๋ฉด ๋œ๋‹ค.

 

์—ฐ์˜ˆ์ธ ๋ชจ๋ธ์„ ํ›ˆ๋ จ์‹œ์ผœ๋ดค๋Š”๋ฐ ๊ฝค ์ž˜๋‚˜์™”์ง€๋งŒ 300๋ฉ”๊ฐ€๊ฐ€ ๋„˜์—ˆ๊ณ  ์‹œ๊ฐ„์€ 30๋ถ„ ์กฐ๊ธˆ ๋„˜๊ฒŒ ๊ฑธ๋ ธ๋‹ค.

์‚ฌ์šฉ๋ฒ•์€ ๊ฐ„๋‹จํ•˜์ง€๋งŒ ์‹œ๊ฐ„์ด ์ข€ ๊ฑธ๋ฆฌ๊ณ  ์šฉ๋Ÿ‰์ด ์ž‘์ง€ ์•Š๋‹ค. ๋˜ํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋กœ๋ผ๊ฐ€ ์•„๋‹Œ checkpoint ํŒŒ์ผ๋กœ ๋‚˜์˜จ๋‹ค.

* ๊ฒฐ๋ก  : ์•„๋ž˜ 4๊ฐœ์˜ ์ด๋ฏธ์ง€ ํ›ˆ๋ จ๋ฒ• ์ค‘์—์„œ dreambooth๋Š” ํƒˆ๋ฝ

 

1. webui-user.bat ํŒŒ์ผ์„ ์—ด๊ณ  --listen ์ถ”๊ฐ€. 

set COMMANDLINE_ARGS=--listen

์ด์™€ ๊ฐ™์ด ์„ค์ •ํ•˜๊ณ  ์‹คํ–‰ํ•˜๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ 7860 ํฌํŠธ๊ฐ€ ๊ธฐ๋ณธ์œผ๋กœ ์—ด๋ฆฐ๋‹ค. ๋งŒ์•ฝ ํฌํŠธ๋ฅผ 8001๋ฒˆ์œผ๋กœ ๋ฐ”๊พธ๊ณ  ์‹ถ๋‹ค๋ฉด

--listen --port 8001 ์ฒ˜๋Ÿผ ๋„ฃ์œผ๋ฉด ๋œ๋‹ค.


2. ์œˆ๋„์šฐ ๋ฐฉํ™”๋ฒฝ ์—ด๊ธฐ
๋ฐฉํ™”๋ฒฝ ์„ค์ • ๊ฒ€์ƒ‰ > ๊ณ ๊ธ‰์„ค์ •

์ธ๋ฐ”์šด๋“œ > ์ƒˆ๊ทœ์น™

ํฌํŠธ : 7860 > ๊ณ„์† ๋‹ค์Œ ํด๋ฆญ. ์ด๋ฆ„ ์ •๋„๋งŒ ๋„ฃ์–ด์ฃผ์ž.

 

3. iptime์—์„œ ํฌํŠธ ์—ด๊ธฐ

4. ์™„์„ฑ. ์ด์ œ ์™ธ๋ถ€์—์„œ ๋ถ™์–ด๋ณด์ž.

http://121.140.201.222:7860/

http://๋‚ด์•„์ดํ”ผ:ํฌํŠธ๋ฒˆํ˜ธ

 

5. ์ด์ œ ์Šค๋งˆํŠธํฐ์ด๋‚˜ ์™ธ๋ถ€PC์—์„œ๋„ ์ ‘์†ํ•  ์ˆ˜ ์žˆ๋‹ค.

* ๋งŒ์•ฝ wsl ํ™˜๊ฒฝ์ด๋ผ๋ฉด ์ถ”๊ฐ€์ ์ธ ์—ฐ๊ฒฐ ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ค. ์ฆ‰ wsl์˜ ํฌํŠธ์™€ ์œˆ๋„์šฐ์—์„œ ์˜คํ”ˆํ•œ ํฌํŠธ๋ฅผ ์—ฐ๊ฒฐํ•ด์ค˜์•ผ ํ•œ๋‹ค.
- ๊ด€๋ฆฌ์ž ๋ชจ๋“œ๋กœ ํŒŒ์›Œ์‰˜์„ ์—ฐํ›„,

netsh interface portproxy add v4tov4 listenport=wsl์—์„œ ์˜คํ”ˆํ•œ ํฌํŠธ listenaddress=0.0.0.0 connectport=์™ธ๋ถ€์—ฐ๊ฒฐํฌํŠธ connectaddress=wsl ip์ฃผ์†Œ


์‹ค์ œ ์˜ˆ์‹œ)

netsh interface portproxy add v4tov4 listenport=8001 listenaddress=0.0.0.0 connectport=8001 connectaddress=172.28.51.232


- wsl์—์„œ ์™ธ๋ถ€๋กœ ์—ด๋ฆฐ ํฌํŠธ ํ™•์ธ

netsh interface portproxy show v4tov4


- ๋งŒ์•ฝ ์œ„์—์„œ ์˜คํ”ˆํ•œ ํฌํŠธ๋ฅผ ๋‹ค์‹œ ๋‹ซ๊ณ  ์‹ถ๋‹ค๋ฉด

netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=8001

 

์ด๋ฏธ์ง€๋ฅผ ๋ฝ‘๋‹ค๋ณด๋ฉด ์ด๋ ‡๊ฒŒ ๋ณด๋ผ์ƒ‰ ์ ์ด ์ƒ๊ธธ๋•Œ๊ฐ€ ์žˆ๋‹ค

์ด๋•Œ ์˜คํ†  ์ธ์ฝ”๋” vae ํŒŒ์ผ๋กœ ํ›„๋ณด์ •์ด ํ•„์š”ํ•˜๋‹จ๋‹ค.

Settings ํƒญ์„ ํƒ > ์™ผ์ชฝ์˜ Stable Diffusion > SE VAE ์„ ํƒ์ฐฝ์—์„œ ์„ ํƒ

๋งŒ์•ฝ ํŒŒ์ผ์ด ์—†๋‹ค๋ฉด https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors <- ํด๋ฆญํ•˜๋ฉด ์ €์žฅ. 

์ €์žฅํ•œ ํŒŒ์ผ์„ stable-diffusion-webui\models\VAE ํด๋”์•ˆ์— ๋„ฃ๊ณ  ์ƒ๋‹จ์˜ Apply settings ๋ฒ„ํŠผ ํด๋ฆญ

ํ›„๋ณด์ •์„ ์œ„ํ•œ vae ์ข…๋ฅ˜๋„ ์—ฌ๋Ÿฌ๊ฐ€์ง€๊ฐ€ ์žˆ๋Š” ๊ฒƒ ๊ฐ™๋‹ค. 

๋‚˜์ค‘์— ํ•„์š”ํ•ด์ง€๋ฉด ๊ทธ๋•Œ๋‚˜ ์•Œ์•„๋ณด์ž

+ Recent posts