I'm in need of help on how to print the values in the loop, as they pass through the ReLU3 layer

Heberht_Dias: <p>Hi!</p>
<p>I’m in need of help on how to print the values ​​in the loop, as they pass through the ReLU3 layer. The idea is to save each layer view.</p>
<p>my code:</p>
<p>import torch.nn as nn</p>
<p>import torch.nn.functional as F</p>
<p>import brevitas.nn as qnn</p>
<p>from brevitas.quant import IntBias</p>
<p>from brevitas.inject.enum import ScalingImplType</p>
<p>from brevitas.inject.defaults import Int8ActPerTensorFloatMinMaxInit</p>
<p>class convModel(nn.Module):</p>
<pre><code>def __init__(self):

    super().__init__()

    # Conv2D(in_channels, out_channels, kernel_size, ...)

    self.quantconv1 = qnn.QuantConv2d(3, 32, 3, weight_bit_width=4)

    self.batchnorm1 = nn.BatchNorm2d(32)

    self.quantReLU1 = qnn.QuantReLU(bit_width=4)

    self.quantconv2 = qnn.QuantConv2d(32, 64, 3, weight_bit_width=4)

    self.batchnorm2 = nn.BatchNorm2d(64)

    self.quantReLU2 = qnn.QuantReLU(bit_width=4)

    self.quantconv3 = qnn.QuantConv2d(64, 128, 3, weight_bit_width=4)

    self.batchnorm3 = nn.BatchNorm2d(128)

    self.quantReLU3 = qnn.QuantReLU(bit_width=4)

    self.quantconv4 = qnn.QuantConv2d(128, 128, 3, weight_bit_width=4)

    self.batchnorm4 = nn.BatchNorm2d(128)

    self.quantReLU4 = qnn.QuantReLU(bit_width=4)

    self.quantconv5 = qnn.QuantConv2d(128, 128, 3, weight_bit_width=4)

    self.batchnorm5 = nn.BatchNorm2d(128)

    self.quantReLU5 = qnn.QuantReLU(bit_width=4)

    

    # MaxPool2D(kernel_size, stride, ...)

    self.quantmaxpool = qnn.QuantMaxPool2d(2, 2)

    self.dropout1 = qnn.Dropout2d(0.2)

    self.dropout2 = qnn.Dropout2d(0.4)

    

    self.quantfc1 = qnn.QuantLinear(4 * 4 * 128, 512)

    self.quantfc2 = qnn.QuantLinear(512, 256)

    self.quantfc3 = qnn.QuantLinear(256, 84)

    self.quantfc4 = qnn.QuantLinear(84, 10)

    

def forward(self, x):

    x = F.QuantReLU(self.batchnorm1(self.quantconv1(x)))              # 32 filtros

    x = F.relu(self.batchnorm2(self.quantconv2(x)))                   # 64 filtros

    x = self.quantmaxpool(self.batchnorm3(self.quantconv3(x)))        # 128 filtros

    x = F.QuantReLU(x)

    x = F.QuantReLU(self.batchnorm4(self.quantconv4(x)))              # 128 filtros

    x = self.quantmaxpool(self.batchnorm5(self.quantconv5(x)))        # 128 filtros

    x = F.QuantReLU(x)

    

    x = torch.flatten(x, 1)

    x = F.QuantReLU(self.quantfc1(x))

    x = quantdropout2(x)                                              # 40%

    x = F.QuantReLU(self.quantfc2(x))

    x = quantdropout1(x)

    x = F.QuantReLU(self.quantfc3(x))

    x = quantdropout1(x)

    x = quantdropout4(x)

    

    return x</code></pre>

ptrblck: <p>I’m not sure I understand the question completely. It seem you would like to print the outputs of <code>self.quantReLU3</code> but this layer doesn’t seem to be used at all in the <code>forward</code> method.<br>
Could you explain the use case a bit more and which value should be printed?</p>

Heberht_Dias: <p>Good Morning <a class="mention" href="/u/ptrblck">@ptrblck</a></p>
<p>Let me explain my project:</p>
<p>My project about Split Learning.</p>
<p>I created a CNN with Dataset Cifar10, after that I did a quantization with brevitas. The next step now is to create a variable that each batch will store the output data from ReLU3. I need to do this in the middle of the loop and go to print as the values pass through the chosen bed.</p>