From e80b78ea44405fe5ea25aed25881ea1a7bab23fd Mon Sep 17 00:00:00 2001 From: Wesley Williams Date: Mon, 26 Feb 2018 17:50:10 +0000 Subject: [PATCH 1/3] Script to download models --- download_models.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 download_models.py diff --git a/download_models.py b/download_models.py new file mode 100644 index 0000000..8276561 --- /dev/null +++ b/download_models.py @@ -0,0 +1,35 @@ +# Download code taken from Code taken from https://stackoverflow.com/questions/25010369/wget-curl-large-file-from-google-drive/39225039#39225039 +import requests + +def download_file_from_google_drive(id, destination): + URL = "https://docs.google.com/uc?export=download" + + session = requests.Session() + + response = session.get(URL, params = { 'id' : id }, stream = True) + token = get_confirm_token(response) + + if token: + params = { 'id' : id, 'confirm' : token } + response = session.get(URL, params = params, stream = True) + + save_response_content(response, destination) + +def get_confirm_token(response): + for key, value in response.cookies.items(): + if key.startswith('download_warning'): + return value + + return None + +def save_response_content(response, destination): + CHUNK_SIZE = 32768 + + with open(destination, "wb") as f: + for chunk in response.iter_content(CHUNK_SIZE): + if chunk: # filter out keep-alive new chunks + f.write(chunk) + +file_id = '1ENgQm9TgabE1R99zhNf5q6meBvX6WFuq' +destination = './models.zip' +download_file_from_google_drive(file_id, destination) \ No newline at end of file From de7cd39bd3893cdd23bf22ccd0e764da94658ec6 Mon Sep 17 00:00:00 2001 From: Wesley Williams Date: Mon, 26 Feb 2018 18:03:55 +0000 Subject: [PATCH 2/3] Model download bash script, usage explained --- USAGE.md | 7 +++++++ download_models.sh | 3 +++ 2 files changed, 10 insertions(+) create mode 100755 download_models.sh diff --git a/USAGE.md b/USAGE.md index a70ac59..99637d7 100644 --- a/USAGE.md +++ b/USAGE.md @@ -34,6 +34,13 @@ We only tested our code in the following environment. - Download pretrained networks via the following [link](https://drive.google.com/open?id=1ENgQm9TgabE1R99zhNf5q6meBvX6WFuq). - Unzip and store the model files under `models`. +#### (Optional) Download script + - Automatically downloads pretrained networks and unzips them. + - Requires requests (`pip install requests`) +``` +bash download_models.sh +``` + ### Example 1: Transfer the style of a style photo to a content photo. - Create image and output folders and make sure nothing is inside the folders. `mkdir images && mkdir results` - Go to the image folder: `cd images` diff --git a/download_models.sh b/download_models.sh new file mode 100755 index 0000000..e1645af --- /dev/null +++ b/download_models.sh @@ -0,0 +1,3 @@ +#!/bin/bash +python download_models.py +unzip models.zip From 4f4532271cc551dbcbec57880864dbb2fea9101d Mon Sep 17 00:00:00 2001 From: Wesley Williams Date: Thu, 8 Mar 2018 13:19:20 +0000 Subject: [PATCH 3/3] Only import smooth_filter if needed, allows running without cupy --- process_stylization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process_stylization.py b/process_stylization.py index c4ecd09..7e2b97c 100644 --- a/process_stylization.py +++ b/process_stylization.py @@ -14,7 +14,6 @@ import torchvision.utils as utils from photo_smooth import Propagator -from smooth_filter import smooth_filter # Load Propagator p_pro = Propagator() @@ -70,6 +69,7 @@ def stylization(p_wct, content_image_path, style_image_path, content_seg_path, s print("NotImplemented: The CPU version of smooth filter has not been implemented currently.") return + from smooth_filter import smooth_filter with Timer("Elapsed time in post processing: %f"): out_img = smooth_filter(output_image_path, content_image_path, f_radius=15, f_edge=1e-1) out_img.save(output_image_path)