In ./pipelines/_train.py
, aim to import something from 3 different path levels:
./_config.py
(in father path)./networks/_cnn.py
(in cousin path)./networks/autoencoder/encoder.py
(in nephew path)
- Add
__init__.py
in each path where there exits more than one files, such as./networks/__init__.py
. - Import everything necessary under the same path, for example, import
encoder
anddecoder
in./networks/autoencoder/__init__/py
.
In Python 3.6.7, it's unfeasible to use the script below in _train.py
to import files under ./networks
:
import sys
sys.path.append("..")
because the current path you run _train.py
is ./pipelines/
, you have to add this scipt in _train.py
:
sys.path.append("../networks")
emmmmm..., how about files under networks/autoencoder
? It's not elegant to add so many lines.
Extend all paths recursively. I know it's not beautiful, but it really works.
# in _train.py (I wanna run it at path ./pipelines)
import sys, os
sys.path.extend([".."] + [os.path.join(root, name) for root, dirs, _ in os.walk("../") for name in dirs])
$ cd pipelines
$ python _train.py
You will see:
batch_size = 64
epochs = 500
cnn_layer1
lstm_layer1