Skip to content

Commit d976cfc

Browse files
committed
🎲 Support for setting the random seed.
1 parent fa3398b commit d976cfc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/texturize/__main__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
|_| |_|\___|\__,_|_| \__,_|_| \__\___/_/\_\\__|\__,_|_| |_/___\___|
77
88
Usage:
9+
texturize SOURCE... [--size=WxH] [--output=FILE] [--seed=SEED] [--device=DEVICE]
910
[--octaves=O] [--precision=P] [--iterations=I]
1011
texturize --help
1112
@@ -18,6 +19,7 @@
1819
Options:
1920
SOURCE Path to source image to use as texture.
2021
-s WxH, --size=WxH Output resolution as WIDTHxHEIGHT. [default: 640x480]
22+
--seed=SEED Configure the random number generation.
2123
--device=DEVICE Hardware to use, either "cpu" or "cuda".
2224
--octaves=O Number of octaves to process. [default: 5]
2325
--precision=P Set the quality for the optimization. [default: 1e-4]
@@ -96,7 +98,7 @@ def _prepare_gram(self, features):
9698

9799

98100
def get_all_layers(critics):
99-
"""Determine the minimal list of layer features that needs to be extracted from the image.
101+
"""Determine the minimal list of features that needs to be extracted from the image.
100102
"""
101103
layers = set(itertools.chain.from_iterable(c.get_layers() for c in critics))
102104
return sorted(list(layers))
@@ -323,6 +325,13 @@ def main():
323325
# Scan all the files based on the patterns specified.
324326
files = itertools.chain.from_iterable(glob.glob(s) for s in config["SOURCE"])
325327
for filename in files:
328+
# If there's a random seed, use it for all images.
329+
if config["--seed"] is not None:
330+
seed = int(config["--seed"])
331+
torch.manual_seed(seed)
332+
torch.cuda.manual_seed(seed)
333+
334+
# By default, disable autograd until the core optimization loop.
326335
with torch.no_grad():
327336
try:
328337
run(config, filename)

0 commit comments

Comments
 (0)