티스토리 뷰

Skills/etc

DIV2K dataset 다운로드 방법

미남잉 2023. 6. 6. 15:06
728x90

깃허브에도 정리해두었습니다!⭐️⭐️⭐️⭐️⭐️ https://github.com/cha-suyeon/DIV2K_DW

 

https://data.vision.ee.ethz.ch/cvl/DIV2K/

 

DIV2K Dataset

  Citation If you are using the DIV2K dataset please add a reference to the introductory dataset paper and to one of the following challenge reports. @InProceedings{Agustsson_2017_CVPR_Workshops, author = {Agustsson, Eirikur and Timofte, Radu}, title = {N

data.vision.ee.ethz.ch

DIV2K(DIVerse 2K resolution high-quality images for image processing) 데이터셋은 고품질의 이미지를 제공하는 컴퓨터 비전과 이미지 처리 연구를 위한 데이터셋이다. 이 데이터셋은 고해상도 이미지와 저해상도 이미지의 쌍으로 구성되어 있다. 주로 이미지 슈퍼-해상도(Super-Resolution) 및 다양한 이미지 처리 작업에 사용됨

 

이 홈페이지에서 다운 받을 수 있지만 로컬 다운은 너무 느리므로 패스

 

터미널 환경에서 바로 다운로드 받는 방법으로 다운로드

wget http://data.vision.ee.ethz.ch/cvl/DIV2K/DIV2K_train_HR.zip
wget http://data.vision.ee.ethz.ch/cvl/DIV2K/DIV2K_valid_HR.zip

 

wget이 없다면 'apt install wget' 다운로드 후 진행 (or 'apt-get install wget')

 

그리고 wget으로 바로 되는지 몰라서 사용한 방법

아래의 if url is not None ... 이 부분을 원하는 데이터셋 이름에 맞게 수정해주면 다운 가능하다. 

import requests as reqs
from bs4 import BeautifulSoup as BS
import shutil
import sys
import os

ROOT_URL = 'https://data.vision.ee.ethz.ch/cvl/DIV2K/'

def main(root_url, dw_addr):
    root_req = reqs.get(root_url)

    if root_req.status_code != 200:
        raise Exception(f"Server is down at {root_url}")

    soup = BS(root_req.content, 'lxml')
    a_s = soup.select('li > a')
    total_files = len([a for a in a_s if a['href'] is not None and 'DIV2K_train_HR.zip' in a['href']])
    downloaded_files = 0

    for a in a_s:
        url = a['href']
        if url is not None and 'DIV2K_train_HR.zip' in url:
            try:
                print(f"Downloading from {url}")
                fn = url.split('/')[-1]
                addr = f"{dw_addr}/{fn}"
                with reqs.get(url, stream=True) as r:
                    with open(addr, 'wb') as f:
                        shutil.copyfileobj(r.raw, f)

                downloaded_files += 1
                print(f"Downloaded {downloaded_files}/{total_files} files")
                
            except Exception as e:
                print(f"Couldn't download from {url}")
                print(e)

    print("Download completed!")


if __name__ == "__main__":
    download_dir = sys.argv[1]
    if not os.path.exists(download_dir):
        os.makedirs(download_dir)
    main(ROOT_URL, download_dir)

 

main.py로 저장해주고, 명령어로 입력하면 됨

 

python main.py <Output_DIR>

 

현재 경로에 다운로드 해주고 싶다면 'python main.py .' 을 입력

728x90
댓글