{"id":12614,"date":"2023-02-01T21:02:34","date_gmt":"2023-02-01T13:02:34","guid":{"rendered":"http:\/\/139.9.1.231\/?p=12614"},"modified":"2023-02-01T21:02:35","modified_gmt":"2023-02-01T13:02:35","slug":"moxingbushu2","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2023\/02\/01\/moxingbushu2\/","title":{"rendered":"\u6a21\u578b\u90e8\u7f72\uff1a\u89e3\u51b3\u6a21\u578b\u90e8\u7f72\u4e2d\u7684\u96be\u9898"},"content":{"rendered":"\n<p><strong>\u8f6c\uff1a<a href=\"https:\/\/zhuanlan.zhihu.com\/p\/479290520\" target=\"_blank\" rel=\"noreferrer noopener\">\u6a21\u578b\u90e8\u7f72\u5165\u95e8\u6559\u7a0b\uff08\u4e8c\uff09\uff1a\u89e3\u51b3\u6a21\u578b\u90e8\u7f72\u4e2d\u7684\u96be\u9898<\/a><\/strong><\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background\">\u6211\u4eec\u90e8\u7f72\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u8d85\u5206\u8fa8\u7387\u6a21\u578b\uff0c\u4e00\u5207\u90fd\u5341\u5206\u987a\u5229\u3002\u4f46\u662f\uff0c\u4e0a\u4e00\u4e2a\u6a21\u578b\u8fd8\u6709\u4e00\u4e9b\u7f3a\u9677\u2014\u2014\u56fe\u7247\u7684\u653e\u5927\u500d\u6570\u56fa\u5b9a\u662f 4\uff0c\u6211\u4eec\u65e0\u6cd5\u8ba9\u56fe\u7247\u653e\u5927\u4efb\u610f\u7684\u500d\u6570\u3002\u73b0\u5728\uff0c\u6211\u4eec\u6765\u5c1d\u8bd5\u90e8\u7f72\u4e00\u4e2a\u652f\u6301\u52a8\u6001\u653e\u5927\u500d\u6570\u7684\u6a21\u578b\uff0c\u4f53\u9a8c\u4e00\u4e0b\u5728\u6a21\u578b\u90e8\u7f72\u4e2d\u53ef\u80fd\u4f1a\u78b0\u5230\u7684\u56f0\u96be\u3002<\/p>\n\n\n\n<h2 id=\"h_479290520_0\">\u6a21\u578b\u90e8\u7f72\u4e2d\u5e38\u89c1\u7684\u96be\u9898<\/h2>\n\n\n\n<p>\u5728\u4e4b\u524d\u7684\u5b66\u4e60\u4e2d\uff0c\u6211\u4eec\u5728\u6a21\u578b\u90e8\u7f72\u4e0a\u987a\u98ce\u987a\u6c34\uff0c\u6ca1\u6709\u78b0\u5230\u4efb\u4f55\u95ee\u9898\u3002\u8fd9\u662f\u56e0\u4e3a SRCNN \u6a21\u578b\u53ea\u5305\u542b\u51e0\u4e2a\u7b80\u5355\u7684\u7b97\u5b50\uff0c\u800c\u8fd9\u4e9b\u5377\u79ef\u3001\u63d2\u503c\u7b97\u5b50\u5df2\u7ecf\u5728\u5404\u4e2a\u4e2d\u95f4\u8868\u793a\u548c\u63a8\u7406\u5f15\u64ce\u4e0a\u5f97\u5230\u4e86\u5b8c\u7f8e\u652f\u6301\u3002\u5982\u679c\u6a21\u578b\u7684\u64cd\u4f5c\u7a0d\u5fae\u590d\u6742\u4e00\u70b9\uff0c\u6211\u4eec\u53ef\u80fd\u5c31\u8981\u4e3a\u517c\u5bb9\u6a21\u578b\u800c\u4ed8\u51fa\u5927\u91cf\u7684\u529f\u592b\u4e86\u3002\u5b9e\u9645\u4e0a\uff0c\u6a21\u578b\u90e8\u7f72\u65f6\u4e00\u822c\u4f1a\u78b0\u5230\u4ee5\u4e0b\u51e0\u7c7b\u56f0\u96be\uff1a<\/p>\n\n\n\n<ul><li>\u6a21\u578b\u7684\u52a8\u6001\u5316\u3002\u51fa\u4e8e\u6027\u80fd\u7684\u8003\u8651\uff0c\u5404\u63a8\u7406\u6846\u67b6\u90fd\u9ed8\u8ba4\u6a21\u578b\u7684\u8f93\u5165\u5f62\u72b6\u3001\u8f93\u51fa\u5f62\u72b6\u3001\u7ed3\u6784\u662f\u9759\u6001\u7684\u3002\u800c\u4e3a\u4e86\u8ba9\u6a21\u578b\u7684\u6cdb\u7528\u6027\u66f4\u5f3a\uff0c\u90e8\u7f72\u65f6\u9700\u8981\u5728\u5c3d\u53ef\u80fd\u4e0d\u5f71\u54cd\u539f\u6709\u903b\u8f91\u7684\u524d\u63d0\u4e0b\uff0c\u8ba9\u6a21\u578b\u7684\u8f93\u5165\u8f93\u51fa\u6216\u662f\u7ed3\u6784\u52a8\u6001\u5316\u3002<\/li><li>\u65b0\u7b97\u5b50\u7684\u5b9e\u73b0\u3002\u6df1\u5ea6\u5b66\u4e60\u6280\u672f\u65e5\u65b0\u6708\u5f02\uff0c\u63d0\u51fa\u65b0\u7b97\u5b50\u7684\u901f\u5ea6\u5f80\u5f80\u5feb\u4e8e ONNX \u7ef4\u62a4\u8005\u652f\u6301\u7684\u901f\u5ea6\u3002\u4e3a\u4e86\u90e8\u7f72\u6700\u65b0\u7684\u6a21\u578b\uff0c\u90e8\u7f72\u5de5\u7a0b\u5e08\u5f80\u5f80\u9700\u8981\u81ea\u5df1\u5728 ONNX \u548c\u63a8\u7406\u5f15\u64ce\u4e2d\u652f\u6301\u65b0\u7b97\u5b50\u3002<\/li><li>\u4e2d\u95f4\u8868\u793a\u4e0e\u63a8\u7406\u5f15\u64ce\u7684\u517c\u5bb9\u95ee\u9898\u3002\u7531\u4e8e\u5404\u63a8\u7406\u5f15\u64ce\u7684\u5b9e\u73b0\u4e0d\u540c\uff0c\u5bf9 ONNX \u96be\u4ee5\u5f62\u6210\u7edf\u4e00\u7684\u652f\u6301\u3002\u4e3a\u4e86\u786e\u4fdd\u6a21\u578b\u5728\u4e0d\u540c\u7684\u63a8\u7406\u5f15\u64ce\u4e2d\u6709\u540c\u6837\u7684\u8fd0\u884c\u6548\u679c\uff0c\u90e8\u7f72\u5de5\u7a0b\u5e08\u5f80\u5f80\u5f97\u4e3a\u67d0\u4e2a\u63a8\u7406\u5f15\u64ce\u5b9a\u5236\u6a21\u578b\u4ee3\u7801\uff0c\u8fd9\u4e3a\u6a21\u578b\u90e8\u7f72\u5f15\u5165\u4e86\u8bb8\u591a\u5de5\u4f5c\u91cf\u3002<\/li><\/ul>\n\n\n\n<p>\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u5bf9\u539f\u6765\u7684 SRCNN \u6a21\u578b\u505a\u4e00\u4e9b\u5c0f\u7684\u4fee\u6539\uff0c\u4f53\u9a8c\u4e00\u4e0b\u6a21\u578b\u52a8\u6001\u5316\u5bf9\u6a21\u578b\u90e8\u7f72\u9020\u6210\u7684\u56f0\u96be\uff0c\u5e76\u5b66\u4e60\u89e3\u51b3\u8be5\u95ee\u9898\u7684\u4e00\u79cd\u65b9\u6cd5\u3002<\/p>\n\n\n\n<h3 id=\"h_479290520_1\">\u5b9e\u73b0\u52a8\u6001\u653e\u5927\u7684\u8d85\u5206\u8fa8\u7387\u6a21\u578b<\/h3>\n\n\n\n<p>\u5728\u539f\u6765\u7684 SRCNN \u4e2d\uff0c\u56fe\u7247\u7684\u653e\u5927\u6bd4\u4f8b\u662f\u5199\u6b7b\u5728\u6a21\u578b\u91cc\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class SuperResolutionNet(nn.Module): \n    def __init__(self, upscale_factor): \n        super().__init__() \n        self.upscale_factor = upscale_factor \n        self.img_upsampler = nn.Upsample( \n            scale_factor=self.upscale_factor, \n            mode='bicubic', \n            align_corners=False) \n \n... \n \ndef init_torch_model(): \n    torch_model = SuperResolutionNet(upscale_factor=3) \n <\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u4f7f\u7528 upscale_factor \u6765\u63a7\u5236\u6a21\u578b\u7684\u653e\u5927\u6bd4\u4f8b\u3002\u521d\u59cb\u5316\u6a21\u578b\u7684\u65f6\u5019\uff0c\u6211\u4eec\u9ed8\u8ba4\u4ee4 upscale_factor \u4e3a 3\uff0c\u751f\u6210\u4e86\u4e00\u4e2a\u653e\u5927 3 \u500d\u7684 PyTorch \u6a21\u578b\u3002\u8fd9\u4e2a PyTorch \u6a21\u578b\u6700\u7ec8\u88ab\u8f6c\u6362\u6210\u4e86 ONNX \u683c\u5f0f\u7684\u6a21\u578b\u3002\u5982\u679c\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u653e\u5927 4 \u500d\u7684\u6a21\u578b\uff0c\u9700\u8981\u91cd\u65b0\u751f\u6210\u4e00\u904d\u6a21\u578b\uff0c\u518d\u505a\u4e00\u6b21\u5230 ONNX \u7684\u8f6c\u6362\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\uff0c\u5047\u8bbe\u6211\u4eec\u8981\u505a\u4e00\u4e2a\u8d85\u5206\u8fa8\u7387\u7684\u5e94\u7528\u3002\u6211\u4eec\u7684\u7528\u6237\u5e0c\u671b\u56fe\u7247\u7684\u653e\u5927\u500d\u6570\u80fd\u591f\u81ea\u7531\u8bbe\u7f6e\u3002\u800c\u6211\u4eec\u4ea4\u7ed9\u7528\u6237\u7684\uff0c\u53ea\u6709\u4e00\u4e2a .onnx \u6587\u4ef6\u548c\u8fd0\u884c\u8d85\u5206\u8fa8\u7387\u6a21\u578b\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u6211\u4eec\u5728\u4e0d\u4fee\u6539 .onnx \u6587\u4ef6\u7684\u524d\u63d0\u4e0b\u6539\u53d8\u653e\u5927\u500d\u6570\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\uff0c\u6211\u4eec\u5fc5\u987b\u4fee\u6539\u539f\u6765\u7684\u6a21\u578b\uff0c\u4ee4\u6a21\u578b\u7684\u653e\u5927\u500d\u6570\u53d8\u6210\u63a8\u7406\u65f6\u7684\u8f93\u5165\u3002\u5728\u4e0a\u4e00\u7bc7\u6587\u7ae0\u4e2d\u7684 Python \u811a\u672c\u7684\u57fa\u7840\u4e0a\uff0c\u6211\u4eec\u505a\u4e00\u4e9b\u4fee\u6539\uff0c\u5f97\u5230\u8fd9\u6837\u7684\u811a\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import torch \nfrom torch import nn \nfrom torch.nn.functional import interpolate \nimport torch.onnx \nimport cv2 \nimport numpy as np \n \n \nclass SuperResolutionNet(nn.Module): \n \n    def __init__(self): \n        super().__init__() \n \n        self.conv1 = nn.Conv2d(3, 64, kernel_size=9, padding=4) \n        self.conv2 = nn.Conv2d(64, 32, kernel_size=1, padding=0) \n        self.conv3 = nn.Conv2d(32, 3, kernel_size=5, padding=2) \n \n        self.relu = nn.ReLU() \n \n    def forward(self, x, upscale_factor): \n        x = interpolate(x, \n                        scale_factor=upscale_factor, \n                        mode='bicubic', \n                        align_corners=False) \n        out = self.relu(self.conv1(x)) \n        out = self.relu(self.conv2(out)) \n        out = self.conv3(out) \n        return out \n \n \ndef init_torch_model(): \n    torch_model = SuperResolutionNet() \n \n    state_dict = torch.load('srcnn.pth')&#91;'state_dict'] \n \n    <em># Adapt the checkpoint <\/em>\n    for old_key in list(state_dict.keys()): \n        new_key = '.'.join(old_key.split('.')&#91;1:]) \n        state_dict&#91;new_key] = state_dict.pop(old_key) \n \n    torch_model.load_state_dict(state_dict) \n    torch_model.eval() \n    return torch_model \n \n \nmodel = init_torch_model() \n \ninput_img = cv2.imread('face.png').astype(np.float32) \n \n<em># HWC to NCHW <\/em>\ninput_img = np.transpose(input_img, &#91;2, 0, 1]) \ninput_img = np.expand_dims(input_img, 0) \n \n<em># Inference <\/em>\ntorch_output = model(torch.from_numpy(input_img), 3).detach().numpy() \n \n<em># NCHW to HWC <\/em>\ntorch_output = np.squeeze(torch_output, 0) \ntorch_output = np.clip(torch_output, 0, 255) \ntorch_output = np.transpose(torch_output, &#91;1, 2, 0]).astype(np.uint8) \n \n<em># Show image <\/em>\ncv2.imwrite(\"face_torch_2.png\", torch_output) <\/code><\/pre>\n\n\n\n<p>SuperResolutionNet \u672a\u4fee\u6539\u4e4b\u524d\uff0cnn.Upsample \u5728\u521d\u59cb\u5316\u9636\u6bb5\u56fa\u5316\u4e86\u653e\u5927\u500d\u6570\uff0c\u800c PyTorch \u7684 interpolate \u63d2\u503c\u7b97\u5b50\u53ef\u4ee5\u5728\u8fd0\u884c\u9636\u6bb5\u9009\u62e9\u653e\u5927\u500d\u6570\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u5728\u65b0\u811a\u672c\u4e2d\u4f7f\u7528 interpolate \u4ee3\u66ff nn.Upsample\uff0c\u4ece\u800c\u8ba9\u6a21\u578b\u652f\u6301\u52a8\u6001\u653e\u5927\u500d\u6570\u7684\u8d85\u5206\u3002 \u5728\u7b2c 55 \u884c\u4f7f\u7528\u6a21\u578b\u63a8\u7406\u65f6\uff0c\u6211\u4eec\u628a\u653e\u5927\u500d\u6570\u8bbe\u7f6e\u4e3a 3\u3002\u6700\u540e\uff0c\u56fe\u7247\u4fdd\u5b58\u5728\u6587\u4ef6 &#8220;face_torch_2.png&#8221; \u4e2d\u3002\u4e00\u5207\u6b63\u5e38\u7684\u8bdd\uff0c&#8221;face_torch_2.png&#8221; \u548c &#8220;face_torch.png&#8221; \u7684\u5185\u5bb9\u4e00\u6a21\u4e00\u6837\u3002<\/p>\n\n\n\n<p>\u901a\u8fc7\u7b80\u5355\u7684\u4fee\u6539\uff0cPyTorch \u6a21\u578b\u5df2\u7ecf\u652f\u6301\u4e86\u52a8\u6001\u5206\u8fa8\u7387\u3002\u73b0\u5728\u6211\u4eec\u6765\u5c1d\u8bd5\u4e00\u4e0b\u5bfc\u51fa\u6a21\u578b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x = torch.randn(1, 3, 256, 256) \n \nwith torch.no_grad(): \n    torch.onnx.export(model, (x, 3), \n                      \"srcnn2.onnx\", \n                      opset_version=11, \n                      input_names=&#91;'input', 'factor'], \n                      output_names=&#91;'output']) \n <\/code><\/pre>\n\n\n\n<p>\u8fd0\u884c\u8fd9\u4e9b\u811a\u672c\u65f6\uff0c\u4f1a\u62a5\u4e00\u957f\u4e32\u9519\u8bef\u3002\u6ca1\u529e\u6cd5\uff0c\u6211\u4eec\u78b0\u5230\u4e86\u6a21\u578b\u90e8\u7f72\u4e2d\u7684\u517c\u5bb9\u6027\u95ee\u9898\u3002<\/p>\n\n\n\n<h2 id=\"h_479290520_2\">\u89e3\u51b3\u65b9\u6cd5\uff1a\u81ea\u5b9a\u4e49\u7b97\u5b50<\/h2>\n\n\n\n<p>\u76f4\u63a5\u4f7f\u7528 PyTorch \u6a21\u578b\u7684\u8bdd\uff0c\u6211\u4eec\u4fee\u6539\u51e0\u884c\u4ee3\u7801\u5c31\u80fd\u5b9e\u73b0\u6a21\u578b\u8f93\u5165\u7684\u52a8\u6001\u5316\u3002\u4f46\u5728\u6a21\u578b\u90e8\u7f72\u4e2d\uff0c\u6211\u4eec\u8981\u82b1\u6570\u500d\u7684\u65f6\u95f4\u6765\u8bbe\u6cd5\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u3002\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u987a\u7740\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\uff0c\u4f53\u9a8c\u4e00\u4e0b\u6a21\u578b\u90e8\u7f72\u7684\u56f0\u96be\uff0c\u5e76\u5b66\u4e60\u4f7f\u7528\u81ea\u5b9a\u4e49\u7b97\u5b50\u7684\u65b9\u5f0f\uff0c\u89e3\u51b3\u8d85\u5206\u8fa8\u7387\u6a21\u578b\u7684\u52a8\u6001\u5316\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u521a\u521a\u7684\u62a5\u9519\u662f\u56e0\u4e3a<strong> PyTorch \u6a21\u578b\u5728\u5bfc\u51fa\u5230 ONNX \u6a21\u578b\u65f6\uff0c\u6a21\u578b\u7684\u8f93\u5165\u53c2\u6570\u7684\u7c7b\u578b\u5fc5\u987b\u5168\u90e8\u662f torch.Tensor\u3002\u800c\u5b9e\u9645\u4e0a\u6211\u4eec\u4f20\u5165\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570&#8221; 3 &#8220;\u662f\u4e00\u4e2a\u6574\u5f62\u53d8\u91cf\u3002\u8fd9\u4e0d\u7b26\u5408 PyTorch \u8f6c ONNX \u7684\u89c4\u5b9a\u3002\u6211\u4eec\u5fc5\u987b\u8981\u4fee\u6539\u4e00\u4e0b\u539f\u6765\u7684\u6a21\u578b\u7684\u8f93\u5165\u3002\u4e3a\u4e86\u4fdd\u8bc1\u8f93\u5165\u7684\u6240\u6709\u53c2\u6570\u90fd\u662f torch.Tensor \u7c7b\u578b\u7684\uff0c\u6211\u4eec\u505a\u5982\u4e0b\u4fee\u6539<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>... \n \nclass SuperResolutionNet(nn.Module): \n \n    def forward(self, x, upscale_factor): \n        x = interpolate(x, \n                        scale_factor=upscale_factor.item(), \n                        mode='bicubic', \n                        align_corners=False) \n \n... \n \n<em># Inference <\/em>\n<em># Note that the second input is torch.tensor(3) <\/em>\ntorch_output = model(torch.from_numpy(input_img), torch.tensor(3)).detach().numpy() \n \n... \n \nwith torch.no_grad(): \n    torch.onnx.export(model, (x, torch.tensor(3)), \n                      \"srcnn2.onnx\", \n                      opset_version=11, \n                      input_names=&#91;'input', 'factor'], \n                      output_names=&#91;'output']) <\/code><\/pre>\n\n\n\n<p>\u7531\u4e8e PyTorch \u4e2d interpolate \u7684 scale_factor \u53c2\u6570\u5fc5\u987b\u662f\u4e00\u4e2a\u6570\u503c\uff0c\u6211\u4eec\u4f7f\u7528 torch.Tensor.item() \u6765\u628a\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\u7684 torch.Tensor \u8f6c\u6362\u6210\u6570\u503c\u3002\u4e4b\u540e\uff0c\u5728\u6a21\u578b\u63a8\u7406\u65f6\uff0c\u6211\u4eec\u4f7f\u7528 torch.tensor(3) \u4ee3\u66ff 3\uff0c\u4ee5\u4f7f\u5f97\u6211\u4eec\u7684\u6240\u6709\u8f93\u5165\u90fd\u6ee1\u8db3\u8981\u6c42\u3002\u73b0\u5728\u8fd0\u884c\u811a\u672c\u7684\u8bdd\uff0c\u65e0\u8bba\u662f\u76f4\u63a5\u8fd0\u884c\u6a21\u578b\uff0c\u8fd8\u662f\u5bfc\u51fa ONNX \u6a21\u578b\uff0c\u90fd\u4e0d\u4f1a\u62a5\u9519\u4e86\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\uff0c\u5bfc\u51fa ONNX \u65f6\u5374\u62a5\u4e86\u4e00\u6761 TraceWarning \u7684\u8b66\u544a\u3002\u8fd9\u6761\u8b66\u544a\u8bf4\u6709\u4e00\u4e9b\u91cf\u53ef\u80fd\u4f1a\u8ffd\u8e2a\u5931\u8d25\u3002\u8fd9\u662f\u600e\u4e48\u56de\u4e8b\u5462\uff1f\u8ba9\u6211\u4eec\u628a\u751f\u6210\u7684<strong> srcnn2.onnx \u7528 Netron <\/strong>\u53ef\u89c6\u5316\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-15.png\" alt=\"\" class=\"wp-image-12624\" width=\"157\" height=\"158\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-15.png 295w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-15-150x150.png 150w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-15-120x120.png 120w\" sizes=\"(max-width: 157px) 100vw, 157px\" \/><\/figure><\/div>\n\n\n\n<p>\u53ef\u4ee5\u53d1\u73b0\uff0c\u867d\u7136\u6211\u4eec\u628a\u6a21\u578b\u63a8\u7406\u7684\u8f93\u5165\u8bbe\u7f6e\u4e3a\u4e86\u4e24\u4e2a\uff0c\u4f46 ONNX \u6a21\u578b\u8fd8\u662f\u957f\u5f97\u548c\u539f\u6765\u4e00\u6a21\u4e00\u6837\uff0c\u53ea\u6709\u4e00\u4e2a\u53eb &#8221; input &#8221; \u7684\u8f93\u5165\u3002<strong>\u8fd9\u662f\u7531\u4e8e\u6211\u4eec\u4f7f\u7528\u4e86 torch.Tensor.item() \u628a\u6570\u636e\u4ece Tensor \u91cc\u53d6\u51fa\u6765\uff0c\u800c\u5bfc\u51fa ONNX \u6a21\u578b\u65f6\u8fd9\u4e2a\u64cd\u4f5c\u662f\u65e0\u6cd5\u88ab\u8bb0\u5f55\u7684\uff0c\u53ea\u597d\u62a5\u4e86\u4e00\u6761 TraceWarning\u3002<\/strong>\u8fd9\u5bfc\u81f4 interpolate \u63d2\u503c\u51fd\u6570\u7684\u653e\u5927\u500d\u6570\u8fd8\u662f\u88ab\u8bbe\u7f6e\u6210\u4e86&#8221; 3 &#8220;\u8fd9\u4e2a\u56fa\u5b9a\u503c\uff0c\u6211\u4eec\u5bfc\u51fa\u7684&#8221; srcnn2.onnx &#8220;\u548c\u6700\u5f00\u59cb\u7684&#8221; srcnn.onnx &#8220;\u5b8c\u5168\u76f8\u540c\u3002<\/p>\n\n\n\n<p>\u76f4\u63a5\u4fee\u6539\u539f\u6765\u7684\u6a21\u578b\u4f3c\u4e4e\u884c\u4e0d\u901a\uff0c\u6211\u4eec\u5f97\u4ece PyTorch \u8f6c ONNX \u7684\u539f\u7406\u5165\u624b\uff0c\u5f3a\u884c\u4ee4 ONNX \u6a21\u578b\u660e\u767d\u6211\u4eec\u7684\u60f3\u6cd5\u4e86\u3002<\/p>\n\n\n\n<p>\u4ed4\u7ec6\u89c2\u5bdf Netron \u4e0a\u53ef\u89c6\u5316\u51fa\u7684 ONNX \u6a21\u578b\uff0c\u53ef\u4ee5\u53d1\u73b0\u5728 PyTorch \u4e2d\u65e0\u8bba\u662f\u4f7f\u7528\u6700\u65e9\u7684 nn.Upsample\uff0c\u8fd8\u662f\u540e\u6765\u7684 interpolate\uff0cPyTorch \u91cc\u7684\u63d2\u503c\u64cd\u4f5c\u6700\u540e\u90fd\u4f1a\u8f6c\u6362\u6210 ONNX \u5b9a\u4e49\u7684 Resize \u64cd\u4f5c\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6240\u8c13 PyTorch \u8f6c ONNX\uff0c\u5b9e\u9645\u4e0a\u5c31\u662f\u628a\u6bcf\u4e2a PyTorch \u7684\u64cd\u4f5c\u6620\u5c04\u6210\u4e86 ONNX \u5b9a\u4e49\u7684\u7b97\u5b50\u3002<\/p>\n\n\n\n<p>\u70b9\u51fb\u8be5\u7b97\u5b50\uff0c\u53ef\u4ee5\u770b\u5230\u5b83\u7684\u8be6\u7ec6\u53c2\u6570\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"857\" height=\"1024\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-16-857x1024.png\" alt=\"\" class=\"wp-image-12630\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-16-857x1024.png 857w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-16-251x300.png 251w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-16-768x917.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-16.png 935w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><\/figure><\/div>\n\n\n\n<p>\u5176\u4e2d\uff0c\u5c55\u5f00 scales\uff0c\u53ef\u4ee5\u770b\u5230 scales \u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 4 \u7684\u4e00\u7ef4\u5f20\u91cf\uff0c\u5176\u5185\u5bb9\u4e3a [1, 1, 3, 3], \u8868\u793a Resize \u64cd\u4f5c\u6bcf\u4e00\u4e2a\u7ef4\u5ea6\u7684\u7f29\u653e\u7cfb\u6570\uff1b\u5176\u7c7b\u578b\u4e3a Initializer\uff0c\u8868\u793a\u8fd9\u4e2a\u503c\u662f\u6839\u636e\u5e38\u91cf\u76f4\u63a5\u521d\u59cb\u5316\u51fa\u6765\u7684\u3002\u5982\u679c\u6211\u4eec\u80fd\u591f\u81ea\u5df1\u751f\u6210\u4e00\u4e2a ONNX \u7684 Resize \u7b97\u5b50\uff0c\u8ba9 scales \u6210\u4e3a\u4e00\u4e2a\u53ef\u53d8\u91cf\u800c\u4e0d\u662f\u5e38\u91cf\uff0c\u5c31\u50cf\u5b83\u4e0a\u9762\u7684 X \u4e00\u6837\uff0c\u90a3\u8fd9\u4e2a\u8d85\u5206\u8fa8\u7387\u6a21\u578b\u5c31\u80fd\u52a8\u6001\u7f29\u653e\u4e86\u3002<\/p>\n\n\n\n<p>\u73b0\u6709\u5b9e\u73b0\u63d2\u503c\u7684 PyTorch \u7b97\u5b50\u6709\u4e00\u5957\u89c4\u5b9a\u597d\u7684\u6620\u5c04\u5230 ONNX Resize \u7b97\u5b50\u7684\u65b9\u6cd5\uff0c\u8fd9\u4e9b\u6620\u5c04\u51fa\u7684 Resize \u7b97\u5b50\u7684 scales \u53ea\u80fd\u662f\u5e38\u91cf\uff0c\u65e0\u6cd5\u6ee1\u8db3\u6211\u4eec\u7684\u9700\u6c42\u3002\u6211\u4eec\u5f97\u81ea\u5df1\u5b9a\u4e49\u4e00\u4e2a\u5b9e\u73b0\u63d2\u503c\u7684 PyTorch \u7b97\u5b50\uff0c\u7136\u540e\u8ba9\u5b83\u6620\u5c04\u5230\u4e00\u4e2a\u6211\u4eec\u671f\u671b\u7684 ONNX Resize \u7b97\u5b50\u4e0a\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u7684\u811a\u672c\u5b9a\u4e49\u4e86\u4e00\u4e2a PyTorch \u63d2\u503c\u7b97\u5b50\uff0c\u5e76\u5728\u6a21\u578b\u91cc\u4f7f\u7528\u4e86\u5b83\u3002\u6211\u4eec\u5148\u901a\u8fc7\u8fd0\u884c\u6a21\u578b\u6765\u9a8c\u8bc1\u8be5\u7b97\u5b50\u7684\u6b63\u786e\u6027\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import torch \nfrom torch import nn \nfrom torch.nn.functional import interpolate \nimport torch.onnx \nimport cv2 \nimport numpy as np \n \n \nclass NewInterpolate(torch.autograd.Function): \n \n    @staticmethod \n    def symbolic(g, input, scales): \n        return g.op(\"Resize\", \n                    input, \n                    g.op(\"Constant\", \n                         value_t=torch.tensor(&#91;], dtype=torch.float32)), \n                    scales, \n                    coordinate_transformation_mode_s=\"pytorch_half_pixel\", \n                    cubic_coeff_a_f=-0.75, \n                    mode_s='cubic', \n                    nearest_mode_s=\"floor\") \n \n    @staticmethod \n    def forward(ctx, input, scales): \n        scales = scales.tolist()&#91;-2:] \n        return interpolate(input, \n                           scale_factor=scales, \n                           mode='bicubic', \n                           align_corners=False) \n \n \nclass StrangeSuperResolutionNet(nn.Module): \n \n    def __init__(self): \n        super().__init__() \n \n        self.conv1 = nn.Conv2d(3, 64, kernel_size=9, padding=4) \n        self.conv2 = nn.Conv2d(64, 32, kernel_size=1, padding=0) \n        self.conv3 = nn.Conv2d(32, 3, kernel_size=5, padding=2) \n \n        self.relu = nn.ReLU() \n \n    def forward(self, x, upscale_factor): \n        x = NewInterpolate.apply(x, upscale_factor) \n        out = self.relu(self.conv1(x)) \n        out = self.relu(self.conv2(out)) \n        out = self.conv3(out) \n        return out \n \n \ndef init_torch_model(): \n    torch_model = StrangeSuperResolutionNet() \n \n    state_dict = torch.load('srcnn.pth')&#91;'state_dict'] \n \n    <em># Adapt the checkpoint <\/em>\n    for old_key in list(state_dict.keys()): \n        new_key = '.'.join(old_key.split('.')&#91;1:]) \n        state_dict&#91;new_key] = state_dict.pop(old_key) \n \n    torch_model.load_state_dict(state_dict) \n    torch_model.eval() \n    return torch_model \n \n \nmodel = init_torch_model() \nfactor = torch.tensor(&#91;1, 1, 3, 3], dtype=torch.float) \n \ninput_img = cv2.imread('face.png').astype(np.float32) \n \n<em># HWC to NCHW <\/em>\ninput_img = np.transpose(input_img, &#91;2, 0, 1]) \ninput_img = np.expand_dims(input_img, 0) \n \n<em># Inference <\/em>\ntorch_output = model(torch.from_numpy(input_img), factor).detach().numpy() \n \n<em># NCHW to HWC <\/em>\ntorch_output = np.squeeze(torch_output, 0) \ntorch_output = np.clip(torch_output, 0, 255) \ntorch_output = np.transpose(torch_output, &#91;1, 2, 0]).astype(np.uint8) \n \n<em># Show image <\/em>\ncv2.imwrite(\"face_torch_3.png\", torch_output) <\/code><\/pre>\n\n\n\n<p>\u6a21\u578b\u8fd0\u884c\u6b63\u5e38\u7684\u8bdd\uff0c\u4e00\u5e45\u653e\u59273\u500d\u7684\u8d85\u5206\u8fa8\u7387\u56fe\u7247\u4f1a\u4fdd\u5b58\u5728&#8221;face_torch_3.png&#8221;\u4e2d\uff0c\u5176\u5185\u5bb9\u548c&#8221;face_torch.png&#8221;\u5b8c\u5168\u76f8\u540c\u3002<\/p>\n\n\n\n<p>\u5728\u521a\u521a\u90a3\u4e2a\u811a\u672c\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49 PyTorch \u63d2\u503c\u7b97\u5b50\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class NewInterpolate(torch.autograd.Function): \n \n    @staticmethod \n    def symbolic(g, input, scales): \n        return g.op(\"Resize\", \n                    input, \n                    g.op(\"Constant\", \n                         value_t=torch.tensor(&#91;], dtype=torch.float32)), \n                    scales, \n                    coordinate_transformation_mode_s=\"pytorch_half_pixel\", \n                    cubic_coeff_a_f=-0.75, \n                    mode_s='cubic', \n                    nearest_mode_s=\"floor\") \n \n    @staticmethod \n    def forward(ctx, input, scales): \n        scales = scales.tolist()&#91;-2:] \n        return interpolate(input, \n                           scale_factor=scales, \n                           mode='bicubic', \n                           align_corners=False) <\/code><\/pre>\n\n\n\n<p>\u5728\u5177\u4f53\u4ecb\u7ecd\u8fd9\u4e2a\u7b97\u5b50\u7684\u5b9e\u73b0\u524d\uff0c\u8ba9\u6211\u4eec\u5148\u7406\u6e05\u4e00\u4e0b\u601d\u8def\u3002\u6211\u4eec\u5e0c\u671b\u65b0\u7684\u63d2\u503c\u7b97\u5b50\u6709\u4e24\u4e2a\u8f93\u5165\uff0c\u4e00\u4e2a\u662f\u88ab\u7528\u4e8e\u64cd\u4f5c\u7684\u56fe\u50cf\uff0c\u4e00\u4e2a\u662f\u56fe\u50cf\u7684\u653e\u7f29\u6bd4\u4f8b\u3002\u524d\u9762\u8bb2\u5230\uff0c\u4e3a\u4e86\u5bf9\u63a5 ONNX \u4e2d Resize \u7b97\u5b50\u7684 scales \u53c2\u6570\uff0c\u8fd9\u4e2a\u653e\u7f29\u6bd4\u4f8b\u662f\u4e00\u4e2a [1, 1, x, x] \u7684\u5f20\u91cf\uff0c\u5176\u4e2d x \u4e3a\u653e\u5927\u500d\u6570\u3002\u5728\u4e4b\u524d\u653e\u59273\u500d\u7684\u6a21\u578b\u4e2d\uff0c\u8fd9\u4e2a\u53c2\u6570\u88ab\u56fa\u5b9a\u6210\u4e86[1, 1, 3, 3]\u3002\u56e0\u6b64\uff0c\u5728\u63d2\u503c\u7b97\u5b50\u4e2d\uff0c\u6211\u4eec\u5e0c\u671b\u6a21\u578b\u7684\u7b2c\u4e8c\u4e2a\u8f93\u5165\u662f\u4e00\u4e2a [1, 1, w, h] \u7684\u5f20\u91cf\uff0c\u5176\u4e2d w \u548c h \u5206\u522b\u662f\u56fe\u7247\u5bbd\u548c\u9ad8\u7684\u653e\u5927\u500d\u6570\u3002<\/p>\n\n\n\n<p>\u641e\u6e05\u695a\u4e86\u63d2\u503c\u7b97\u5b50\u7684\u8f93\u5165\uff0c\u518d\u770b\u4e00\u770b\u7b97\u5b50\u7684\u5177\u4f53\u5b9e\u73b0\u3002\u7b97\u5b50\u7684\u63a8\u7406\u884c\u4e3a\u7531\u7b97\u5b50\u7684 foward \u65b9\u6cd5\u51b3\u5b9a\u3002\u8be5\u65b9\u6cd5\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u5fc5\u987b\u4e3a ctx\uff0c\u540e\u9762\u7684\u53c2\u6570\u4e3a\u7b97\u5b50\u7684\u81ea\u5b9a\u4e49\u8f93\u5165\uff0c\u6211\u4eec\u8bbe\u7f6e\u4e24\u4e2a\u8f93\u5165\uff0c\u5206\u522b\u4e3a\u88ab\u64cd\u4f5c\u7684\u56fe\u50cf\u548c\u653e\u7f29\u6bd4\u4f8b\u3002\u4e3a\u4fdd\u8bc1\u63a8\u7406\u6b63\u786e\uff0c\u9700\u8981\u628a [1, 1, w, h] \u683c\u5f0f\u7684\u8f93\u5165\u5bf9\u63a5\u5230\u539f\u6765\u7684 interpolate \u51fd\u6570\u4e0a\u3002\u6211\u4eec\u7684\u505a\u6cd5\u662f\u622a\u53d6\u8f93\u5165\u5f20\u91cf\u7684\u540e\u4e24\u4e2a\u5143\u7d20\uff0c\u628a\u8fd9\u4e24\u4e2a\u5143\u7d20\u4ee5 list \u7684\u683c\u5f0f\u4f20\u5165 interpolate \u7684 scale_factor \u53c2\u6570\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8981\u51b3\u5b9a\u65b0\u7b97\u5b50\u6620\u5c04\u5230 ONNX \u7b97\u5b50\u7684\u65b9\u6cd5\u3002\u6620\u5c04\u5230 ONNX \u7684\u65b9\u6cd5\u7531\u4e00\u4e2a\u7b97\u5b50\u7684 symbolic \u65b9\u6cd5\u51b3\u5b9a\u3002symbolic \u65b9\u6cd5\u7b2c\u4e00\u4e2a\u53c2\u6570\u5fc5\u987b\u662fg\uff0c\u4e4b\u540e\u7684\u53c2\u6570\u662f\u7b97\u5b50\u7684\u81ea\u5b9a\u4e49\u8f93\u5165\uff0c\u548c forward \u51fd\u6570\u4e00\u6837\u3002ONNX \u7b97\u5b50\u7684\u5177\u4f53\u5b9a\u4e49\u7531\u00a0<strong>g.op<\/strong>\u00a0\u5b9e\u73b0\u3002g.op \u7684\u6bcf\u4e2a\u53c2\u6570\u90fd\u53ef\u4ee5\u6620\u5c04\u5230 ONNX \u4e2d\u7684\u7b97\u5b50\u5c5e\u6027\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"537\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-17-1024x537.png\" alt=\"\" class=\"wp-image-12633\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-17-1024x537.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-17-300x157.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-17-768x403.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-17.png 1072w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u5bf9\u4e8e\u5176\u4ed6\u53c2\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u7167\u7740\u73b0\u5728\u7684&nbsp;<a href=\"https:\/\/github.com\/onnx\/onnx\/blob\/main\/docs\/Operators.md#Resize\" target=\"_blank\" rel=\"noreferrer noopener\">Resize \u7b97\u5b50<\/a>\u586b\u3002\u800c\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6211\u4eec\u73b0\u5728\u5e0c\u671b scales \u53c2\u6570\u662f\u7531\u8f93\u5165\u52a8\u6001\u51b3\u5b9a\u7684\u3002\u56e0\u6b64\uff0c\u5728\u586b\u5165 ONNX \u7684 scales \u65f6\uff0c\u6211\u4eec\u8981\u628a symbolic \u65b9\u6cd5\u7684\u8f93\u5165\u53c2\u6570\u4e2d\u7684 scales \u586b\u5165\u3002<\/p>\n\n\n\n<p>\u63a5\u7740\uff0c\u8ba9\u6211\u4eec\u628a\u65b0\u6a21\u578b\u5bfc\u51fa\u6210 ONNX \u6a21\u578b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x = torch.randn(1, 3, 256, 256) \n \nwith torch.no_grad(): \n    torch.onnx.export(model, (x, factor), \n                      \"srcnn3.onnx\", \n                      opset_version=11, \n                      input_names=&#91;'input', 'factor'], \n                      output_names=&#91;'output']) <\/code><\/pre>\n\n\n\n<p>\u628a\u5bfc\u51fa\u7684 &#8221; srcnn3.onnx &#8221; \u8fdb\u884c\u53ef\u89c6\u5316\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-18.png\" alt=\"\" class=\"wp-image-12634\" width=\"282\" height=\"298\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-18.png 433w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/02\/image-18-284x300.png 284w\" sizes=\"(max-width: 282px) 100vw, 282px\" \/><\/figure><\/div>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u6b63\u5982\u6211\u4eec\u6240\u671f\u671b\u7684\uff0c\u5bfc\u51fa\u7684 ONNX \u6a21\u578b\u6709\u4e86\u4e24\u4e2a\u8f93\u5165\uff01\u7b2c\u4e8c\u4e2a\u8f93\u5165\u8868\u793a\u56fe\u50cf\u7684\u653e\u7f29\u6bd4\u4f8b\u3002<\/p>\n\n\n\n<p>\u4e4b\u524d\u5728\u9a8c\u8bc1 PyTorch \u6a21\u578b\u548c\u5bfc\u51fa ONNX \u6a21\u578b\u65f6\uff0c\u6211\u4eec\u5bbd\u9ad8\u7684\u7f29\u653e\u6bd4\u4f8b\u8bbe\u7f6e\u6210\u4e86 3&#215;3\u3002\u73b0\u5728\uff0c\u5728\u7528 ONNX Runtime \u63a8\u7406\u65f6\uff0c\u6211\u4eec\u5c1d\u8bd5\u4f7f\u7528 4&#215;4 \u7684\u7f29\u653e\u6bd4\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import onnxruntime \n \ninput_factor = np.array(&#91;1, 1, 4, 4], dtype=np.float32) \nort_session = onnxruntime.InferenceSession(\"srcnn3.onnx\") \nort_inputs = {'input': input_img, 'factor': input_factor} \nort_output = ort_session.run(None, ort_inputs)&#91;0] \n \nort_output = np.squeeze(ort_output, 0) \nort_output = np.clip(ort_output, 0, 255) \nort_output = np.transpose(ort_output, &#91;1, 2, 0]).astype(np.uint8) \ncv2.imwrite(\"face_ort_3.png\", ort_output) <\/code><\/pre>\n\n\n\n<p>\u8fd0\u884c\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a\u8fb9\u957f\u653e\u59274\u500d\u7684\u8d85\u5206\u8fa8\u7387\u56fe\u7247 &#8220;face_ort_3.png&#8221;\u3002\u52a8\u6001\u7684\u8d85\u5206\u8fa8\u7387\u6a21\u578b\u751f\u6210\u6210\u529f\u4e86\uff01\u53ea\u8981\u4fee\u6539 input_factor\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u81ea\u7531\u5730\u63a7\u5236\u56fe\u7247\u7684\u7f29\u653e\u6bd4\u4f8b\u3002<\/p>\n\n\n\n<p><strong>\u6211\u4eec\u521a\u521a\u7684\u5de5\u4f5c\uff0c\u5b9e\u9645\u4e0a\u662f\u7ed5\u8fc7 PyTorch \u672c\u8eab\u7684\u9650\u5236\uff0c\u51ed\u7a7a\u201c\u634f\u201d\u51fa\u4e86\u4e00\u4e2a ONNX \u7b97\u5b50\u3002\u4e8b\u5b9e\u4e0a\uff0c\u6211\u4eec\u4e0d\u4ec5\u53ef\u4ee5\u521b\u5efa\u73b0\u6709\u7684 ONNX \u7b97\u5b50\uff0c\u8fd8\u53ef\u4ee5\u5b9a\u4e49\u65b0\u7684 ONNX \u7b97\u5b50\u4ee5\u62d3\u5c55 ONNX \u7684\u8868\u8fbe\u80fd\u529b\u3002\u540e\u7eed\u6559\u7a0b\u4e2d\u6211\u4eec\u5c06\u4ecb\u7ecd\u81ea\u5b9a\u4e49\u65b0 ONNX \u7b97\u5b50\u7684\u65b9\u6cd5\u3002<\/strong><\/p>\n\n\n\n<h3>\u603b\u7ed3\uff1a<\/h3>\n\n\n\n<ul><li>\u6a21\u578b\u90e8\u7f72\u4e2d\u5e38\u89c1\u7684\u51e0\u7c7b\u56f0\u96be\u6709\uff1a\u6a21\u578b\u7684\u52a8\u6001\u5316\uff1b\u65b0\u7b97\u5b50\u7684\u5b9e\u73b0\uff1b\u6846\u67b6\u95f4\u7684\u517c\u5bb9\u3002<\/li><li>PyTorch \u8f6c ONNX\uff0c\u5b9e\u9645\u4e0a\u5c31\u662f\u628a\u6bcf\u4e00\u4e2a\u64cd\u4f5c\u8f6c\u5316\u6210 ONNX \u5b9a\u4e49\u7684\u67d0\u4e00\u4e2a\u7b97\u5b50\u3002\u6bd4\u5982\u5bf9\u4e8e PyTorch \u4e2d\u7684 Upsample \u548c interpolate\uff0c\u5728\u8f6c ONNX \u540e\u6700\u7ec8\u90fd\u4f1a\u6210\u4e3a ONNX \u7684 Resize \u7b97\u5b50\u3002<\/li><li>\u901a\u8fc7\u4fee\u6539\u7ee7\u627f\u81ea torch.autograd.Function \u7684\u7b97\u5b50\u7684 symbolic \u65b9\u6cd5\uff0c\u53ef\u4ee5\u6539\u53d8\u8be5\u7b97\u5b50\u6620\u5c04\u5230 ONNX \u7b97\u5b50\u7684\u884c\u4e3a\u3002<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\uff1a\u6a21\u578b\u90e8\u7f72\u5165\u95e8\u6559\u7a0b\uff08\u4e8c\uff09\uff1a\u89e3\u51b3\u6a21\u578b\u90e8\u7f72\u4e2d\u7684\u96be\u9898 \u6211\u4eec\u90e8\u7f72\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u8d85\u5206\u8fa8\u7387\u6a21\u578b\uff0c\u4e00\u5207\u90fd\u5341\u5206\u987a\u5229\u3002\u4f46\u662f\uff0c\u4e0a\u4e00 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2023\/02\/01\/moxingbushu2\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u6a21\u578b\u90e8\u7f72\uff1a\u89e3\u51b3\u6a21\u578b\u90e8\u7f72\u4e2d\u7684\u96be\u9898<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,26],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/12614"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=12614"}],"version-history":[{"count":21,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/12614\/revisions"}],"predecessor-version":[{"id":12639,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/12614\/revisions\/12639"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=12614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=12614"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=12614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}