Hi, I am new to Deep Learning and Pytorch. I am interested in quantization and have gone through the Transfer learning and Post Training Static Quantization tutorial. However, there are a few questions that i hope to get some idea from the community.
For Transfer learning:
- I noticed that the quantized model implements a custom head, for fine tuning purpose. However, since the model is restructured due to the
from torch import nn
def create_combined_model(model_fe):
Step 1. Isolate the feature extractor.
model_fe_features = nn.Sequential(
model_fe.quant, # Quantize the input
model_fe.conv1,
model_fe.bn1,
model_fe.relu,
model_fe.maxpool,
model_fe.layer1,
model_fe.layer2,
model_fe.layer3,
model_fe.layer4,
model_fe.avgpool,
model_fe.dequant, # Dequantize the output
)Step 2. Create a new “head”
new_head = nn.Sequential(
nn.Dropout(p=0.5),
nn.Linear(num_ftrs, 2),
)Step 3. Combine, and don’t forget the quant stubs.
new_model = nn.Sequential(
model_fe_features,
nn.Flatten(1),
new_head,
)
return new_model
- Why is there no new
forward()
defined for it? Can theforward()
recognize the new network layout for the model automatically?
For Post Training Static Quantization:
- I noticed that the tutorial transforms the pretrained model to quantized model by merging the intermediate operations such as
nn.Conv2d()
,nn.ReLU()
andnn.BatchNorm2d()
, intoConvBnReLU2d()
. I know that the guideline in Quantization, suggests to perform operation fusing whenever quantizing a model. But is it possible to implement each quantized modules independently without fusing all of them as one? As i believe i have seen the quantization implementation ofnn.quantized.Conv2d()
,nn.quantized.ReLU()
. (Although there is nonn.quantized.BatchNorm2d()
yet). - The reason i am asking is because i am interested in extracting the intermediate outputs. I would like to inspect the intermediate outputs such as output from
nn.quantized.Conv2d()
andnn.quantized.ReLU()
independently. I believe if i fuse the module usingConvBnReLU2d
, it would only yield me the final output that has gone throughBatchNorm2d()
andReLU()
instead of the intermediate outputs for each intermediate operations, right?
I am new to this community and this is my first post. If this post does not follow the community guideline, please let me know. Thank you.