pytorch - How to find the name of layers in preloaded ...
stackoverflow.com › questions › 68924829Aug 25, 2021 · To get the actual exact name of the layer you can loop over the modules with named_modules and only pick the nn.ReLU layers: >>> relus = [name for name, module in model.named_modules() if isinstance(module, nn.ReLU)] >>> relus ['backbone.relu', 'backbone.layer1.0.relu', 'backbone.layer1.1.relu', 'backbone.layer1.2.relu', 'backbone.layer2.0.relu', 'backbone.layer2.1.relu', 'backbone.layer2.2.relu', 'backbone.layer2.3.relu', 'backbone.layer3.0.relu', 'backbone.layer3.1.relu', 'backbone.layer3 ...