0

Pardon my relative inexperience in Python, I am trying to run this code (taken from GitHub) but interpreter is unable to resolve the reference for ini_file_io and model (I have seen a similar post, but I am seeing the same issue both on PyCharm and MS Visual Studio Code). Directory Structure is as follows:

Directory Structure

Here is the main.py: (both ini_file_io.py and model.py are available in same directory)

import os
import tensorflow as tf


from ini_file_io import load_train_ini       #Unresolved Reference
from model import cgan_unet_xy               #Unresolved Reference


def main(_):

    # load training parameter #
    ini_file = '../outcome/model/ini/tr_param.ini'
    param_sets = load_train_ini(ini_file)
    param_set = param_sets[0]

    print('====== Phase >>> %s <<< ======' % param_set['phase'])

    if not os.path.exists(param_set['chkpoint_dir']):
        os.makedirs(param_set['chkpoint_dir'])
    if not os.path.exists(param_set['labeling_dir']):
        os.makedirs(param_set['labeling_dir'])

    with tf.Session() as sess:
        model = cgan_unet_xy(sess, param_set)

        if param_set['phase'] == 'train':
            model.train()
        elif param_set['phase'] == 'test':
            model.test()
        elif param_set['phase'] == 'crsv':
            model.test4crsv()

if __name__ == '__main__':
    tf.app.run()

Any help will be really appreciated.

3
  • can you load a pic of your directory structure or do a tree so we can be crystal clear here? Commented Oct 24, 2018 at 1:51
  • @LeKhan9 Ok wait a min. (Its same as this github.com/xy0806/3D-cGAN/tree/master/FCN_cGAN_3D_full_xy/… by the way) Commented Oct 24, 2018 at 1:53
  • Also, is there a reason you are passing an underscore to main? I believe you can rm that Commented Oct 24, 2018 at 2:27

1 Answer 1

1
  1. Try adding a empty file named __init__.py that is the same directory level as the 3 files in question: main, ini.., and model

    Python uses these files as markers for directory level imports


  1. Note that this should not be a concern for same dir level files. I believe you may be running the code from the wrong place. Try to cd into the directory that these files exist it and run the main.py there instead of some other directory.

    If you can't do that then you'd have to add that dir to your python path.

  2. You can also try a relative import — try from .ini_file_io import load_train_ini instead.

Sign up to request clarification or add additional context in comments.

7 Comments

I have tried this but didn't work yet. (Fixed _ in main() as well)
Just to be clear, have you tried running from the terminal by cd'ing there instead of on Pycharm? Sometimes Pycharm running dir can get funky
You can also try a relative import — try from .ini_file_io import load_train_ini instead.
Yeah you are right. I have tried from terminal but its giving another import issue, let me get back to you once its fixed to confirm its really working. Thanks a lot!
I am still fixing those other errors so not in the state to evaluate it being perfect solution but nevertheless I have upvoted it for the time you taken to help me and maybe it would be the correct solution as well.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.