{"id":4701,"date":"2021-04-18T20:04:21","date_gmt":"2021-04-18T11:04:21","guid":{"rendered":"https:\/\/denasu.com\/blog\/?p=4701"},"modified":"2022-06-07T23:08:11","modified_gmt":"2022-06-07T14:08:11","slug":"unity%e3%81%a7%e3%83%af%e3%83%bc%e3%83%89%e8%87%aa%e5%8b%95%e7%94%9f%e6%88%90","status":"publish","type":"post","link":"https:\/\/denasu.com\/blog\/2021\/04\/diary4701","title":{"rendered":"Unity\u3067\u30ef\u30fc\u30c9\u81ea\u52d5\u751f\u6210"},"content":{"rendered":"\n<p>\u30a6\u30a7\u30b6\u30bf\u30a44.1\u3067\u306f\u30c7\u30a3\u30fc\u30d7\u30e9\u30fc\u30cb\u30f3\u30b0\u3092\u4f7f\u3063\u305f<a href=\"https:\/\/denasu.com\/blog\/2020\/04\/diary4507\">\u30ef\u30fc\u30c9\u81ea\u52d5\u751f\u6210<\/a>\u3092\u5b9f\u88c5\u3057\u305f\u3002\u3067\u3001Unity\u3067\u4f5c\u3063\u3066\u3044\u308b\u30bf\u30a4\u30d4\u30f3\u30b0\u30bd\u30d5\u30c8\u3067\u306f\u57fa\u672c\u7684\u306b\u30ef\u30fc\u30c9\u306f\u81ea\u52d5\u751f\u6210\u306b\u3057\u305f\u3044\u306a\u3001\u3068\u3044\u3046\u3053\u3068\u3067\u8abf\u67fb\u3002<\/p>\n\n\n<h3>PyTorch+Barracuda\u3067LSTM<\/h3>\n\n\n<p>Unity\u3067\u306f<a href=\"https:\/\/github.com\/Unity-Technologies\/barracuda-release\">Barracuda<\/a>\u3068\u3044\u3046\u30a8\u30f3\u30b8\u30f3\u3092\u4f7f\u3063\u3066\u30c7\u30a3\u30fc\u30d7\u30e9\u30fc\u30cb\u30f3\u30b0\u3092\u52d5\u304b\u305b\u308b\u3002\u591a\u5206\u4f8b\u306b\u3088\u3063\u3066\u4ed6\u3067\u5b66\u7fd2\u3057\u305f\u3082\u306e\u3092\u4f7f\u3048\u308b\u3060\u3051\u3002\u3064\u307e\u308aPython\u306a\u3069\u3067\u4f5c\u3063\u305f\u30e2\u30c7\u30eb\u3092ONNX\u306b\u5909\u63db\u3059\u308b\u3068Unity\u3067\u3082\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b\u306e\u3060\u304c\u3001<a href=\"https:\/\/denasu.com\/blog\/2021\/04\/diary4697\">\u524d\u56de\u306e\u65e5\u8a18<\/a>\u306e\u3088\u3046\u306bkeras\u3067\u306fTensorFlow2\u304c\u4f7f\u3048\u306a\u304b\u3063\u305f\u308a\u3057\u3066\u5909\u63db\u304c\u3067\u304d\u306a\u304b\u3063\u305f\u3002PyTorch\u3082\u5909\u63db\u3057\u305f\u30e2\u30c7\u30eb\u3092Unity\u4e0a\u306b\u6301\u3063\u3066\u304f\u308b\u3068\u30a8\u30e9\u30fc\u306b\u306a\u3063\u3066\u3044\u305f\u306e\u3060\u304c\u3001Barracuda\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u30921.3.3\uff08\u5b9f\u9a13\u7248\uff09\u306b\u3059\u308b\u3068\u8aad\u307f\u8fbc\u3093\u3067\u304f\u308c\u305f\u3002<\/p>\n\n\n\n<p>\u3067\u3001Embedded\u5c64\u3001LSTM\u5c64\u3092\u5165\u308c\u305f\u30e2\u30c7\u30eb\u3092\u52d5\u304b\u3057\u3066\u307f\u305f\u306e\u3060\u304c\u3001\u3069\u3046\u3082\u4e00\u7b87\u6240\u304a\u304b\u3057\u306a\u90e8\u5206\u304c\u3042\u308b\u3002BarracudaReferenceCPU.cs\u306eLSTM\u95a2\u6570\u3067\u3001\u5165\u529b\u30c6\u30f3\u30bd\u30eb\u306e\u5f62\u304c\uff08\u30ef\u30fc\u30c9\u30d9\u30af\u30c8\u30eb, \u30d0\u30c3\u30c1\uff09\u306b\u306a\u3063\u3066\u3044\u308b\u307d\u304f\u3066\u3001LTSM\u306e\u5404\u30b2\u30fc\u30c8\u306e\u91cd\u307f\u30c6\u30f3\u30bd\u30eb\uff08\u30ef\u30fc\u30c9\u30d9\u30af\u30c8\u30eb, \u96a0\u308c\u72b6\u614b\uff09\u3068\u306e\u5185\u7a4d\u3092\u53d6\u308d\u3046\u3068\u3057\u3066\u884c\u5217\u306e\u578b\u30a8\u30e9\u30fc\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3002\u5177\u4f53\u7684\u306b\u306f\u3053\u3053\u3002<\/p>\n\n\n\n<p><pre class=\"brush:csharp\">\nvar i_mad_w = _(Add(new[] { _(MatMul(X_sequence, false, W[g_i], false)), Wb[g_i] }));<br\/>\nvar j_mad_w = _(Add(new[] { _(MatMul(X_sequence, false, W[g_j], false)), Wb[g_j] }));<br\/>\nvar f_mad_w = _(Add(new[] { _(MatMul(X_sequence, false, W[g_f], false)), Wb[g_f] }));<br\/>\nvar o_mad_w = _(Add(new[] { _(MatMul(X_sequence, false, W[g_o], false)), Wb[g_o] }));\n<\/pre><\/p>\n\n\n\n<p>MatMul\uff08\u884c\u5217\u7a4d\uff09\u306e\u7b2c2\u5f15\u6570\u304c\u8ee2\u7f6e\u30d5\u30e9\u30b0\u306b\u306a\u3063\u3066\u3044\u3066\u3001\u3053\u3053\u3092true\u306b\u3059\u308b\u3068\u3046\u307e\u304f\u3044\u304f\u3002\u4f7f\u3044\u65b9\u304c\u60aa\u3044\u3093\u3060\u3068\u306f\u601d\u3046\u3051\u3069\u3001\u5916\u5074\u304b\u3089\u306a\u3093\u3068\u304b\u3067\u304d\u308b\u3088\u3046\u306a\u3082\u306e\u3067\u306f\u306a\u3055\u305d\u3046\u306a\u306e\u3067PyTorch\u3068\u306e\u76f8\u6027\u306a\u306e\u304b\u306a\u3042\u3002<\/p>\n\n\n\n<p>\u4ed6\u306b\u3082\u3001\u5143\u3005\u306f\u30e2\u30c7\u30eb\u306e\u6700\u5f8c\u306b\u51fa\u529b\u30ef\u30fc\u30c9\u306e\u78ba\u7387\u3092\u53d6\u308b\u305f\u3081\u306bsoftmax\u3092\u5165\u308c\u3066\u3044\u305f\u306e\u3060\u304c\u3001\u305d\u3063\u3061\u3082reshape\u3067\u306a\u305c\u304b\u5217\u304c\u5897\u3048\u3066\u3057\u307e\u3063\u3066\u578b\u30a8\u30e9\u30fc\u306b\u306a\u3063\u305f\u308a\u3002\u3053\u3063\u3061\u306fC#\u5074\u3067\u8a08\u7b97\u3059\u308c\u3070\u3044\u3044\u306e\u3067\u554f\u984c\u306f\u306a\u3044\u3051\u3069\u3002<\/p>\n\n\n<h3>\u7d50\u679c<\/h3>\n\n\n<p>\u3053\u3093\u306a\u611f\u3058\u3002\u307e\u3060\u30c7\u30d0\u30c3\u30b0\u7248\u3067CPU\u4f7f\u7528\u3060\u3051\u3069\u3001\u751f\u6210\u306e\u901f\u5ea6\u306f1\u6587\u30671\u79d2\u672a\u6e80\u304f\u3089\u3044\u304b\u306a\u3002\u65e5\u672c\u8a9e\u306e\u51fa\u6765\u3068\u3057\u3066\u306f\u30fb\u30fb\u30fb\u5b66\u7fd2\u304c15\u5206\u304f\u3089\u3044\u306a\u306e\u3067\u3001\u3082\u3046\u5c11\u3057\u5b66\u7fd2\u3059\u308c\u3070\u3088\u304f\u306a\u308b\u304b\u3082\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/denasu.com\/blog\/wp-content\/uploads\/2021\/04\/2021041801.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"756\" height=\"520\" src=\"https:\/\/denasu.com\/blog\/wp-content\/uploads\/2021\/04\/2021041801.jpg\" alt=\"\" class=\"wp-image-4709\"\/><\/a><\/figure>\n\n\n<h3>\u307e\u3068\u3081<\/h3>\n\n\n<p>Barracuda\u3092\u5b9f\u9a13\u7248\u306b\u3057\u3066\u3055\u3089\u306b\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b9\u306b\u4e0a\u8a18\u306e\u4fee\u6b63\u3092\u3059\u308b\u3068\u52d5\u304f\u306e\u3060\u304c\u3001Unity\u30e9\u30a4\u30bb\u30f3\u30b9\u3092\u8abf\u3079\u306a\u3044\u3068\u516c\u958b\u306f\u3067\u304d\u306a\u3044\u304b\u306a\u3042\u3002\u516c\u958b\u307e\u3067\u306b\u30ea\u30ea\u30fc\u30b9\u7248\u304c\u51fa\u3066\u30d0\u30b0\uff1f\u304c\u4fee\u6b63\u3055\u308c\u3066\u3044\u308b\u3068\u3044\u3044\u306a\u3042\u3002<\/p>\n\n\n\n<p>\u306a\u304a\u3001\u4eca\u56deBarracuda\u3092\u30c7\u30d0\u30c3\u30b0\u3057\u3064\u3064\u3001LSTM\u3092\u81ea\u5206\u3067\u5b9f\u88c5\u3057\u305f\u3082\u306e\u3068\u5b9f\u884c\u5185\u5bb9\u3092\u6bd4\u8f03\u3057\u3066\u3088\u3046\u3084\u304f\u554f\u984c\u304c\u5224\u660e\u3057\u305f\uff08\u306a\u3093\u3068\u306a\u304f\u8ee2\u7f6e\u304c\u3044\u308b\u306e\u306f\u3059\u3050\u5206\u304b\u3063\u305f\u3051\u3069\u3001\u30c7\u30d0\u30c3\u30b0\u3057\u3066\u3088\u3046\u3084\u304f\u7406\u7531\u304c\u5206\u304b\u3063\u305f\uff09\u306e\u3060\u304c\u3001\u3084\u3063\u3071\u308a\u4e00\u56de\u81ea\u5206\u3067\u5b9f\u88c5\u3057\u3066\u3044\u308b\u304b\u3089\u5206\u304b\u308b\u90e8\u5206\u3082\u3042\u308b\u3002\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u4f7f\u3044\u65b9\u3092\u77e5\u3063\u3066\u3044\u308b\u3060\u3051\u3058\u3083\u306a\u304f\u3066\u4e2d\u8eab\u3082\u77e5\u3063\u3066\u308b\u65b9\u304c\u3044\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30a6\u30a7\u30b6\u30bf\u30a44.1\u3067\u306f\u30c7\u30a3\u30fc\u30d7\u30e9\u30fc\u30cb\u30f3\u30b0\u3092\u4f7f\u3063\u305f\u30ef\u30fc\u30c9\u81ea\u52d5\u751f\u6210\u3092\u5b9f\u88c5\u3057\u305f\u3002\u3067\u3001Unity\u3067\u4f5c\u3063\u3066\u3044\u308b\u30bf\u30a4\u30d4\u30f3\u30b0\u30bd\u30d5\u30c8\u3067\u306f\u57fa\u672c\u7684\u306b\u30ef\u30fc\u30c9\u306f\u81ea\u52d5\u751f\u6210\u306b\u3057\u305f\u3044\u306a\u3001\u3068\u3044\u3046\u3053\u3068\u3067\u8abf\u67fb\u3002 PyTorch+Barracuda\u3067LSTM Unity\u3067\u306fBarracuda\u3068\u3044\u3046\u30a8\u30f3\u30b8\u30f3\u3092\u4f7f\u3063\u3066\u30c7\u30a3\u30fc\u30d7\u30e9\u30fc\u30cb\u30f3\u30b0\u3092\u52d5\u304b\u305b\u308b\u3002\u591a\u5206\u4f8b\u306b\u3088\u3063\u3066\u4ed6\u3067\u5b66\u7fd2\u3057\u305f\u3082\u306e\u3092\u4f7f\u3048\u308b\u3060\u3051\u3002\u3064\u307e\u308aPython\u306a\u3069\u3067\u4f5c\u3063\u305f\u30e2\u30c7\u30eb\u3092ONNX\u306b\u5909\u63db\u3059\u308b\u3068Unity\u3067\u3082\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b\u306e\u3060\u304c\u3001\u524d\u56de\u306e\u65e5\u8a18\u306e\u3088\u3046\u306bkeras\u3067\u306fTensorFlow2\u304c\u4f7f\u3048\u306a\u304b\u3063\u305f\u308a\u3057\u3066\u5909\u63db\u304c\u3067\u304d\u306a\u304b\u3063\u305f\u3002PyTorch\u3082\u5909\u63db\u3057\u305f\u30e2\u30c7\u30eb\u3092Unity\u4e0a\u306b\u6301\u3063\u3066\u304f\u308b\u3068\u30a8\u30e9\u30fc\u306b\u306a\u3063\u3066\u3044\u305f\u306e\u3060\u304c\u3001Barracuda\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u30921.3.3\uff08\u5b9f\u9a13\u7248\uff09\u306b\u3059\u308b\u3068\u8aad\u307f\u8fbc\u3093\u3067\u304f\u308c\u305f\u3002 \u3067\u3001Embedded\u5c64\u3001LSTM\u5c64\u3092\u5165\u308c\u305f\u30e2\u30c7\u30eb\u3092\u52d5\u304b\u3057\u3066\u307f\u305f\u306e\u3060\u304c\u3001\u3069\u3046\u3082\u4e00\u7b87\u6240\u304a\u304b\u3057\u306a\u90e8\u5206\u304c\u3042\u308b\u3002BarracudaReferenceCPU.cs\u306eLSTM\u95a2\u6570\u3067\u3001\u5165\u529b\u30c6\u30f3\u30bd\u30eb\u306e\u5f62\u304c\uff08\u30ef\u30fc\u30c9\u30d9\u30af\u30c8\u30eb, \u30d0\u30c3\u30c1\uff09\u306b\u306a\u3063\u3066\u3044\u308b\u307d\u304f\u3066\u3001LTSM\u306e\u5404\u30b2\u30fc\u30c8\u306e\u91cd\u307f\u30c6\u30f3\u30bd\u30eb\uff08\u30ef\u30fc\u30c9\u30d9\u30af\u30c8\u30eb, \u96a0\u308c\u72b6\u614b\uff09\u3068\u306e\u5185\u7a4d\u3092\u53d6\u308d\u3046\u3068\u3057\u3066\u884c\u5217\u306e\u578b\u30a8\u30e9\u30fc\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3002\u5177\u4f53\u7684\u306b\u306f\u3053\u3053\u3002 var i_mad_w = _(Add(new[] { _(MatMul(X_sequence, false, W[g_i], false)), Wb[g_i] })); var j_mad_w = _(Add(new[] { _(MatMul(X_sequence, false, W[g_j], false)), Wb[g_j] })); var f_mad_w = _(Add(new[] { _(MatMul(X_sequence, false, W[g_f], false)), Wb[g_f] })); var o_mad_w = _(Add(new[] { _(MatMul(X_sequence, false, W[g_o], false)), Wb[g_o] })); MatMul\uff08\u884c\u5217\u7a4d\uff09\u306e\u7b2c2\u5f15\u6570\u304c\u8ee2\u7f6e\u30d5\u30e9\u30b0\u306b\u306a\u3063\u3066\u3044\u3066\u3001\u3053\u3053\u3092true\u306b\u3059\u308b\u3068\u3046\u307e\u304f\u3044\u304f\u3002\u4f7f\u3044\u65b9\u304c\u60aa\u3044\u3093\u3060\u3068\u306f\u601d\u3046\u3051\u3069\u3001\u5916\u5074\u304b\u3089\u306a\u3093\u3068\u304b\u3067\u304d\u308b\u3088\u3046\u306a\u3082\u306e\u3067\u306f\u306a\u3055\u305d\u3046\u306a\u306e\u3067PyTorch\u3068\u306e\u76f8\u6027\u306a\u306e\u304b\u306a\u3042\u3002 \u4ed6\u306b\u3082\u3001\u5143\u3005\u306f\u30e2\u30c7\u30eb\u306e\u6700\u5f8c\u306b\u51fa\u529b\u30ef\u30fc\u30c9\u306e\u78ba\u7387\u3092\u53d6\u308b\u305f\u3081\u306bsoftmax\u3092\u5165\u308c\u3066\u3044\u305f\u306e\u3060\u304c\u3001\u305d\u3063\u3061\u3082reshape\u3067\u306a\u305c\u304b\u5217\u304c\u5897\u3048\u3066\u3057\u307e\u3063\u3066\u578b\u30a8\u30e9\u30fc\u306b\u306a\u3063\u305f\u308a\u3002\u3053\u3063\u3061\u306fC#\u5074\u3067\u8a08\u7b97\u3059\u308c\u3070\u3044\u3044\u306e\u3067\u554f\u984c\u306f\u306a\u3044\u3051\u3069\u3002 \u7d50\u679c \u3053\u3093\u306a\u611f\u3058\u3002\u307e\u3060\u30c7\u30d0\u30c3\u30b0\u7248\u3067CPU\u4f7f\u7528\u3060\u3051\u3069\u3001\u751f\u6210\u306e\u901f\u5ea6\u306f1\u6587\u30671\u79d2\u672a\u6e80\u304f\u3089\u3044\u304b\u306a\u3002\u65e5\u672c\u8a9e\u306e\u51fa\u6765\u3068\u3057\u3066\u306f\u30fb\u30fb\u30fb\u5b66\u7fd2\u304c15\u5206\u304f\u3089\u3044\u306a\u306e\u3067\u3001\u3082\u3046\u5c11\u3057\u5b66\u7fd2\u3059\u308c\u3070\u3088\u304f\u306a\u308b\u304b\u3082\u3002 \u307e\u3068\u3081 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2,3],"tags":[57],"class_list":["post-4701","post","type-post","status-publish","format-standard","hentry","category-programming","category-computer","tag-typing-field"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4ZThs-1dP","_links":{"self":[{"href":"https:\/\/denasu.com\/blog\/wp-json\/wp\/v2\/posts\/4701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/denasu.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/denasu.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/denasu.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/denasu.com\/blog\/wp-json\/wp\/v2\/comments?post=4701"}],"version-history":[{"count":20,"href":"https:\/\/denasu.com\/blog\/wp-json\/wp\/v2\/posts\/4701\/revisions"}],"predecessor-version":[{"id":4723,"href":"https:\/\/denasu.com\/blog\/wp-json\/wp\/v2\/posts\/4701\/revisions\/4723"}],"wp:attachment":[{"href":"https:\/\/denasu.com\/blog\/wp-json\/wp\/v2\/media?parent=4701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/denasu.com\/blog\/wp-json\/wp\/v2\/categories?post=4701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/denasu.com\/blog\/wp-json\/wp\/v2\/tags?post=4701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}