Problems about import modules

I try to read faster r-cnn implemented by ruotianluo. Almost all important python files are in ‘‘lib’’ fold, which is not a package (there is no init.py file under it). I really don’t understand why modules can be import using code like ‘from model.config import cfg’ (model is a fold in lib, and config is a ‘.py’ file under model).
The detailed program structure can be found in https://github.com/ruotianluo/pytorch-faster-rcnn, and the import sample can be seen in https://github.com/ruotianluo/pytorch-faster-rcnn/blob/master/lib/model/train_val.py

Let me see if I can help. Folders are folders, they are there because of your O. S. As long as your python folders are in your python path(where python looks for folders and files) Python can see the folder and make use of its contents. Modules end in .py. They can contain the init function, but don’t have to. I have wrote modules with pure functional code, meaning no init and no classes. They need to be imported to be used. Importing saves memory as you don’t need to import all modules on your computer to run your code only the ones you need. It also saves time because you don’t have to wait for your computer to load imported files off the hard drive they are read off the hard drive once and stored in memory. You can import modules, classes and even single functions. Then, after you import you need to create a “version” or instance of the imported object to be able to use it, if it’s a class. You don’t need to create a “version” or instance if its a function.
So in your example, you are telling your program to look in the lib folder, and the model module. You are giving directions on where to go. Once it is looking in the model.config you tell it to load the cfg class into memory because it will be needed later. It would be like me telling you the directions to the store and then telling you to grab some bread while you are there because we will need it later

I get it. Just now, I found ‘lib’ is added into python path in ‘_init_paths.py’ .
Thank you.