[BUG] No ways provided to replicate fps on retrained models.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9.3k
- Forks
- 4.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 4
Description
Add Link
https://pytorch.org/tutorials/intermediate/realtime_rpi.html
Describe the bug
I am getting 25-30fps on my rpi4 with provided snippet.
However, after finetuning mobilenet_v2 and applying:
# Quantize the model
quantized_model = torch.quantization.quantize_dynamic(
model, {torch.nn.Linear}, dtype=torch.qint8
)
# Convert the quantized model to TorchScript
script_model = torch.jit.script(quantized_model)
I am only getting 2.5fps.
The tutorial suggests:
You can create your own model or fine tune an existing one. If you fine tune on one of the models from [torchvision.models.quantized](https://pytorch.org/vision/stable/models.html#quantized-models) most of the work to fuse and quantize has already been done for you so you can directly deploy with good performance on a Raspberry Pi.
But provides no guidance on how to do it.
My attempts to do so failed:
torch.backends.quantized.engine = 'qnnpack'
model = models.quantization.mobilenet_v2(pretrained=True, quantize=True) # INT
num_classes = 3
model.classifier[1] = torch.nn.Linear(model.last_channel, num_classes)
would result in
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
[<ipython-input-48-ddcd2d77aac5>](https://localhost:8080/#) in <cell line: 24>()
39
40 # Forward pass
---> 41 outputs = model(inputs)
42 loss = criterion(outputs, labels)
43
6 frames
[/usr/local/lib/python3.10/dist-packages/torch/nn/modules/linear.py](https://localhost:8080/#) in forward(self, input)
112
113 def forward(self, input: Tensor) -> Tensor:
--> 114 return F.linear(input, self.weight, self.bias)
115
116 def extra_repr(self) -> str:
RuntimeError: mat1 and mat2 must have the same dtype
Multiple attempts to create custom Linear layer that supports int8 dtype also failed.
Describe your environment
not relevant
cc @datumbox @nairbv @fmassa @NicolasHug @YosuaMichael
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked realtime Raspberry Pi tutorial and compare its quantization snippet with the reported fine-tuned MobileNetV2 flow. Reproduce the 2.5fps result and the mat1/mat2 dtype error, then document a verified retraining and deployment path that achieves the tutorial's expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation, machine-learning
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100