How to import library from file in resource folder

how to import

from context.code.resources.ODConv import ODConv2d
from context.code.resources.utils import cluster, get_R, get_data, build_adata, co_embed, comp_tsne_km, comp_umap, preprocess, read_tiff
where resources is folder
such that it would be inside inference function which will call other function
model = MyModel()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/context/code/main.py”, line 220, in init
self.odconv2d = ODConv2d(in_planes=3, out_planes=16, kernel_size=4,
^^^^^^^^
NameError: name ‘ODConv2d’ is not defined

Are you trying to do it from a Notebook? If you are using a custom library, I suggest you submit via the CLI instead.

If you still want to keep working on Colab, you can try to:

from resources.ODConv import ODConv2d
from resources.utils import cluster, get_R, get_data, build_adata, co_embed, comp_tsne_km, comp_umap, preprocess, read_tiff

# as long as your files are:
#   main.py
#   resources/
#     __init__.py   <- may be required
#     ODConv.py
#     utils.py

Be aware that the resources/ directory can change location and that is why you should always use the model_directory_path.

Please give me a Run ID so I can try to help you with the logs.

run# 25353 — 25362

what is model_directory_path ?
there are
(
test_directory_path: str,
data_file_path: str,
):
also i had troubles to use
from resources.ODConv import ODConv2d

this is probably work
from context.code.resources.ODConv import ODConv2d

i created init.py file in resources folder
and doing another attempt

Run #25353: You do not have access to internet while inside the runner. That is why it is crashing.

Run #25362: Your usage of the resources directory is pretty unique. Try the following:

import sys

def train(
    model_directory_path: str
):
    sys.path.append(model_directory_path)

    from ODConv import ODConv2d
    odconv2d = ODConv2d(...)

The model_directory_path is a parameter that will always contain the path to your resources/ directory, wherever it is located. (the full list is available here)

i got

File “/context/code/main.py”, line 498, in infer
sys.path.append(model_directory_path)
^^^^^^^^^^^^^^^^^^^^
NameError: name ‘model_directory_path’ is not defined

is it possible to define model_directory_path in infer function?

Parameters are dynamic, please just define it.