Relative import – from from ZSSGAN.model.ZSSGAN import ZSSGAN

Question:

I’m working on the StyleGAN-NADA repo, and I am having issues loading the ZSSGAN function. The command line to do so is from ZSSGAN.model.ZSSGAN import ZSSGAN, where

  1. The first ZSSGAN is the name of a folder
  2. model is a folder inside the first folder
  3. The second ZSSGAN is a script
  4. The third ZSSGAN is a function inside the script, which defines a network architecture

If I give the command from ZSSGAN.model.ZSSGAN import ZSSGAN the code hangs and it never completes the task. If I cd into the ZSSGAN folder and give as a command from model.ZSSGAN import ZSSGAN, the task is completed in a few seconds. Unfortunately, this not a solution for me.

Is there a way I can rewrite from ZSSGAN.model.ZSSGAN import ZSSGAN efficiently, so that the ZSSGAN function can be loaded from outside the ZSSGAN folder?

ZSSGAN folder 
 |
 |
 model folder
     |
     |
     ZSSGAN script
         |
         |
         ZSSGAN function

The absolute path to the ZSSGAN folder is already appended to sys.path.

Asked By: albus_c

||

Answers:

The authors of this repository made this ZSSGAN folder as the collection of the packages and scripts, and even their train.py script is inside of the ZSSGAN folder.

All their relative imports has been set up that way. But i believe you can make the ZSSGAN folder a master package by changing all relative imports in this project, like examples below:

in ZSSGAN/mapper/latent_mappers.py

from mapper.stylegan2.model import EqualLinear, PixelNorm

in ZSSGAN/model/sg2_model.py

from op import FusedLeakyReLU, fused_leaky_relu, upfirdn2d, conv2d_gradfix
Answered By: unfathomable loss
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.