verbose: 1 = Index and Layer_name columns only; 2 = Model structure; 3 = Model Structure and layer_info (output dims, params and frozen/unfrozen); 4 = include layer_info and block/layer counts in container rows; 5 = expose hidden columns.tight: True = tight layout with minimal space between rows (best for large models with many rows to display). False = display dataframe with normal row spacing. The default is True but less than 10 rows are automatically displayed with normal spacing.truncate: truncate number displayed columns by integer value between -10 and 10. 0 = default. Negative values reveal hidden columns. Overidden when the verbose argument is set to a non-default setting.align_cols: 'left' or 'right' alignment of column datatop: display first 10 rows only followed by a count of undisplayed rows
Searchterm can be:
int: the module with Index numberintis returnedfloat: module(s) wherestr(float)matches the Layer_name are returnedstr: module(s) withstrin one of 'Layer_name', 'Torch_class', 'Division', 'Module', 'Block', 'Layer_description' are returned. Columns are searched in this order with the search ending with the first column to make a match/matches.dict, e.g. {'col', 'str'} matchesstrin columncol
Searchterms can also be a combined as follows:
[101, 102, 105]logical OR of rows matching indexes101,102plus103('0.5', 'conv2d')logical AND of rows matching0.5in Layer_name andconv2dinLayer_description{{'col1', 'str1'}, {'col2', 'str2'}}logical OR of matchesstr1incol1plusstr2incol'.
Return only exact matches between searchterm and column entry with exact = True (default).
.
%%capture
_, _, test_df = get_test_vars()
test_df['lyr_obj'] = None
test_eq(len(cndf_search(test_df, 12, )), 1)
test_eq(len(cndf_search(test_df, '0.6.1.conv2')), 1)
test_eq(len(cndf_search(test_df, 0.6, exact=False)), 16)
test_eq(len(cndf_search(test_df, {'Module_name': '0.6', 'Layer_description':'Conv2d'}, exact=True)), 1)
test_eq(len(cndf_search(test_df, ['0.6', '0.5'], exact=False)), 32)
test_eq(cndf_search(test_df, ('0.6', '0.5'), exact=False), None)
Fastai2 Learner objects are created from a dataloader, model and optimizer as decribed in the fastai documentation https://dev.fast.ai/ (also 03_examples00.ipynb and 04_examples01.ipynb). Run convnav_supported_models() from a notebook cell to see the list of supported models.
cn = ConvNav(Learner, Learner.summary()
test_learner, test_summary, _ = get_test_vars()
cn_test = ConvNav(test_learner, test_summary)
test_eq(type(cn_test._cndf), DataFrame)
test_eq(len(cn_test._cndf), 79) # rows
test_eq(len(cn_test._cndf.columns), 22) # columns
Search and view the CNDF dataframe.¶
Additional methods:¶
Searchterm b should be the block's module name from model.named_modules(). Preceeding '0.' are removed so '0.0.6.1', '0.6.1' and '6.1' are all equivelent and match Container_block 1 of Container_child 6. Block layers are included by default. To return the block container element only, set layers=False. To just get the block's layers, set layers_only=True.
Spread is an ideal method for finding a small group of evenly spaced model elements (typically blocks) to use to investigate model activity, particularly for larger models (see 04_examples01.ipynb).
%%capture
test_learner, test_summary, _ = get_test_vars()
cn_test = ConvNav(test_learner, test_summary)
test_eq(len(cn_test.search(0.6, exact=False, show=False)), 16)
cn_test.view()
cn_test.head
cn_test.body
cn_test.divs
test_eq(len(cn_test.linear_layers), 2)
test_eq(len(cn_test.dim_transitions), 5)
test_eq(len(cn_test.find_block('0.5.1')), 6)
test_eq(len(cn_test.find_block('0.5.1', layers=False)), 1)
test_eq(len(cn_test.find_conv('first', 5)), 5)
test_eq(len(cn_test.children), 8)
test_eq(len(cn_test.blocks), 8)
test_eq(len(cn_test.spread('conv', 8)), 7)
del(cn_test)
Saving and loading CNDF dataframes.¶
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 before saving. To save the model objects as well, check you have enough space in the download location and set with_modules to True. Dataframes are gzip compressed.