3

I am trying to implement StyleGAN2-ADA PyTorch: https://github.com/NVlabs/stylegan2-ada-pytorch.

On the GitHub repo, it states the following:

The above code requires torch_utils and dnnlib to be accessible via PYTHONPATH. It does not need source code for the networks themselves — their class definitions are loaded from the pickle via torch_utils.persistence.

What does this mean, and how can I do this?

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • Related... https://stackoverflow.com/questions/55985317/is-there-any-documentation-for-dnnlib-additional-lib-in-projects-of-nvlabs – AKX Sep 13 '21 at 21:14

1 Answers1

1

Let's say you have the source code of this repo cloned to /somepath/stylegan2-ada-pytorch which means that the directories you quoted are at /somepath/stylegan2-ada-pytorch/torch_utils and /somepath/stylegan2-ada-pytorch/dnnlib, respectively.

Now let's say you have a python script that you want to access this code. It can be anywhere on your machine, as long as you add this to the top of your python script:

import os
import sys

#save the literal filepath to both directories as strings
tu_path = os.path.join('somepath','stylegan2-ada-pytorch','torch_utils')
dnnlib_path = os.path.join('somepath','stylegan2-ada-pytorch','dnnlib')

#add those strings to python path
sys.path.append(tu_path)
sys.path.append(dnnlib_path )

Note that this only adds those location to PYTHONPATH for the duration of that python script running, so you need this at the top of any python script that intends to use those libraries.

Cobra
  • 612
  • 6
  • 15
  • As a side note: with the Path class ( `from pathlib import Path` ) you can operate on paths in a much nicer way. `tu_path = Path('somepath') / 'stylegan2-ada-pytorch' / 'torch_utils'` and then do higher level path operations on the `tu_path` object. – Peter Moore Sep 14 '21 at 01:49