Search and modify layer/module outputs by name

Izan_C_G: <p>Hi, I wish to extract/modify several module outputs from <a href="https://pytorch.org/vision/stable/models/generated/torchvision.models.quantization.resnet50.html#torchvision.models.quantization.resnet50" rel="noopener nofollow ugc">Resnet50</a> pre-trained model. I desire to do so before the dequantized layers. I decided to see the model graph with Netron to know which ones I want. Because of that, I transformed the torchvision model to a onnx model with the following code:</p>
<pre><code class="lang-auto">weights = models.ResNet50_QuantizedWeights.DEFAULT
model = models.resnet50(weights=weights, quantize=True)

dummy_input = torch.randn(125, 3, 224, 224)
input_names = [ "actual_input" ]
output_names = [ "output" ]

torch.onnx.export(model, 
                  dummy_input,
                  "resnet50torch2-int8prova.onnx",
                  input_names=input_names,
                  output_names=output_names
                  )
</code></pre>
<p>The resulting graph is the following:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/3/c3d35877a11e231756946481c5152e115aad600e.png" data-download-href="https://discuss.pytorch.org/uploads/default/c3d35877a11e231756946481c5152e115aad600e" title="graph"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/3/c3d35877a11e231756946481c5152e115aad600e_2_690x402.png" alt="graph" data-base62-sha1="rWlUzOUJZzxivbTtqP1CKSq2zpA" width="690" height="402" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/3/c3d35877a11e231756946481c5152e115aad600e_2_690x402.png, https://discuss.pytorch.org/uploads/default/optimized/3X/c/3/c3d35877a11e231756946481c5152e115aad600e_2_1035x603.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/c/3/c3d35877a11e231756946481c5152e115aad600e_2_1380x804.png 2x" data-dominant-color="3C3C3C"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">graph</span><span class="informations">1860×1085 129 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>The output I want is named “onnx::DequantizeLinear_148”, which is also the input of a dequantize layer. However, my problem is that I don’t know how to identify this output in the pytorch model. When I print the model, there are no names and the model’s graph changes completely:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/8/b87b25ca3cd2412558bf487756a060ca2bf10bad.png" data-download-href="https://discuss.pytorch.org/uploads/default/b87b25ca3cd2412558bf487756a060ca2bf10bad" title="pytorch"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/b/8/b87b25ca3cd2412558bf487756a060ca2bf10bad_2_607x500.png" alt="pytorch" data-base62-sha1="qjZHdI9tQRjBbBooC9tRMedNlKJ" width="607" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/b/8/b87b25ca3cd2412558bf487756a060ca2bf10bad_2_607x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/b/8/b87b25ca3cd2412558bf487756a060ca2bf10bad_2_910x750.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/b/8/b87b25ca3cd2412558bf487756a060ca2bf10bad.png 2x" data-dominant-color="252525"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">pytorch</span><span class="informations">1128×929 119 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
How can I search the outputs by name and then modify or obtain for example, with some hooks? Any information or background or example code will help.</p>
<p>Thank you.</p>

HDCharles: <p>there is no dequantize op in the pytorch model.</p>
<p>you converted to onnx, which took a bunch of pytorch ops and converted them to onnx ops. This conversion isn’t 1 to 1 but often 1 to many, so it doesn’t exist. You may want to ask the onnx folks how you retrieve this conversion mapping.</p>