From 8c663db10aeb9ca0d853146e54b312484344b194 Mon Sep 17 00:00:00 2001 From: Valentin Date: Wed, 31 May 2017 05:40:28 +0300 Subject: [PATCH] Initialize random numbers generator at start When model is being loaded/rebuild, Torch's random numbers generator is not yet initialized with manual seed, which makes always random images with NIN ImageNet model, even with "-seed" option. Because NIN ImageNet model (https://github.com/BVLC/caffe/wiki/Model-Zoo#network-in-network-model) uses dropout layer with random values. Placing RNG initialization at start allows repeatable results (with manual seed) with NIN ImageNet model, like with VGG models. --- neural_style.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/neural_style.lua b/neural_style.lua index adc7621..c21cb5f 100644 --- a/neural_style.lua +++ b/neural_style.lua @@ -50,6 +50,9 @@ cmd:option('-style_layers', 'relu1_1,relu2_1,relu3_1,relu4_1,relu5_1', 'layers f local function main(params) + if params.seed >= 0 then + torch.manualSeed(params.seed) + end local dtype, multigpu = setup_gpu(params) local loadcaffe_backend = params.backend @@ -195,9 +198,6 @@ local function main(params) collectgarbage() -- Initialize the image - if params.seed >= 0 then - torch.manualSeed(params.seed) - end local img = nil if params.init == 'random' then img = torch.randn(content_image:size()):float():mul(0.001)