-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AIMET and YOLOv5 #1067
Comments
Hi @cascosula , Seems that this issue is caused by the SPPF of yolov5, maybe you could replace it with the equivalent SPP. Check the following for additional context about the SPPF module |
Thank for your reply! This work for me! I have another question that if I need SPPF for speeding up mentioned in ultralytics/yolov5#4420,
|
I guess that we can use other technique to speed up the inference of SPP. |
@cascosula Thanks for reporting this and @zhiqwang Thanks for pitching in. @cascosula just curious about modified block - why was this needed? |
Hi @quic-ssiddego and @cascosula , This problem occurs because SPPF will reuse the node nn.MaxPool2d. And in fact, many downstream inference frameworks do not have good support for this way of calling functions, such as nni and ncnn. (ncnn use an assign unique pass to resolve this issue later.) The main purpose of YOLOv5's newly proposed SPPF is to speed up inference (vs SPP), but this speedup has only been tested on PyTorch platform, and its internal operators may change further if it is converted to other platforms via ONNX or torchscript. Maybe we need further data to judge whether this module could be accelerated on the end platform. I think at this stage we can directly use the traditional SPP and optimize the inference of this module by means of something like passing on the inference framework due to the fact that there are downstream incompatibilities. |
Hi @quic-ssiddego, |
Hi @zhiqwang, |
Hi, did you quantize yolov5 with SPP successfully? I try to quantize yolov5(v5) with QuantizationSimModel but when call function sim.compute_encodings() it throw error: "AttributeError: 'StaticGridQuantWrapper' object has no attribute 'f'". Could you help to fix it? Thanks. |
In yolov5 forward method, it assign "f", "i" to modules to help connecting its dataflow. After quantsim adding wrapper modules, you can add these attributes back externally to wrapper modules before calling sim.compute_encodings.
Or you can modify the initialization of wrapper module in qc_quantize_op.py. You can add these attributes in module_to_wrap to wrapper module. The same error will happen when exporting onnx model. |
Hi, I appreciate that you reply quickly. However, after adding add 'i' and 'f' to wrapper modules, I met other error
Do you know how to fix it? Thanks for helping me! |
This problem is caused by the Concat module in yolov5. |
Hi, Thank for your guide. But could you provide me the code how to skip quantization of Concat layer, I really don't know how to do. And could you share your accuray you get when trying quatization technique with aimet (cle, adaround or QAT) for yolov5? |
You could modify forward method of StaticGridQuantWrapper in qc_quantize_op.py
|
Hi, I followed your guide and successfully quantized with Quansim technique. However, when exporting to onnx, I don't know how to add "i" and "f" to wrapper module in onnx_utils.py. Could you help me to pass over this problem? Thanks very much! |
Hi @tucachmo2202, This problem is similar to that quantsim adds wrapper modules but wrapper modules do not have these attributes. |
Hi, it's so embarrassing to annoy you again. But I don't know how to modify initialization of wrapper module. It's very nice of you that you provide me the code to do that. Thank you very much! |
Hi @cascosula, I'm stuck to convert onnx too. Would you mind helping me with the code to modify CustomMarker in onnx_utils.py. Thank you very much! |
Hi, You could find a classmethod of OnnxSaver class.
|
I exported model to onnx successfully. Thank you very much! |
@cascosula Is the support for nodes with list input available? Like I have a custom node which takes in list of tensors. Also I cant just avoid quantizing such nodes as I have an issue also with a Concat node with input tensors with different range of inputs hence need channel wise quantization in such case |
您好,您已经成功进行了yolov5的QAT吗?我在进行感知量化训练时精度一直上不去,可以让我看一下你的量化代码吗? |
Hi, currently I was trying to quantized YOLOv5n(v6.0) with AIMET(v1.19.1) and aimed to futher applied the quantized model to device through Snapdragon Neural Processing SDK(1.59).
I have followed suggestions in #168 but failed at applying AIMET to YOLOv5.
Error occured as I applied batchnorm folding to YOLOv5
The error message is
It seems that it is invalid to apply AIMET to models with reused layers. However, I could do batchnorm folding to yolov5 with SNPE tools and obtain quantized model in *.dlc.
I am wondering the difference between AIMET and SNPE.
Is it possible to build the quantization pipeline AIMET+SNPE to YOLOv5?
The text was updated successfully, but these errors were encountered: