Skip to content

Commit bed87fb

Browse files
suquarkmingyuliutw
authored andcommitted
More info about model loading & converting
1 parent fa95b25 commit bed87fb

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

USAGE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,19 @@ We only tested our code in the following environment.
3131

3232
### Download pretrained networks
3333

34+
**PyTorch models**
35+
36+
These models are extracted from Torch7 models and currently used in the project.
37+
38+
- Pull them from the `PhotoWCTModels` submodule: `git submodule update --init --recursive`
39+
40+
**Origin Torch7 models**
41+
3442
- Download pretrained networks via the following [link](https://drive.google.com/open?id=1ENgQm9TgabE1R99zhNf5q6meBvX6WFuq).
3543
- Unzip and store the model files under `models`.
3644

45+
`converter.py` shows how to convert Torth7 models to PyTorch models.
46+
3747
### Example 1: Transfer the style of a style photo to a content photo.
3848
- Create image and output folders and make sure nothing is inside the folders. `mkdir images && mkdir results`
3949
- Go to the image folder: `cd images`

demo.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode).
44
"""
55

6+
from __future__ import print_function
67
import argparse
78

89
import torch
@@ -11,7 +12,8 @@
1112
from photo_wct import PhotoWCT
1213

1314
parser = argparse.ArgumentParser(description='Photorealistic Image Stylization')
14-
parser.add_argument('--model', default='./PhotoWCTModels/photo_wct.pth', help='Path to the PhotoWCT model')
15+
parser.add_argument('--model', default='./PhotoWCTModels/photo_wct.pth',
16+
help='Path to the PhotoWCT model. These are provided by the PhotoWCT submodule, please use `git submodule update --init --recursive` to pull.')
1517
parser.add_argument('--content_image_path', default='./images/content1.png')
1618
parser.add_argument('--content_seg_path', default=[])
1719
parser.add_argument('--style_image_path', default='./images/style1.png')
@@ -21,7 +23,12 @@
2123

2224
# Load model
2325
p_wct = PhotoWCT()
24-
p_wct.load_state_dict(torch.load(args.model))
26+
try:
27+
p_wct.load_state_dict(torch.load(args.model))
28+
except:
29+
print("Fail to load PhotoWCT models. PhotoWCT submodule not updated?")
30+
exit()
31+
2532
p_wct.cuda(0)
2633

2734
process_stylization.stylization(

process_stylization_examples.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode).
44
"""
55

6+
from __future__ import print_function
67
import argparse
78
import os
89

@@ -12,7 +13,8 @@
1213
import process_stylization
1314

1415
parser = argparse.ArgumentParser(description='Photorealistic Image Stylization')
15-
parser.add_argument('--model', default='./PhotoWCTModels/photo_wct.pth', help='Path to the PhotoWCT model')
16+
parser.add_argument('--model', default='./PhotoWCTModels/photo_wct.pth',
17+
help='Path to the PhotoWCT model. These are provided by the PhotoWCT submodule, please use `git submodule update --init --recursive` to pull.')
1618
args = parser.parse_args()
1719

1820
folder = 'examples'

0 commit comments

Comments
 (0)