{"id":4832,"date":"2022-07-16T19:54:39","date_gmt":"2022-07-16T11:54:39","guid":{"rendered":"http:\/\/139.9.1.231\/?p=4832"},"modified":"2022-07-16T19:54:45","modified_gmt":"2022-07-16T11:54:45","slug":"torch-meshgrid","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/07\/16\/torch-meshgrid\/","title":{"rendered":"torch.meshgrid\uff08\uff09\u51fd\u6570\u89e3\u6790"},"content":{"rendered":"\n<p>   \u6700\u8fd1\u770b\u5230\u5f88\u591a\u8bba\u6587\u91cc\u90fd\u6709\u8fd9\u4e2a\u51fd\u6570\uff08yolov3 \u4ee5\u53ca\u6700\u8fd1\u5927\u706b\u7684swin transformer\uff09\uff0c\u8bb0\u5f55\u4e0b\u51fd\u6570\u7684\u4f7f\u7528\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/pytorch.org\/docs\/stable\/generated\/torch.meshgrid.html\">https:\/\/pytorch.org\/docs\/stable\/generated\/torch.meshgrid.html<\/a><\/p>\n\n\n\n<h3>\u8bf4\u660e\uff1a<\/h3>\n\n\n\n<p>\u3000\u3000<a href=\"https:\/\/pytorch.org\/docs\/master\/generated\/torch.meshgrid.html\" target=\"_blank\" rel=\"noreferrer noopener\">torch.meshgrid()<\/a>\u7684\u529f\u80fd\u662f\u751f\u6210\u7f51\u683c\uff0c\u53ef\u4ee5\u7528\u4e8e\u751f\u6210\u5750\u6807\u3002<\/p>\n\n\n\n<h3>\u51fd\u6570\u8f93\u5165:<\/h3>\n\n\n\n<p>\u3000\u3000\u8f93\u5165\u4e24\u4e2a\u6570\u636e\u7c7b\u578b\u76f8\u540c\u7684\u4e00\u7ef4tensor<\/p>\n\n\n\n<h3>\u51fd\u6570\u8f93\u51fa\uff1a<\/h3>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u8f93\u51fa\u4e24\u4e2atensor\uff08tensor\u884c\u6570\u4e3a\u7b2c\u4e00\u4e2a\u8f93\u5165\u5f20\u91cf\u7684\u5143\u7d20\u4e2a\u6570\uff0c\u5217\u6570\u4e3a\u7b2c\u4e8c\u4e2a\u8f93\u5165\u5f20\u91cf\u7684\u5143\u7d20\u4e2a\u6570\uff09<\/p>\n\n\n\n<h3>\u6ce8\u610f\uff1a<\/h3>\n\n\n\n<p>\u3000\u30001\uff09\u5f53\u4e24\u4e2a\u8f93\u5165tensor\u6570\u636e\u7c7b\u578b\u4e0d\u540c\u6216\u7ef4\u5ea6\u4e0d\u662f\u4e00\u7ef4\u65f6\u4f1a\u62a5\u9519\u3002<\/p>\n\n\n\n<p>\u3000\u30002\uff09\u5176\u4e2d\u7b2c\u4e00\u4e2a\u8f93\u51fa\u5f20\u91cf\u586b\u5145\u7b2c\u4e00\u4e2a\u8f93\u5165\u5f20\u91cf\u4e2d\u7684\u5143\u7d20\uff0c\u5404\u884c\u5143\u7d20\u76f8\u540c\uff1b\u7b2c\u4e8c\u4e2a\u8f93\u51fa\u5f20\u91cf\u586b\u5145\u7b2c\u4e8c\u4e2a\u8f93\u5165\u5f20\u91cf\u4e2d\u7684\u5143\u7d20\u5404\u5217\u5143\u7d20\u76f8\u540c\u3002<\/p>\n\n\n\n<pre id=\"codecell0\" class=\"wp-block-preformatted\">&gt;&gt;&gt; <strong>x<\/strong> <strong>=<\/strong> <strong>torch<\/strong><strong>.<\/strong><strong>tensor<\/strong><strong>([<\/strong>1<strong>,<\/strong> 2<strong>,<\/strong> 3<strong>])<\/strong>\n&gt;&gt;&gt; <strong>y<\/strong> <strong>=<\/strong> <strong>torch<\/strong><strong>.<\/strong><strong>tensor<\/strong><strong>([<\/strong>4<strong>,<\/strong> 5<strong>,<\/strong> 6<strong>])<\/strong>\n\nObserve the element-wise pairings across the grid, (1, 4),\n(1, 5), ..., (3, 6). This is the same thing as the\ncartesian product.\n&gt;&gt;&gt; <strong>grid_x<\/strong><strong>,<\/strong> <strong>grid_y<\/strong> <strong>=<\/strong> <strong>torch<\/strong><strong>.<\/strong><strong>meshgrid<\/strong><strong>(<\/strong><strong>x<\/strong><strong>,<\/strong> <strong>y<\/strong><strong>,<\/strong> <strong>indexing<\/strong><strong>=<\/strong>'ij'<strong>)<\/strong>\n&gt;&gt;&gt; <strong>grid_x<\/strong>\ntensor([[1, 1, 1],\n        [2, 2, 2],\n        [3, 3, 3]])\n&gt;&gt;&gt; <strong>grid_y<\/strong>\ntensor([[4, 5, 6],\n        [4, 5, 6],\n        [4, 5, 6]])<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># \u30101\u3011\r\nimport torch\r\na = torch.tensor(&#91;1, 2, 3, 4])\r\nprint(a)\r\nb = torch.tensor(&#91;4, 5, 6])\r\nprint(b)\r\nx, y = torch.meshgrid(a, b)\r\nprint(x)\r\nprint(y)\r\n \r\n\u7ed3\u679c\u663e\u793a\uff1a\r\ntensor(&#91;1, 2, 3, 4])\r\ntensor(&#91;4, 5, 6])\r\ntensor(&#91;&#91;1, 1, 1],\r\n        &#91;2, 2, 2],\r\n        &#91;3, 3, 3],\r\n        &#91;4, 4, 4]])\r\ntensor(&#91;&#91;4, 5, 6],\r\n        &#91;4, 5, 6],\r\n        &#91;4, 5, 6],\r\n        &#91;4, 5, 6]])\r\n \r\n \r\n \r\n# \u30102\u3011\r\nimport torch\r\na = torch.tensor(&#91;1, 2, 3, 4, 5, 6])\r\nprint(a)\r\nb = torch.tensor(&#91;7, 8, 9, 10])\r\nprint(b)\r\nx, y = torch.meshgrid(a, b)\r\nprint(x)\r\nprint(y)\r\n \r\n\u7ed3\u679c\u663e\u793a\uff1a\r\ntensor(&#91;1, 2, 3, 4, 5, 6])\r\ntensor(&#91; 7,  8,  9, 10])\r\ntensor(&#91;&#91;1, 1, 1, 1],\r\n        &#91;2, 2, 2, 2],\r\n        &#91;3, 3, 3, 3],\r\n        &#91;4, 4, 4, 4],\r\n        &#91;5, 5, 5, 5],\r\n        &#91;6, 6, 6, 6]])\r\ntensor(&#91;&#91; 7,  8,  9, 10],\r\n        &#91; 7,  8,  9, 10],\r\n        &#91; 7,  8,  9, 10],\r\n        &#91; 7,  8,  9, 10],\r\n        &#91; 7,  8,  9, 10],\r\n        &#91; 7,  8,  9, 10]])<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u770b\u5230\u5f88\u591a\u8bba\u6587\u91cc\u90fd\u6709\u8fd9\u4e2a\u51fd\u6570\uff08yolov3 \u4ee5\u53ca\u6700\u8fd1\u5927\u706b\u7684swin transformer\uff09\uff0c\u8bb0\u5f55\u4e0b\u51fd\u6570\u7684\u4f7f &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/07\/16\/torch-meshgrid\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">torch.meshgrid\uff08\uff09\u51fd\u6570\u89e3\u6790<\/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],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/4832"}],"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=4832"}],"version-history":[{"count":7,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/4832\/revisions"}],"predecessor-version":[{"id":4839,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/4832\/revisions\/4839"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=4832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=4832"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=4832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}