-
Notifications
You must be signed in to change notification settings - Fork 1
/
option.py
103 lines (96 loc) · 6.51 KB
/
option.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import argparse
import os
class Options():
def __init__(self):
self.parser = argparse.ArgumentParser(description="parser for MXNet-Gluon-Style-Transfer")
subparsers = self.parser.add_subparsers(title="subcommands", dest="subcommand")
# training args
train_arg = subparsers.add_parser("train",
help="parser for training arguments")
train_arg.add_argument("--ngf", type=int, default=64,
help="number of generator filter channels, default 128")
train_arg.add_argument("--epochs", type=int, default=4,
help="number of training epochs, default is 2")
train_arg.add_argument("--batch-size", type=int, default=4,
help="batch size for training, default is 4")
train_arg.add_argument("--dataset", type=str, default="dataset/",
help="path to training dataset, the path should point to a folder "
"containing another folder with all the training images")
train_arg.add_argument("--style-folder", type=str, default="images/styles/",
help="path to style-folder")
train_arg.add_argument("--save-model-dir", type=str, default="models/",
help="path to folder where trained model will be saved.")
train_arg.add_argument("--image-size", type=int, default=256,
help="size of training images, default is 256 X 256")
train_arg.add_argument("--style-size", type=int, default=512,
help="size of style-image, default is the original size of style image")
train_arg.add_argument("--cuda", type=int, default=1,
help="set it to 1 for running on GPU, 0 for CPU")
train_arg.add_argument("--seed", type=int, default=42,
help="random seed for training")
train_arg.add_argument("--content-weight", type=float, default=1.0,
help="weight for content-loss, default is 1.0")
train_arg.add_argument("--style-weight", type=float, default=5.0,
help="weight for style-loss, default is 5.0")
train_arg.add_argument("--lr", type=float, default=1e-3,
help="learning rate, default is 0.001")
train_arg.add_argument("--log-interval", type=int, default=500,
help="number of images after which the training loss is logged, default is 500")
train_arg.add_argument("--resume", type=str, default=None,
help="resume if needed")
# optim args (Gatys CVPR 2016)
optim_arg = subparsers.add_parser("optim",
help="parser for optimization arguments")
optim_arg.add_argument("--iters", type=int, default=500,
help="number of training iterations, default is 500")
optim_arg.add_argument("--content-image", type=str, default="images/content/venice-boat.jpg",
help="path to content image you want to stylize")
optim_arg.add_argument("--style-image", type=str, default="images/9styles/candy.jpg",
help="path to style-image")
optim_arg.add_argument("--content-size", type=int, default=512,
help="factor for scaling down the content image")
optim_arg.add_argument("--style-size", type=int, default=512,
help="size of style-image, default is the original size of style image")
optim_arg.add_argument("--output-image", type=str, default="output.jpg",
help="path for saving the output image")
optim_arg.add_argument("--cuda", type=int, default=1,
help="set it to 1 for running on GPU, 0 for CPU")
optim_arg.add_argument("--content-weight", type=float, default=1.0,
help="weight for content-loss, default is 1.0")
optim_arg.add_argument("--style-weight", type=float, default=5.0,
help="weight for style-loss, default is 5.0")
optim_arg.add_argument("--lr", type=float, default=1e1,
help="learning rate, default is 0.001")
optim_arg.add_argument("--log-interval", type=int, default=50,
help="number of images after which the training loss is logged, default is 50")
# evaluation args
eval_arg = subparsers.add_parser("eval", help="parser for evaluation/stylizing arguments")
eval_arg.add_argument("--ngf", type=int, default=128,
help="number of generator filter channels, default 128")
eval_arg.add_argument("--content-image", type=str, required=True,
help="path to content image you want to stylize")
eval_arg.add_argument("--style-image", type=str, default="images/9styles/candy.jpg",
help="path to style-image")
eval_arg.add_argument("--content-size", type=int, default=512,
help="factor for scaling down the content image")
eval_arg.add_argument("--style-size", type=int, default=512,
help="size of style-image, default is the original size of style image")
eval_arg.add_argument("--style-folder", type=str, default="images/9styles/",
help="path to style-folder")
eval_arg.add_argument("--output-image", type=str, default="output.jpg",
help="path for saving the output image")
eval_arg.add_argument("--model", type=str, required=True,
help="saved model to be used for stylizing the image")
eval_arg.add_argument("--cuda", type=int, default=1,
help="set it to 1 for running on GPU, 0 for CPU")
def parse(self):
return self.parser.parse_args()
class program_args():
def __init__(self,contentImage,styleImage,outputImage,ngf=128,size=512,cuda=0):
self.ngf = ngf #number of generator filter channels
self.size = size
self.contentImage = contentImage
self.styleImage = styleImage
self.outputImage = outputImage
self.cuda = cuda
self.model = 'models/models/21styles.params'