From 64bc5ca72983dbe4e92e4b1558ab796b157e67e2 Mon Sep 17 00:00:00 2001
From: Laurent COLBOIS <lcolbois@.idiap.ch>
Date: Mon, 10 May 2021 11:15:20 +0200
Subject: [PATCH] Fix StyleGAN2 pickle loading

---
 .../ijcb2021_synthetic_dataset/stylegan2/generator.py      | 7 +++++--
 .../stylegan2/pretrained_networks.py                       | 1 -
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/bob/paper/ijcb2021_synthetic_dataset/stylegan2/generator.py b/bob/paper/ijcb2021_synthetic_dataset/stylegan2/generator.py
index 31b2877..5605754 100644
--- a/bob/paper/ijcb2021_synthetic_dataset/stylegan2/generator.py
+++ b/bob/paper/ijcb2021_synthetic_dataset/stylegan2/generator.py
@@ -1,10 +1,11 @@
-from . import dnnlib, pretrained_networks
+from . import dnnlib
 from .dnnlib import tflib
 from .. import utils
 from bob.extension import rc
 import numpy as np
 import bob.io.image
 import tensorflow as tf
+import pickle
 
 class StyleGAN2Generator(object):
     def __init__(self, 
@@ -24,7 +25,9 @@ class StyleGAN2Generator(object):
                                 and for all at initialization.
         :param image_postprocessing_fn : Additional function to apply to the generated images before saving. 
         """
-        _G, _D, Gs = pretrained_networks.load_networks(sg2_path)
+        with open(sg2_path, 'rb') as pkl_file:
+            _G, _D, Gs = pickle.load(pkl_file)
+
         self.network = Gs
         self.latent_dim = self.network.input_shape[-1]
         self.run_kwargs = {'randomize_noise': randomize_noise,
diff --git a/bob/paper/ijcb2021_synthetic_dataset/stylegan2/pretrained_networks.py b/bob/paper/ijcb2021_synthetic_dataset/stylegan2/pretrained_networks.py
index 9ad3e5e..7573ac0 100644
--- a/bob/paper/ijcb2021_synthetic_dataset/stylegan2/pretrained_networks.py
+++ b/bob/paper/ijcb2021_synthetic_dataset/stylegan2/pretrained_networks.py
@@ -9,7 +9,6 @@
 import pickle
 import sys
 import os
-sys.path.append('/idiap/home/lcolbois/colbois_reporting/synthface/synthface/stylegan2')
 from . import dnnlib
 from dnnlib import tflib
 
-- 
GitLab