get_submodule
- UNet.get_submodule(target: str) Module
- Returns the submodule given by - targetif it exists, otherwise throws an error.- For example, let’s say you have an - nn.Module- Athat looks like this:- A( (net_b): Module( (net_c): Module( (conv): Conv2d(16, 33, kernel_size=(3, 3), stride=(2, 2)) ) (linear): Linear(in_features=100, out_features=200, bias=True) ) )- (The diagram shows an - nn.Module- A.- Ahas a nested submodule- net_b, which itself has two submodules- net_cand- linear.- net_cthen has a submodule- conv.)- To check whether or not we have the - linearsubmodule, we would call- get_submodule("net_b.linear"). To check whether we have the- convsubmodule, we would call- get_submodule("net_b.net_c.conv").- The runtime of - get_submoduleis bounded by the degree of module nesting in- target. A query against- named_modulesachieves the same result, but it is O(N) in the number of transitive modules. So, for a simple check to see if some submodule exists,- get_submoduleshould always be used.- Parameters:
- target – The fully-qualified string name of the submodule to look for. (See above example for how to specify a fully-qualified string.) 
- Returns:
- The submodule referenced by - target
- Return type:
- torch.nn.Module 
- Raises:
- AttributeError – If the target string references an invalid path or resolves to something that is not an - nn.Module