If I have to use a layer like simple_cnn I import from fastai.layers import *
If I have to use ItemList I import from fastai.data_block import *
So my question is why from fastai import * does not work (or what does it do, it does not import anything)? Why I have to import all files independently?
How I installed fastai?
Created a new pytorch env conda create -n PyTorch anaconda
from fastai import * : binds all submodules to the fastai namespace so that they can be referenced as fastai.XXXXX (where XXXX is submodule name like vision or tabular). But I don’t think it makes all functions available inside each submodule. Any functions that don’t reside in a submodule, i.e. inside the higher level fastai parent module are available though.
from fastai.layers import * based on the submodules link seems to implicitly load the fastai parent module. To me this means that writing from fastai.layers import * is the same as writing: from fastai import * and from fastai.layers import *. In that situation it seems from fastai import * is superfluous.
The behavior of from x import * is defined by whether or not you are importing from a package, a module or a subpackage of the parent package. Modules are *.py files (e.g. data_block.py, whereas subpackages are child directories of the parent package (e.g. fastai.vision).
If you’re importing a package or a subpackage, the default behavior is defined by the __init__.py file in that directory. In addition to specified imports in this file, the __all__ variable can specify additional packages for import. See the example below from the fastai.vision subpackage.
In the case of from fastai import *, the fastai/__init__.py file does not explicitly specify any imports or an __all__ variable.
In the case of from fastai import * , the fastai/__init__.py file does not explicitly specify any imports or an __all__ variable.
That’s helpful. I just screenshot-ed my fastai directory. I think based on that the from fastai import * buys you all of the *.py files and respective functions you can see in the screenshot (i.e. basic_data, basic_train, basics, callback, etc…) that aren’t in the subdirectories/subpackage/submodule. So fast.ai is minimally functional with fastai import * but you can’t use the tabular, text, vision subpackages unless you specifically import them.