前提・実現したいこと
Google ColaboratoryでStyleGANを実装しようとしています。(初学者です)
generatorをロードするのurlを変更することで他の画像も生成できると記載があった為、ImageNetデータセットで学習する予定です。(imagenetを用いたstyleganがstylegan+clipなどしかなかったため)
generatorのロードの部分で
ModuleNotFoundError: No module named 'torch_utils.persistence'
というエラーがでています
主に以下の記事を参考にして進めていましたが、わかりませんでした。
・https://teratail.com/questions/295390
・https://qiita.com/pacifinapacific/items/1d6cca0ff4060e12d336
・http://cedro3.com/ai/stylegan/
・https://qiita.com/Phoeboooo/items/12d21916de56d125f0be
発生している問題・エラーメッセージ
Python
1from google.colab import drive 2drive.mount('/content/drive') 3%cd /content/drive/My Drive 4 5 6#git clone でStyleGANのコードを使えるようにする 7!git clone https://github.com/NVlabs/stylegan.git 8 9#ディレクトリ移動 10%cd stylegan 11!pip uninstall tensorflow -y 12!pip install tensorflow-gpu==1.15.0 13import tensorflow.compat.v1 as tf 14tf.disable_v2_behavior() 15 16 17generatorをロードする 18 19import os 20import pickle 21import numpy as np 22import PIL.Image 23import dnnlib 24import dnnlib.tflib as tflib 25import config 26 27def main(): 28 # Initialize TensorFlow. 29 tflib.init_tf() 30 31 # Load pre-trained network. 32 url = 'https://s3.eu-central-1.amazonaws.com/avg-projects/stylegan_xl/models/imagenet512.pkl' # karras2019stylegan-ffhq-1024x1024.pkl 33 with dnnlib.util.open_url(url, cache_dir=config.cache_dir) as f: 34 _G, _D, Gs = pickle.load(f) 35 # _G = Instantaneous snapshot of the generator. Mainly useful for resuming a previous training run. 36 # _D = Instantaneous snapshot of the discriminator. Mainly useful for resuming a previous training run. 37 # Gs = Long-term average of the generator. Yields higher-quality results than the instantaneous snapshot. 38 39 # Print network details. 40 Gs.print_layers() 41 42 # Pick latent vector. 43 rnd = np.random.RandomState(10) # seed = 10 44 latents0 = rnd.randn(1, Gs.input_shape[1]) 45 latents1 = rnd.randn(1, Gs.input_shape[1]) 46 latents2 = rnd.randn(1, Gs.input_shape[1]) 47 latents3 = rnd.randn(1, Gs.input_shape[1]) 48 latents4 = rnd.randn(1, Gs.input_shape[1]) 49 latents5 = rnd.randn(1, Gs.input_shape[1]) 50 latents6 = rnd.randn(1, Gs.input_shape[1]) 51 52 num_split = 39 # 2つのベクトルを39分割 53 for i in range(40): 54 latents = latents6+(latents0-latents6)*i/num_split 55 # Generate image. 56 fmt = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True) 57 images = Gs.run(latents, None, truncation_psi=0.7, randomize_noise=True, output_transform=fmt) 58 59 # Save image. 60 os.makedirs(config.result_dir, exist_ok=True) 61 png_filename = os.path.join(config.result_dir, 'photo'+'{0:04d}'.format(i)+'.png') 62 PIL.Image.fromarray(images[0], 'RGB').save(png_filename) 63 64if __name__ == "__main__": 65 main()
該当のソースコード
Python
1ModuleNotFoundError Traceback (most recent call last) 2<ipython-input-8-a1bc236cff97> in <module> 3 45 4 46 if __name__ == "__main__": 5---> 47 main() 6 7<ipython-input-8-a1bc236cff97> in main() 8 14 url = 'https://s3.eu-central-1.amazonaws.com/avg-projects/stylegan_xl/models/imagenet512.pkl' # karras2019stylegan-ffhq-1024x1024.pkl 9 15 with dnnlib.util.open_url(url, cache_dir=config.cache_dir) as f: 10---> 16 _G, _D, Gs = pickle.load(f) 11 17 # _G = Instantaneous snapshot of the generator. Mainly useful for resuming a previous training run. 12 18 # _D = Instantaneous snapshot of the discriminator. Mainly useful for resuming a previous training run. 13 14ModuleNotFoundError: No module named 'torch_utils.persistence'
補足情報(FW/ツールのバージョンなど)
ImageNetの.plkファイルが見つけれず、下記サイトのモデル選択のurlをダウンロードしてGoogle Driveにアップロードして用いています。
エラーは
"https://s3.eu-central-1.amazonaws.com/avg-projects/stylegan_xl/models/imagenet512.pkl"
が原因だと思うのですが公式サイトなどにImageNetの.pklファイルがありましたら教えてもらえると幸いです。

回答1件
あなたの回答
tips
プレビュー