test_eq(find_model(162), ('resnet', 'resnet50'))
test_eq(find_model(585), ('densenet', 'densenet161'))
test_learner, _, _ = get_test_vars()
module5 = list(test_learner.model.named_modules())[5]
module_last = list(test_learner.model.named_modules())[-1]
test_eq(get_row(module5, 'resnet')['Module_name'], '0.3')
test_eq(get_row(module_last, 'resnet')['Layer_description'], 'Linear(in_features=512, out_features=37, bias=False)')
Utilities¶
test_eq(get_inp_sz(["Sequential (Input shape: ['128 x 3 x 224 x 224'])"]), "128 x 3 x 224 x 224" )
_, test_summary, _ = get_test_vars()
gen = infos_to_gen(test_summary.split('\n'))
test_eq(next(gen), ('Conv2d', '[128 x 64 x 112 x 11]', '9,408', 'False'))
CNDF class builds a dataframe using a fastai Learner and the output of Learner.summary() method. The resulting dataframe, called a CNDF dataframe, combines information from both sources and represents both the structure and information of Learner.model.
CNDF is a parent class of ConvNav and a CNDF dataframe is automatically built when a new ConvNav object is instantiated and for most use cases CNDF dataframes should be built this way. However, if there is a need to build a CNDF dataframe in isolation use:
cndf = CNDF(Learner, Learner.summary())
test_learner, test_summary, _ = get_test_vars()
cndf_test = CNDF(test_learner, test_summary)
test_eq(type(cndf_test._cndf), DataFrame)
test_eq(len(cndf_test._cndf), 79) # rows
test_eq(len(cndf_test._cndf.columns), 22) # columns
In native format, CNDF dataframes include the module objects in a 'lyr_obj' column and the combined size of the module objects can be quite large, 100-200mb for a complex model such as a densenet or xresnet. Thus, by default, module objects are removed from the dataframe. Set with_modules = True
to include module objects. in returned dataframe.
Element selectors¶
_, _, cndf_test = get_test_vars()
test_eq(get_layer(cndf_test, 2)['Module_name'], '0.0')
test_eq(get_layer(cndf_test, 1), None)