diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-Xxx\346\250\241\345\236\213\346\265\213\350\257\225\346\212\245\345\221\212.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-Xxx\346\250\241\345\236\213\346\265\213\350\257\225\346\212\245\345\221\212.docx" index 3148e9dd51264cdd082c82ba0d63de929a604b27..359ceb910871434efdf08a1b74152e050234a8f6 100644 Binary files "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-Xxx\346\250\241\345\236\213\346\265\213\350\257\225\346\212\245\345\221\212.docx" and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/PyTorch\347\246\273\347\272\277\346\216\250\347\220\206-Xxx\346\250\241\345\236\213\346\265\213\350\257\225\346\212\245\345\221\212.docx" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/\344\274\230\345\214\226transpose\345\210\260\346\234\200\345\220\216\344\270\200\346\240\271\350\275\264\345\201\232softmax\346\200\247\350\203\275\344\275\216\347\232\204\351\227\256\351\242\230.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/\344\274\230\345\214\226transpose\345\210\260\346\234\200\345\220\216\344\270\200\346\240\271\350\275\264\345\201\232softmax\346\200\247\350\203\275\344\275\216\347\232\204\351\227\256\351\242\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..233c5952ff6fb746609cd5614276bf00b40d1750 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/\344\274\230\345\214\226transpose\345\210\260\346\234\200\345\220\216\344\270\200\346\240\271\350\275\264\345\201\232softmax\346\200\247\350\203\275\344\275\216\347\232\204\351\227\256\351\242\230.md" @@ -0,0 +1,26 @@ +``` +import sys +import onnx + +if __name__ == '__main__': + model = onnx.load(sys.argv[1]) + graph = model.graph + node = graph.node + softmax_node_index = [] + del_group = [] + for i in range(len(node)): + if node[i].op_type == 'Softmax': + del_group.append((node[i-1], node[i], node[i+1], i)) + for g in del_group: + new_input = g[0].input + new_output = g[2].output + new_name = g[1].name + new_index = g[3] + new_node = onnx.helper.make_node("Softmax", new_input, new_output, new_name, axis=1) + for n in g[:-1]: + graph.node.remove(n) + graph.node.insert(new_index, new_node) + onnx.save(model, sys.argv[2]) +``` +python3 fix_softmax_transpose.py ./wideresnet_dybs.onnx ./wideresnet_dybs_fix.onnx +导出onnx时如果softmax不是在最后一根轴上计算时会通过transpose转换到最后一根轴计算,然而softmax在最后一根轴上计算时性能低,故修改onnx使softmax在原轴上计算。 \ No newline at end of file