本帖最后由 weiyaowu 于 2020-9-21 17:53 编辑
怎么让padding非1的情况,转化成RKNN模型后运行结果与原始模型一致
padding为3的情况, 差异很大
模型为:conv = nn.Conv2d(3, 24, kernel_size=7, stride=4, padding=3)
对输出的每个结果求均方误差,并求和,得到如下结果:
error conv: tensor(0.0229, grad_fn=<DivBackward0>)
输入大小为7×7的图片(for testing)
rknn模型的输出:
rknn: tensor([[[[-0.0435, 0.0381],
[-0.1427, -0.1824]],
[[-0.2231, 0.1610],
[-0.3589, -0.2549]],
[[ 0.0197, 0.2146],
[ 0.0153, 0.1089]],
[[ 0.0610, 0.0942],
[-0.0364, -0.2529]],
[[ 0.2147, 0.3000],
[ 0.3354, 0.0844]],
[[-0.3381, -0.3726],
[-0.4695, -0.5254]],
[[-0.2036, 0.1350],
[-0.1039, 0.2139]],
[[ 0.4924, 0.3396],
[ 0.2544, 0.2715]],
[[ 0.1801, 0.3538],
[ 0.2494, 0.2211]],
[[ 0.0375, 0.1599],
[ 0.2384, -0.0342]],
[[-0.1003, 0.0793],
[-0.0383, 0.0350]],
[[ 0.0131, 0.0291],
[-0.1832, -0.1711]],
[[-0.0696, -0.1406],
[ 0.1866, 0.2043]],
[[ 0.5425, 0.3594],
[ 0.3469, 0.3213]],
原始模型输出:
ori: tensor([[[[-0.2067, -0.0678],
[-0.2290, -0.5431]],
[[-0.5568, -0.2483],
[-0.5607, -0.5167]],
[[-0.1513, 0.3004],
[-0.0080, 0.1863]],
[[ 0.0307, -0.0954],
[-0.1113, -0.3946]],
[[ 0.3539, 0.4045],
[ 0.2531, -0.0693]],
[[-0.3760, -0.4564],
[-0.6494, -0.6431]],
[[-0.1356, 0.1528],
[-0.1594, 0.2709]],
[[ 0.3504, 0.3073],
[ 0.0511, 0.4266]],
[[ 0.2230, 0.6711],
[ 0.2688, 0.5008]],
[[ 0.1132, 0.2968],
[ 0.1319, -0.0510]],
[[-0.2679, -0.0534],
[-0.2470, -0.1034]],
[[ 0.0898, -0.0829],
[-0.2416, -0.1357]],
[[ 0.1727, -0.1298],
[ 0.0939, -0.0803]],
[[ 0.6158, 0.4063],
[ 0.3085, 0.2521]],
[[-0.2076, -0.0540],
[-0.6225, -0.0025]],
[[-0.1226, -0.1383],
[-0.2372, -0.2738]],
padding为1的情况,差异很小
模型为:
conv = nn.Conv2d(3, 24, kernel_size=7, stride=1, padding=1)
对输出的每个结果求均方误差,并求和,得到如下结果:
error conv: tensor(1.0450e-07, grad_fn=<DivBackward0>)
rknn模型的输出:
rknn: tensor([[[[-0.2781, -0.2886, 0.0007],
[-0.1164, -0.3240, -0.1401],
[-0.3733, -0.3120, -0.2385]],
[[-0.1428, -0.5063, -0.3162],
[-0.0798, -0.3521, -0.3206],
[ 0.2048, -0.0817, -0.0911]],
[[ 0.2117, 0.0552, -0.2227],
[-0.3069, -0.4011, -0.5103],
[-0.1105, -0.3206, -0.2103]],
[[ 0.6572, 0.4602, 0.3538],
[ 0.6509, 0.5454, 0.5151],
[ 0.4919, 0.5308, 0.5996]],
[[ 0.1541, 0.2432, 0.2408],
[ 0.1591, 0.2455, 0.0314],
[-0.0367, -0.1293, -0.1676]],
[[-0.2091, -0.3601, -0.3840],
[-0.0414, -0.2581, -0.2542],
[ 0.0132, -0.0882, -0.2583]],
[[ 0.1332, 0.2003, 0.1907],
[ 0.2734, 0.2524, 0.0765],
[ 0.4480, 0.5703, 0.3569]],
[[ 0.1080, -0.2629, -0.3450],
[-0.0476, -0.3416, -0.2112],
[ 0.0663, -0.0280, -0.0485]],
[[ 0.0297, -0.1058, 0.0953],
[ 0.0276, -0.3767, 0.1707],
[ 0.0079, -0.1234, 0.1416]],
[[-0.0445, 0.0433, -0.0571],
[-0.1063, -0.0553, -0.1445],
[-0.1181, -0.3228, -0.3196]],
原始模型输出:
ori: tensor([[[[-0.2785, -0.2887, 0.0008],
[-0.1165, -0.3244, -0.1402],
[-0.3737, -0.3122, -0.2387]],
[[-0.1430, -0.5069, -0.3163],
[-0.0798, -0.3524, -0.3208],
[ 0.2051, -0.0818, -0.0911]],
[[ 0.2118, 0.0551, -0.2228],
[-0.3070, -0.4012, -0.5106],
[-0.1106, -0.3208, -0.2105]],
[[ 0.6575, 0.4604, 0.3538],
[ 0.6511, 0.5460, 0.5157],
[ 0.4924, 0.5314, 0.5999]],
[[ 0.1541, 0.2431, 0.2408],
[ 0.1592, 0.2455, 0.0313],
[-0.0368, -0.1293, -0.1678]],
[[-0.2092, -0.3601, -0.3842],
[-0.0413, -0.2584, -0.2543],
[ 0.0131, -0.0882, -0.2586]],
[[ 0.1332, 0.2006, 0.1908],
[ 0.2737, 0.2530, 0.0766],
[ 0.4482, 0.5709, 0.3574]],
[[ 0.1082, -0.2634, -0.3453],
[-0.0477, -0.3419, -0.2114],
[ 0.0664, -0.0279, -0.0485]],
[[ 0.0299, -0.1059, 0.0955],
[ 0.0277, -0.3767, 0.1709],
[ 0.0081, -0.1234, 0.1418]],
[[-0.0447, 0.0431, -0.0573],
[-0.1064, -0.0555, -0.1447],
[-0.1183, -0.3232, -0.3201]],
|