From d976cfc85a978af1a0949ec95beaba9a53e3222a Mon Sep 17 00:00:00 2001 From: "Alex J. Champandard" <445208+alexjc@users.noreply.github.com> Date: Mon, 25 May 2020 23:01:09 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=B2=20Support=20for=20setting=20the=20?= =?UTF-8?q?random=20seed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/texturize/__main__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/texturize/__main__.py b/src/texturize/__main__.py index b6d16ce..9e42756 100644 --- a/src/texturize/__main__.py +++ b/src/texturize/__main__.py @@ -6,6 +6,7 @@ |_| |_|\___|\__,_|_| \__,_|_| \__\___/_/\_\\__|\__,_|_| |_/___\___| Usage: + texturize SOURCE... [--size=WxH] [--output=FILE] [--seed=SEED] [--device=DEVICE] [--octaves=O] [--precision=P] [--iterations=I] texturize --help @@ -18,6 +19,7 @@ Options: SOURCE Path to source image to use as texture. -s WxH, --size=WxH Output resolution as WIDTHxHEIGHT. [default: 640x480] + --seed=SEED Configure the random number generation. --device=DEVICE Hardware to use, either "cpu" or "cuda". --octaves=O Number of octaves to process. [default: 5] --precision=P Set the quality for the optimization. [default: 1e-4] @@ -96,7 +98,7 @@ def _prepare_gram(self, features): def get_all_layers(critics): - """Determine the minimal list of layer features that needs to be extracted from the image. + """Determine the minimal list of features that needs to be extracted from the image. """ layers = set(itertools.chain.from_iterable(c.get_layers() for c in critics)) return sorted(list(layers)) @@ -323,6 +325,13 @@ def main(): # Scan all the files based on the patterns specified. files = itertools.chain.from_iterable(glob.glob(s) for s in config["SOURCE"]) for filename in files: + # If there's a random seed, use it for all images. + if config["--seed"] is not None: + seed = int(config["--seed"]) + torch.manual_seed(seed) + torch.cuda.manual_seed(seed) + + # By default, disable autograd until the core optimization loop. with torch.no_grad(): try: run(config, filename)