用户您好,请详细描述您所遇到的问题,这会帮助我们快速定位问题~
1.芯片型号 :J5
2.天工开物开发包OpenExplorer版本 :J5_OE_1.1.40
3.问题定位 :模型转换
4.问题具体描述 :
参考用户手册4.2.5.3.4.2. 章节的fx示例来插入和可视化centered_yuv2bgr节点
手册链接:https://developer.horizon.cc/api/v1/fileData/horizon\_j5\_open\_explorer\_cn\_doc/plugin/source/advanced\_content/rgb888\_deploy.html
插入该算子后,转hbm模型失败
试了一下,不插入该算子则可以生成hbm模型
颜值即正义
2023 年11 月 1 日 02:17
2
颜值即正义
2023 年10 月 27 日 02:48
3
可以把插入centered_yuv2bgr节点的部分的代码发一下,我们这边检查一下
颜值即正义
2023 年10 月 27 日 02:48
4
你好,你这边可视化graphe后,可以看到插入的centered_yuv2bgr节点嘛?
import torch-
from horizon_plugin_pytorch.quantization import (-
QuantStub,-
prepare_qat_fx,-
convert_fx,-
)-
from horizon_plugin_pytorch.functional import centered_yuv2rgb-
from horizon_plugin_pytorch.quantization.qconfig import (-
default_qat_8bit_fake_quant_qconfig,-
)-
import horizon_plugin_pytorch as horizon-
from horizon_plugin_pytorch import set_march-
import os-
class Net(torch.nn.Module):-
def __init__(self):-
super().__init__()-
self.quant = QuantStub()-
self.conv = torch.nn.Conv2d(3, 3, 3)-
self.bn = torch.nn.BatchNorm2d(3)-
self.relu = torch.nn.ReLU()-
def forward(self, input):-
x = self.quant(input)-
x = self.conv(x)-
x = self.bn(x)-
x = self.relu(x)-
return x-
def set_qconfig(self):-
self.qconfig = default_qat_8bit_fake_quant_qconfig-
data = torch.rand(1, 3, 28, 28)-
net = Net()-
set_march(“bayes”)-
net.set_qconfig()-
qat_net = prepare_qat_fx(net)-
qat_net(data)-
quantized_net = convert_fx(qat_net)-
traced = quantized_net-
print(“Before centered_yuv2rgb”)-
traced.graph.print_tabular()-
# Replace QuantStub nodes with centered_yuv2rgb-
patterns = [“quant”]-
for n in traced.graph.nodes:-
if any(n.target == pattern for pattern in patterns):-
with traced.graph.inserting_after(n):-
new_node = traced.graph.call_function(centered_yuv2rgb, (n,), {“swing”: “full”})-
n.replace_all_uses_with(new_node)-
new_node.args = (n,)-
traced.quant.scale.fill_(1.0)-
traced.recompile()-
print(“\nAfter centered_yuv2rgb”)-
traced.graph.print_tabular()-
def compile_quantized_model(quantized_model):-
example_input = torch.ones(size=(1, 3, 28, 28))-
quantized_model(example_input)-
traced_model = torch.jit.trace(quantized_model, example_input)-
horizon.quantization.check_model(quantized_model, example_input, advice=1)-
hbdk_dir = “debug_test/torchvision_resnet/hbdk_model”-
if not os.path.exists(hbdk_dir):-
os.mkdir(hbdk_dir)-
horizon.quantization.compile_model(-
traced_model, [example_input], opt=2, hbm=hbdk_dir + “/model.hbm”-
)-
# 对模型进行静态性能分析-
horizon.quantization.perf_model(-
traced_model,-
[example_input],-
opt=2,-
input_source=[“pyramid”],-
layer_details=True,-
out_dir=hbdk_dir,-
)-
if 1:-
compile_quantized_model(traced.cpu())
用的就是你们给的例子,但是在1.1.40的docker环境下转hbm失败了。报错就是上面那样