{"id":16651,"date":"2017-10-26T15:49:34","date_gmt":"2017-10-26T06:49:34","guid":{"rendered":"http:\/\/labs.gree.jp\/blog\/?p=16651"},"modified":"2017-10-27T18:30:14","modified_gmt":"2017-10-27T09:30:14","slug":"%e7%a4%be%e5%86%85ai%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0%e3%82%b3%e3%83%b3%e3%83%86%e3%82%b9%e3%83%88%e3%81%a7%e5%84%aa%e5%8b%9d%e3%81%97%e3%81%9f%e3%82%b2%e3%83%bc%e3%83%a0","status":"publish","type":"post","link":"https:\/\/labs.gree.jp\/blog\/2017\/10\/16651\/","title":{"rendered":"\u793e\u5185AI\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b3\u30f3\u30c6\u30b9\u30c8\u3067\u512a\u52dd\u3057\u305f\u30b2\u30fc\u30e0\u30d7\u30ec\u30a4AI\u306e\u7d39\u4ecb"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u5fdc\u7528\u4eba\u5de5\u77e5\u80fd\u30c1\u30fc\u30e0\u306e\u8fbb\u672c\u3067\u3059\u3002<\/p>\n<p>\u6700\u8fd1\u306f\u8a08\u7b97\u30ea\u30bd\u30fc\u30b9\u3001\u30c7\u30fc\u30bf\u91cf\u3001\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306e\u6539\u5584\u306b\u3088\u3063\u3066\u7c21\u5358\u306b\u7cbe\u5ea6\u306e\u9ad8\u3044AI\u304c\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u3064\u3064\u3042\u308a\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u73fe\u72b6\u3067\u306f\u5168\u3066\u306e\u30bf\u30b9\u30af\u306b\u304a\u3044\u3066AI\u3092\u5229\u7528\u3059\u308c\u3070\u3044\u3044\u308f\u3051\u3067\u3082\u3042\u308a\u307e\u305b\u3093\u3057\u3001\u30ea\u30bd\u30fc\u30b9\u306e\u5236\u9650\u3082\u3042\u308b\u305f\u3081\u3001\u7279\u6027\u3092\u7406\u89e3\u3057\u3066\u4e0a\u624b\u306b\u5fdc\u7528\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002\u305d\u3053\u3067\u3001\u793e\u5185\u3067\u306fAI\u5fdc\u7528\u306e\u305f\u3081\u306e\u77e5\u898b\u3084\u74b0\u5883\u3092\u7a4d\u307f\u4e0a\u3052\u3066\u3044\u304f\u6a5f\u4f1a\u3092\u5897\u3084\u3059\u53d6\u308a\u7d44\u307f\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u5148\u65e5\u3001\u53d6\u308a\u7d44\u307f\u306e\u4e00\u74b0\u3067\u30b2\u30fc\u30e0\u30d7\u30ec\u30a4AI\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b3\u30f3\u30c6\u30b9\u30c8\u304c\u958b\u50ac\u3055\u308c\u3001\u7d0420\u30c1\u30fc\u30e0\u304c\u53c2\u52a0\u3057\u3066\u76db\u308a\u4e0a\u304c\u308a\u307e\u3057\u305f\u3002\u3053\u306e\u30b3\u30f3\u30c6\u30b9\u30c8\u3067\u512a\u52dd\u3057\u305f\u30b2\u30fc\u30e0\u30d7\u30ec\u30a4AI\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>AI\u306b\u3088\u308b\u30b2\u30fc\u30e0\u30d7\u30ec\u30a4\u52d5\u753b\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-16652\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2017\/10\/z0.gif\" alt=\"\" width=\"320\" height=\"130\" \/> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-16653\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2017\/10\/z1.gif\" alt=\"\" width=\"320\" height=\"130\" \/><\/p>\n<h1>\u30b3\u30f3\u30c6\u30b9\u30c8\u6982\u8981<\/h1>\n<p>AI\u306b\u30a2\u30af\u30b7\u30e7\u30f3\u30b2\u30fc\u30e0\u306a\u3069\u306e\u30c7\u30d0\u30c3\u30b0\u306e\u4e00\u90e8\u3092\u4efb\u305b\u3089\u308c\u308b\u304b\u3069\u3046\u304b\u691c\u8a3c\u3057\u305f\u3044\u3068\u3044\u3046\u8003\u3048\u3082\u3042\u3063\u305f\u306e\u3067\u3001\u30b2\u30fc\u30e0\u30d7\u30ec\u30a4AI\u304c\u5bfe\u8c61\u3068\u3057\u3066\u9078\u3070\u308c\u307e\u3057\u305f\u3002\u30b2\u30fc\u30e0\u3092AI\u7528\u306b\u5909\u66f4\u305b\u305a\u306b\u753b\u9762\u60c5\u5831\u3060\u3051\u3092\u4f7f\u3063\u3066\u30d7\u30ec\u30a4\u3055\u305b\u305f\u304b\u3063\u305f\u306e\u3067\u3001\u30b2\u30fc\u30e0\u30d7\u30ec\u30a4\u306e\u305f\u3081\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306bUniverse\u3092\u5229\u7528\u3057\u307e\u3057\u305f\u3002NeonRace\u3068\u3044\u3046Flash\u30b2\u30fc\u30e0\u306e\u30b9\u30c6\u30fc\u30b86\u306e\u30b9\u30b3\u30a2\u3067\u9806\u4f4d\u3092\u6c7a\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/openai\/universe\">Universe<\/a>\u306f\u69d8\u3005\u306a\u30b2\u30fc\u30e0\u3084\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092AI\u306b\u30d7\u30ec\u30a4\u3055\u305b\u308b\u305f\u3081\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002\u30b2\u30fc\u30e0\u306fdocker\u30b3\u30f3\u30c6\u30ca\u3067\u5b9f\u884c\u3055\u308c\u3001AI\u306f\u30b2\u30fc\u30e0\u6bce\u306b\u7528\u610f\u3055\u308c\u305f\u5831\u916c\u30b5\u30fc\u30d0\u3068VNC\u3092\u901a\u3058\u3066\u3001\u753b\u9762\u60c5\u5831\u304a\u3088\u3073\u5831\u916c\u306e\u53d6\u5f97\u3068\u30de\u30a6\u30b9\u3084\u30ad\u30fc\u30dc\u30fc\u30c9\u306b\u3088\u308b\u64cd\u4f5c\u304c\u3067\u304d\u307e\u3059\u3002\u5229\u7528\u8005\u306f\u3001\u53d6\u5f97\u3057\u305f\u753b\u9762\u3084\u5831\u916c\u304b\u3089\u6b21\u306e\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u6c7a\u5b9a\u3059\u308bAI\u3092\u4f5c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002 \u4f3c\u305f\u3088\u3046\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3068\u3057\u3066<a href=\"http:\/\/serpent.ai\/\">Serpent AI<\/a>\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<h1><a id=\"user-content-\u30b2\u30fc\u30e0\u306e\u8d77\u52d5\" class=\"anchor\" href=\"https:\/\/gist.git.gree-dev.net\/takaaki-tsujimoto\/1828c517ed281a16c9d7cfd6368795f8#\u30b2\u30fc\u30e0\u306e\u8d77\u52d5\" aria-hidden=\"true\"><\/a>\u30b2\u30fc\u30e0\u306e\u8d77\u52d5<\/h1>\n<p>\u307e\u305a\u306f\u30b2\u30fc\u30e0\u3092\u8d77\u52d5\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"lang:python decode:true\" title=\"\u30b2\u30fc\u30e0\u8d77\u52d5\">import sys\n\nimport gym\nimport universe\n\ndef main():\n    env_id = 'flashgames.NeonRaceLvl6-v0'\n    env = gym.make(env_id)\n\n    env.configure(remotes=1)  # automatically creates a local docker container\n    observation_n = env.reset()\n    while True:\n        action_n = [[('KeyEvent', 'ArrowUp', False)]]\n        observation_n, reward_n, done_n, info = env.step(action_n)\n\n    return 0\n\nif __name__ == '__main__':\n    sys.exit(main())<\/pre>\n<p>\u4e0a\u8a18\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068NeonRace\u306e\u30b9\u30c6\u30fc\u30b86\u304c\u958b\u59cb\u3055\u308c\u3001VNC\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3067localhost:5900\u306b\u63a5\u7d9a\u3059\u308b\u3068\u5b9f\u969b\u306b\u30b2\u30fc\u30e0\u3092\u30d7\u30ec\u30a4\u3067\u304d\u307e\u3059\u30025900\u756a\u30dd\u30fc\u30c8\u3067\u63a5\u7d9a\u3067\u304d\u306a\u304b\u3063\u305f\u5834\u5408\u306f\u3001docker ps\u306a\u3069\u3067\u5f85\u3061\u53d7\u3051\u30dd\u30fc\u30c8\u3092\u8abf\u3079\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u521d\u3081\u3066\u306e\u30d7\u30ec\u30a4\u3067\u308270000\u70b9\u524d\u5f8c\u306f\u51fa\u305b\u308b\u3068\u601d\u3046\u306e\u3067\u300170000\u70b9\u3092\u6700\u521d\u306e\u76ee\u6a19\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<h1>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306e\u5b9f\u884c<\/h1>\n<p>A3C\u306e<a href=\"https:\/\/github.com\/openai\/universe-starter-agent\">\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/a>\u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u308c\u3092\u30d9\u30fc\u30b9\u306b\u3057\u3066\u6539\u826f\u3057\u3066\u304f\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u300216\u4e26\u5217\u3067\u5b9f\u884c\u3059\u308b\u306812\u6642\u9593\u7a0b\u5ea6\u3067\u53ce\u675f\u3059\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>AI\u304c\u9078\u629e\u53ef\u80fd\u306a\u64cd\u4f5c\u304b\u3089\u7121\u99c4\u306a\u3082\u306e\u3092\u9664\u3044\u3066\u5b66\u7fd2\u3055\u305b\u305f\u7d50\u679c\u306f10000\u70b9\u7a0b\u5ea6\u3001\u58c1\u3068\u306e\u885d\u7a81\u56de\u6570\u3092\u6e1b\u3089\u3059\u305f\u3081\u306b\u30b3\u30fc\u30b9\u5916\u3092\u8d70\u308a\u7d9a\u3051\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<h1><a id=\"user-content-\u6027\u80fd\u6539\u5584\u306e\u53d6\u308a\u7d44\u307f\" class=\"anchor\" href=\"https:\/\/gist.git.gree-dev.net\/takaaki-tsujimoto\/1828c517ed281a16c9d7cfd6368795f8#\u6027\u80fd\u6539\u5584\u306e\u53d6\u308a\u7d44\u307f\" aria-hidden=\"true\"><\/a>\u6027\u80fd\u6539\u5584\u306e\u53d6\u308a\u7d44\u307f<\/h1>\n<p>\u3053\u3053\u304b\u3089\u306f\u6027\u80fd\u6539\u5584\u306e\u305f\u3081\u306b\u53d6\u308a\u7d44\u3093\u3060\u65b9\u6cd5\u3092\u3044\u304f\u3064\u304b\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h2><a id=\"user-content-\u7f70\u5247\u306e\u8ffd\u52a0\" class=\"anchor\" href=\"https:\/\/gist.git.gree-dev.net\/takaaki-tsujimoto\/1828c517ed281a16c9d7cfd6368795f8#\u7f70\u5247\u306e\u8ffd\u52a0\" aria-hidden=\"true\"><\/a>\u7f70\u5247\u306e\u8ffd\u52a0<\/h2>\n<p>\u30b3\u30fc\u30b9\u5185\u3092\u8d70\u3089\u305b\u308b\u305f\u3081\u306b\u3001\u30b3\u30fc\u30b9\u5916\u306b\u51fa\u305f\u6642\u306b\u7f70\u5247\u3092\u4e0e\u3048\u307e\u3057\u305f\u3002<\/p>\n<p>\u30b3\u30fc\u30b9\u5916\u306b\u51fa\u305f\u3053\u3068\u3092\u691c\u51fa\u3059\u308b\u305f\u3081\u306b\u3001\u30b2\u30fc\u30e0\u3092\u624b\u52d5\u3067\u30d7\u30ec\u30a4\u3057\u3066\u753b\u9762\u306e\u30ad\u30e3\u30d7\u30c1\u30e3\u3092\u7528\u610f\u3057\u3066\u3001CNN\u3067\u30b3\u30fc\u30b9\u5185\u30fb\u30b3\u30fc\u30b9\u5916\u5224\u5b9a\u3092\u884c\u3044\u307e\u3059\u300298%\u7a0b\u5ea6\u306e\u7cbe\u5ea6\u3067\u30b3\u30fc\u30b9\u5185\u30fb\u30b3\u30fc\u30b9\u5916\u306e\u5224\u5b9a\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u3001AI\u304c\u30b3\u30fc\u30b9\u5185\u3092\u8d70\u308a\u7d9a\u3051\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u30b9\u30b3\u30a2\u3082\u6539\u5584\u3057\u306620000\u70b9\u3067\u3059\u3002<\/p>\n<p>\u30ad\u30e3\u30d7\u30c1\u30e3\u306f\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u7528\u610f\u3067\u304d\u307e\u3059\u3002\u540c\u3058\u3088\u3046\u306a\u753b\u50cf\u3060\u3089\u3051\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u753b\u9762\u306e\u30ad\u30e3\u30d7\u30c1\u30e3\u306f5\u30d5\u30ec\u30fc\u30e0\u306b1\u56de\u306b\u3057\u3066\u3001\u30b3\u30fc\u30b9\u5185\u30fb\u30b3\u30fc\u30b9\u5916\u305d\u308c\u305e\u308c\u306e\u753b\u50cf\u30922000\u679a\u305a\u3064\u7528\u610f\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"lang:python decode:true \">import sys\n\nimport gym\nimport universe\n\nfrom PIL import Image\n\ndef main():\n    env_id = 'flashgames.NeonRaceLvl6-v0'\n    env = gym.make(env_id)\n\n    env.configure(remotes=1)  # automatically creates a local docker container\n    observation_n = env.reset()\n\n    i = 0\n    j = 0\n    while True:\n        action_n = [[('KeyEvent', 'ArrowUp', False)]]\n        observation_n, reward_n, done_n, info = env.step(action_n)\n        if i == 5:\n            i = 0\n            if observation_n[0] is not None :\n                pil_img = Image.fromarray(observation_n[0])\n                pil_img.save('.\/%d.jpg' % j)\n                j += 1\n        i += 1\n\n    return 0\n\nif __name__ == '__main__':\n    sys.exit(main())<\/pre>\n<p>CNN\u306f\u6700\u5f8c\u306b\u63b2\u8f09\u3059\u308b\u30b3\u30fc\u30c9\u3068\u540c\u3058\u3067\u3059\u3002<\/p>\n<h2>\u72b6\u614b\u7a7a\u9593\u306e\u5358\u7d14\u5316<\/h2>\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306e\u30e2\u30c7\u30eb\u3067\u306f\u753b\u9762\u60c5\u5831\u304b\u3089\u7279\u5fb4\u3092\u62bd\u51fa\u3067\u304d\u3066\u3044\u306a\u3044\u3088\u3046\u306b\u601d\u3048\u305f\u306e\u3067\u3001\u753b\u9762\u60c5\u5831\u304b\u3089\u5f79\u306b\u7acb\u3061\u305d\u3046\u306a\u7279\u5fb4\u3092\u62bd\u51fa\u3057\u3066\u72b6\u614b\u7a7a\u9593\u3092\u5358\u7d14\u5316\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u4e8b\u524d\u306b\u7279\u5fb4\u3092\u62bd\u51fa\u3059\u308b\u306e\u3067\u3001\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092CNN\u304b\u3089\u5168\u7d50\u5408\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306b\u5909\u66f4\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>OpenCV\u306b\u3088\u308b\u753b\u50cf\u51e6\u7406\u3084CNN\u3092\u5229\u7528\u3057\u3066\u4ee5\u4e0b\u306e\u7279\u5fb4\u3092\u62bd\u51fa\u3057\u307e\u3057\u305f\u3002<\/p>\n<ul>\n<li>\u30b3\u30fc\u30b9\u5185\u306e\u81ea\u6a5f\u306e\u4f4d\u7f6e<\/li>\n<li>\u59a8\u5bb3\u8eca\u4e21\u306e\u4f4d\u7f6e<\/li>\n<li>\u30dd\u30a4\u30f3\u30c8\u30a2\u30c3\u30d7\u30a2\u30a4\u30c6\u30e0\u306e\u4f4d\u7f6e<\/li>\n<\/ul>\n<p>\u3053\u308c\u3089\u306e\u7279\u5fb4\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u58c1\u3068\u306e\u885d\u7a81\u306e\u56de\u907f\u3001\u59a8\u5bb3\u8eca\u4e21\u306e\u56de\u907f\u3001\u30dd\u30a4\u30f3\u30c8\u30a2\u30c3\u30d7\u30a2\u30a4\u30c6\u30e0\u306e\u53d6\u5f97\u3092\u5b66\u7fd2\u3059\u308b\u3053\u3068\u3092\u671f\u5f85\u3057\u307e\u3057\u305f\u304c\u7279\u306b\u6539\u5584\u306f\u898b\u3089\u308c\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3092\u6539\u826f\u3059\u308b\u3068\u6027\u80fd\u304c\u5411\u4e0a\u3059\u308b\u3068\u306f\u601d\u3044\u307e\u3059\u304c\u3001\u5b66\u7fd2\u306b\u6642\u9593\u304c\u304b\u304b\u308b\u306e\u3067\u5f8c\u56de\u3057\u306b\u3057\u305f\u7d50\u679c\u3001\u30b3\u30f3\u30c6\u30b9\u30c8\u671f\u9593\u4e2d\u306b\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u6539\u826f\u306b\u306f\u7740\u624b\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<h2><a id=\"user-content-\u884c\u52d5\u3092\u4e00\u5b9a\u6642\u9593\u56fa\u5b9a\" class=\"anchor\" href=\"https:\/\/gist.git.gree-dev.net\/takaaki-tsujimoto\/1828c517ed281a16c9d7cfd6368795f8#\u884c\u52d5\u3092\u4e00\u5b9a\u6642\u9593\u56fa\u5b9a\" aria-hidden=\"true\"><\/a>\u884c\u52d5\u3092\u4e00\u5b9a\u6642\u9593\u56fa\u5b9a<\/h2>\n<p>AI\u306f\u30d5\u30ec\u30fc\u30e0\u3054\u3068\u306b\u64cd\u4f5c\u3092\u6c7a\u5b9a\u3059\u308b\u306e\u3067\u3001\u66f2\u304c\u3063\u3066\u3044\u308b\u9014\u4e2d\u306b1\u56de\u3060\u3051\u76f4\u9032\u3057\u3066\u304b\u3089\u307e\u305f\u66f2\u304c\u308a\u59cb\u3081\u308b\u306a\u3069\u306e\u7121\u99c4\u306a\u884c\u52d5\u304c\u591a\u3044\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3057\u305f\u3002NeonRace\u3067\u306f\u30d5\u30ec\u30fc\u30e0\u3054\u3068\u306b\u30ad\u30fc\u5165\u529b\u3092\u5909\u5316\u3055\u305b\u308b\u5fc5\u8981\u304c\u306a\u304b\u3063\u305f\u306e\u3067\u3001\u64cd\u4f5c\u3092\u4e00\u5b9a\u6642\u9593\u56fa\u5b9a\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u30ab\u30fc\u30d6\u304c\u66f2\u304c\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u3001\u30b9\u30b3\u30a2\u304c40000\u70b9\u306b\u6539\u5584\u3057\u307e\u3057\u305f\u3002<\/p>\n<h2><a id=\"user-content-\u30eb\u30fc\u30eb\u30d9\u30fc\u30b9ai\u5316\" class=\"anchor\" href=\"https:\/\/gist.git.gree-dev.net\/takaaki-tsujimoto\/1828c517ed281a16c9d7cfd6368795f8#\u30eb\u30fc\u30eb\u30d9\u30fc\u30b9ai\u5316\" aria-hidden=\"true\"><\/a>\u30eb\u30fc\u30eb\u30d9\u30fc\u30b9AI\u5316<\/h2>\n<p>AI\u306e\u5b66\u7fd2\u3092\u5f85\u3063\u3066\u3044\u308b\u9593\u306b\u3001\u81ea\u6a5f\u4f4d\u7f6e\u3092\u5224\u5b9a\u3057\u3066\u58c1\u306b\u8fd1\u3065\u304f\u3068\u53cd\u5bfe\u5074\u306b\u66f2\u304c\u308b\u3060\u3051\u306e\u5358\u7d14\u306a\u30eb\u30fc\u30eb\u30d9\u30fc\u30b9AI\u3092\u4f5c\u3063\u3066\u307f\u308b\u306850000\u70b9\u304c\u51fa\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u3053\u304b\u3089\u306f\u5f37\u5316\u5b66\u7fd2\u3092\u6368\u3066\u3066\u3001AI\u306e\u884c\u52d5\u30eb\u30fc\u30eb\u306e\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u306b\u6ce8\u529b\u3057\u307e\u3057\u305f\u3002\u4ee5\u4e0b\u306e\u30eb\u30fc\u30eb\u3092\u8abf\u6574\u3059\u308b\u3068\u3001\u6700\u7d42\u7684\u306b\u521d\u5fc3\u8005\u3068\u540c\u7a0b\u5ea6\u306e80000\u70b9\u3092\u51fa\u3059AI\u304c\u5b8c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n<ul>\n<li>\u30b3\u30fc\u30b9\u306e\u66f2\u304c\u308a\u5177\u5408\u306b\u3088\u3063\u3066\u3001\u65e9\u3081\u306b\u66f2\u304c\u308a\u59cb\u3081\u308b<\/li>\n<li>\u30dd\u30a4\u30f3\u30c8\u30a2\u30c3\u30d7\u30a2\u30a4\u30c6\u30e0\u3092\u53d6\u5f97\u3067\u304d\u308b\u3088\u3046\u306b\u30d6\u30ec\u30fc\u30ad\u3092\u304b\u3051\u308b<\/li>\n<\/ul>\n<h1><a id=\"user-content-\u6240\u611f\" class=\"anchor\" href=\"https:\/\/gist.git.gree-dev.net\/takaaki-tsujimoto\/1828c517ed281a16c9d7cfd6368795f8#\u6240\u611f\" aria-hidden=\"true\"><\/a>\u6240\u611f<\/h1>\n<p>\u4eca\u56de\u5bfe\u8c61\u3068\u3057\u305f\u30b2\u30fc\u30e0\u3092\u5f37\u5316\u5b66\u7fd2\u3067\u5b66\u7fd2\u3055\u305b\u308b\u305f\u3081\u306b\u306f\u5831\u916c\u306e\u8a2d\u8a08\u3001\u7279\u5fb4\u30a8\u30f3\u30b8\u30cb\u30a2\u30ea\u30f3\u30b0\u3001\u884c\u52d5\u3092\u4e00\u5b9a\u6642\u9593\u56fa\u5b9a\u3059\u308b\u306a\u3069\u306e\u5bfe\u5fdc\u304c\u5fc5\u8981\u3067\u3057\u305f\u3002\u3057\u304b\u3057\u3001\u624b\u9593\u3092\u304b\u3051\u305f\u5272\u306b\u306f\u5b66\u7fd2\u304c\u9032\u307f\u307e\u305b\u3093\u3002\u753b\u9762\u60c5\u5831\u304b\u3089\u306e\u5b66\u7fd2\u306e\u305f\u3081\u306b\u306f\u30b2\u30fc\u30e0\u6bce\u306e\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u304c\u5fc5\u8981\u3067\u30011\u3064\u306eAI\u3067\u69d8\u3005\u306a\u30b2\u30fc\u30e0\u306b\u5bfe\u5fdc\u3055\u305b\u308b\u3053\u3068\u306f\u96e3\u3057\u305d\u3046\u3067\u3059\u3002\u307e\u305f\u3001AI\u306e\u5b66\u7fd2\u306e\u305f\u3081\u306bAWS\u306ec4.4xlarge\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u5229\u7528\u3057\u305f\u306e\u3067\u3059\u304c\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u5909\u66f4\u3084\u30e2\u30c7\u30eb\u306e\u5909\u66f4\u306e\u305f\u3073\u306b12\u6642\u9593\u307b\u3069\u5b9f\u884c\u3055\u305b\u308b\u5fc5\u8981\u304c\u3042\u308a\u3001\u4eba\u9593\u3068\u540c\u7b49\u306e\u6027\u80fd\u306eAI\u3092\u4f5c\u308b\u307e\u3067\u306b\u306f\u5927\u91cf\u306e\u8a08\u7b97\u30ea\u30bd\u30fc\u30b9\u304c\u5fc5\u8981\u3060\u3068\u601d\u308f\u308c\u307e\u3059\u3002\u73fe\u72b6\u3067\u306f\u6027\u80fd\u9762\u3067\u3082\u30b3\u30b9\u30c8\u9762\u3067\u3082AI\u306b\u30d7\u30ec\u30a4\u3055\u305b\u308b\u30c7\u30d0\u30c3\u30b0\u3088\u308a\u3082\u4eba\u9593\u306b\u3088\u308b\u30c7\u30d0\u30c3\u30b0\u306e\u307b\u3046\u304c\u826f\u3055\u305d\u3046\u3067\u3057\u305f\u3002\u5358\u7d14\u306a\u30b2\u30fc\u30e0\u3067\u3042\u308c\u3070\u3001\u7c21\u5358\u306a\u30eb\u30fc\u30eb\u30d9\u30fc\u30b9AI\u3067\u3082\u305d\u308c\u306a\u308a\u306e\u6027\u80fd\u304c\u3067\u308b\u3053\u3068\u304c\u5b9f\u611f\u3067\u304d\u305f\u306e\u3067\u3001\u307e\u305a\u306f\u30eb\u30fc\u30eb\u30d9\u30fc\u30b9AI\u3067\u8981\u4ef6\u304c\u6e80\u305f\u305b\u308b\u306e\u304b\u691c\u8a0e\u3059\u308b\u306e\u3082\u826f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u30b3\u30f3\u30c6\u30b9\u30c8\u8ab2\u984c\u306e\u9078\u629e\u3068\u3057\u3066\u306f\u53cd\u7701\u70b9\u304c\u3042\u308a\u307e\u3057\u305f\u3002\u4eca\u56de\u306e\u30c6\u30fc\u30de\u3067\u3042\u308b\u5f37\u5316\u5b66\u7fd2\u306b\u99b4\u67d3\u307f\u306e\u306a\u3044\u4eba\u304c\u591a\u304f\u3001\u53c2\u52a0\u8005\u306e\u534a\u5206\u304f\u3089\u3044\u306f\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u52d5\u304b\u3059\u3060\u3051\u3067\u7d42\u308f\u3063\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3057\u305f\u3002\u5e45\u5e83\u3044\u4eba\u306bAI\u3092\u5229\u7528\u3059\u308b\u6a5f\u4f1a\u3092\u4e0e\u3048\u308b\u305f\u3081\u306b\u306f\u5c11\u3057\u305a\u3064\u30b9\u30c6\u30c3\u30d7\u30a2\u30c3\u30d7\u3057\u3066\u3044\u304f\u3088\u3046\u306a\u8ab2\u984c\u3092\u9078\u3076\u3079\u304d\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001AI\u3092\u5229\u7528\u3067\u304d\u308b\u30bf\u30b9\u30af\u306e\u77e5\u898b\u3092\u8caf\u3081\u308b\u305f\u3081\u306b\u306f\u540c\u3058\u3088\u3046\u306a\u8ab2\u984c\u3070\u304b\u308a\u3092\u9078\u3076\u308f\u3051\u306b\u3082\u3044\u304d\u307e\u305b\u3093\u3002\u3053\u308c\u304b\u3089\u3082\u8a66\u884c\u932f\u8aa4\u3057\u306a\u304c\u3089\u3061\u3087\u3046\u3069\u3044\u3044\u8ab2\u984c\u8a2d\u5b9a\u3092\u8003\u3048\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h1><a id=\"user-content-\u304a\u307e\u3051\" class=\"anchor\" href=\"https:\/\/gist.git.gree-dev.net\/takaaki-tsujimoto\/1828c517ed281a16c9d7cfd6368795f8#\u304a\u307e\u3051\" aria-hidden=\"true\"><\/a>\u304a\u307e\u3051<\/h1>\n<p>\u5358\u7d14\u306a\u30eb\u30fc\u30eb\u30d9\u30fc\u30b9AI\u306e\u30b3\u30fc\u30c9\u3092\u63b2\u8f09\u3057\u307e\u3059\u3002\u672c\u6587\u4e2d\u306b\u63b2\u8f09\u3057\u305f\u30ad\u30e3\u30d7\u30c1\u30e3\u7528\u30b3\u30fc\u30c9\u3067\u7528\u610f\u3057\u305f\u753b\u50cf\u3092\u81ea\u6a5f\u306e\u30b3\u30fc\u30b9\u4e2d\u306e\u4f4d\u7f6e\u3067\u5de6\u30fb\u4e2d\u592e\u30fb\u53f3\u306b\u5206\u985e\u3057\u3066<code>left.txt<\/code> <code>center.txt<\/code> <code>right.txt<\/code>\u306b\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9\u3092\u4fdd\u5b58\u3057\u3066\u304b\u3089\u3001<code>python sample.py train<\/code>\u3067\u5b66\u7fd2\u3055\u305b\u3066\u304f\u3060\u3055\u3044\u3002\u5b66\u7fd2\u5f8c\u3001<code>python sample.py<\/code>\u3092\u5b9f\u884c\u3059\u308c\u3070\u30eb\u30fc\u30eb\u30d9\u30fc\u30b9\u306eAI\u304c\u30b2\u30fc\u30e0\u30d7\u30ec\u30a4\u3092\u958b\u59cb\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306eAI\u306f\u305d\u308c\u307b\u3069\u6027\u80fd\u3092\u8981\u6c42\u3057\u306a\u3044\u306e\u3067\u3001\u624b\u5143\u306eCore i7 2.8GHz\u300116GB\u306e\u30e1\u30e2\u30ea\u3092\u642d\u8f09\u3057\u305fMacBook Pro\u3067\u52d5\u4f5c\u3055\u305b\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"lang:default decode:true\">import sys\n\nimport gym\nimport universe\nfrom universe import spaces\nfrom universe import vectorized\nfrom universe.wrappers import Vision\n\nimport numpy as np\nimport cv2\nimport tensorflow as tf\n\nINPUT_SHAPE=(22, 82, 1)\n\ndef flatten(x):\n    return tf.reshape(x, [-1, np.prod(x.get_shape().as_list()[1:])])\n\ndef linear(x, size, name, initializer=None, bias_init=0):\n    w = tf.get_variable(name + \"\/w\", [x.get_shape()[1], size], initializer=initializer)\n    b = tf.get_variable(name + \"\/b\", [size], initializer=tf.constant_initializer(bias_init))\n    return tf.matmul(x, w) + b\n\ndef conv2d(x, num_filters, name, filter_size=(3, 3), stride=(1, 1), pad=\"SAME\", dtype=tf.float32, collections=None):\n    with tf.variable_scope(name):\n        stride_shape = [1, stride[0], stride[1], 1]\n        filter_shape = [filter_size[0], filter_size[1], int(x.get_shape()[3]), num_filters]\n\n        fan_in = np.prod(filter_shape[:3])\n        fan_out = np.prod(filter_shape[:2]) * num_filters\n        w_bound = np.sqrt(6. \/ (fan_in + fan_out))\n\n        w = tf.get_variable(\"W\", filter_shape, dtype, tf.random_uniform_initializer(-w_bound, w_bound),\n                            collections=collections)\n        b = tf.get_variable(\"b\", [1, 1, 1, num_filters], initializer=tf.constant_initializer(0.0),\n                            collections=collections)\n        return tf.nn.conv2d(x, w, stride_shape, pad) + b\n\ndef make_graph():\n    x = tf.placeholder(tf.float32, shape=[None] + list(INPUT_SHAPE))\n    labels = tf.placeholder(tf.float32, shape=[None, 3])\n\n    l = tf.nn.relu(conv2d(x, 16, \"conv1\"))\n    l = tf.nn.relu(conv2d(l, 16, \"conv2\"))\n    l = tf.nn.batch_normalization(l, mean=0, variance=1.0, offset=0.0, scale=True, variance_epsilon=0.001)\n    l = tf.nn.max_pool(l, ksize=(1, 2, 2, 1), strides=(1, 2, 2, 1), padding=\"SAME\")\n    l = tf.nn.relu(linear(flatten(l), 256, \"linear1\"))\n    l = linear(l, 3, \"linear2\")\n    softmax            = tf.nn.softmax(l)\n    cross_entropy      = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(labels=labels, logits=l))\n    train_step         = tf.train.RMSPropOptimizer(0.001).minimize(cross_entropy)\n    correct_prediction = tf.equal(tf.argmax(l, 1), tf.argmax(labels, 1))\n    accuracy           = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))\n    return x, labels, softmax, cross_entropy, train_step, accuracy\n\ndef load_img(path):\n    img = cv2.imread(path, 0)\n    img = cv2.resize(img, (INPUT_SHAPE[1], INPUT_SHAPE[0]))\n    return np.reshape(img, list(INPUT_SHAPE))\n    \ndef train():\n    input_img, labels, softmax, cross_entropy, train_step, accuracy = make_graph()\n\n    data = []\n    label = []\n    print(\"loading data\")\n    with open(\".\/left.txt\", \"r\") as f:\n        for fname in f:\n            path = '.\/left\/%s' % fname.strip()\n            img = load_img(path)\n            data.append(img)\n            label.append([1, 0, 0])\n\n    with open(\".\/center.txt\", \"r\") as f:\n        for fname in f:\n            path = '.\/center\/%s' % fname.strip()\n            img = load_img(path)\n            data.append(img)\n            label.append([0, 1, 0])\n\n    with open(\".\/right.txt\", \"r\") as f:\n        for fname in f:\n            path = '.\/right\/%s' % fname.strip()\n            img = load_img(path)\n            data.append(img)\n            label.append([0, 0, 1])\n\n    ids = np.random.permutation(len(data))\n    data = np.array(data)\n    label = np.array(label)\n    train_x = data[ids[:-50],:,:,:]\n    train_y = label[ids[:-50],:]\n    test_x = data[ids[-50:],:,:,:]\n    test_y = label[ids[-50:],:]\n\n    EPOCH = 10\n    BATCH_SIZE = 128\n    print(\"start training process\")\n    saver = tf.train.Saver()\n    with tf.Session() as sess:\n        sess.run(tf.global_variables_initializer())\n        for i in range(EPOCH):\n            print(\"epoch %d\" % (i + 1))\n            x = np.array_split(train_x, train_x.shape[0] \/ BATCH_SIZE)\n            y = np.array_split(train_y, train_y.shape[0] \/ BATCH_SIZE)\n            processed_sample = 0\n            for j in range(len(x)):\n                loss, train_acc, _ = sess.run([cross_entropy, accuracy, train_step], {input_img: x[j], labels: y[j]})\n                processed_sample += len(x[j])\n                print(\"[%d \/ %d] loss = %.4f, acc = %.3f\" % (processed_sample , len(train_x), loss, train_acc))\n\n            ids = np.random.permutation(len(train_x))\n            train_x = train_x[ids]\n            train_y = train_y[ids]\n            saver.save(sess, \".\/model\/model.ckpt\")\n\n        pred_y = sess.run(accuracy, {input_img: test_x, labels: test_y})\n        print(\"test acc = %.3f\" % pred_y)\n\nclass CropScreen(vectorized.ObservationWrapper):\n    def __init__(self, env, height, width, top=0, left=0):\n        super(CropScreen, self).__init__(env)\n        self.height = height\n        self.width = width\n        self.top = top\n        self.left = left\n\n    def _observation(self, observation):\n        return [ob[self.top:self.top+self.height, self.left:self.left+self.width, :]\n                if ob is not None else None for ob in observation]\n\ndef main():\n    input_img, labels, softmax, _, _, _ = make_graph()\n    saver = tf.train.Saver()\n\n    env_id = 'flashgames.NeonRaceLvl6-v0'\n    env = gym.make(env_id)\n    env = Vision(env)\n    env = CropScreen(env, 260, 640, 260, 18)\n    env.configure(remotes=1)\n    observation = env.reset()\n\n    with tf.Session() as sess:\n        saver.restore(sess, \".\/model\/model.ckpt\")\n        left = right = False\n        while True:\n            action = [racing_vnc(left, right) for ob in observation]\n            observation, _, _, _ = env.step(action)\n            if observation[0] is not None :\n                img = cv2.cvtColor(observation[0], cv2.COLOR_RGB2GRAY)\n                img = cv2.resize(img, (INPUT_SHAPE[1], INPUT_SHAPE[0]))\n                img = np.reshape(img, list(INPUT_SHAPE))\n                position = sess.run(softmax, {input_img: np.array([img])}) # \u30b3\u30fc\u30b9\u306e\u5de6\u3001\u4e2d\u592e\u3001\u53f3\u306e\u3069\u3053\u306b\u3044\u308b\u304b\u5224\u5b9a\n                if np.argmax(position[0]) == 0: # \u5de6\u7aef\u306b\u3044\u308b\u5834\u5408\n                    left = False\n                    right = True\n                elif np.argmax(position[0]) == 1: # \u4e2d\u592e\u306b\u3044\u308b\u5834\u5408\n                    left = right = False\n                elif np.argmax(position[0]) == 2: # \u53f3\u7aef\u306b\u3044\u308b\u5834\u5408\u306f\u5de6\u306b\u66f2\u304c\u308b\n                    left = True\n                    right = False\n    return 0\n\ndef racing_vnc(left=False, right=False):\n    return [spaces.KeyEvent.by_name('up', down=True),\n            spaces.KeyEvent.by_name('left', down=left),\n            spaces.KeyEvent.by_name('right', down=right)]\n\nif __name__ == '__main__':\n    args = sys.argv\n    if len(args) == 2 and args[1] == \"train\":\n        train()\n    else:\n        main()<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u5fdc\u7528\u4eba\u5de5\u77e5\u80fd\u30c1\u30fc\u30e0\u306e\u8fbb\u672c\u3067\u3059\u3002 \u6700\u8fd1\u306f\u8a08\u7b97\u30ea\u30bd\u30fc\u30b9\u3001\u30c7\u30fc\u30bf\u91cf\u3001\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306e\u6539\u5584\u306b\u3088\u3063\u3066\u7c21\u5358\u306b\u7cbe\u5ea6\u306e\u9ad8\u3044AI\u304c\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u3064\u3064\u3042\u308a\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u73fe\u72b6\u3067\u306f\u5168\u3066\u306e\u30bf\u30b9\u30af\u306b\u304a\u3044\u3066AI\u3092\u5229\u7528\u3059\u308c\u3070\u3044\u3044\u308f\u3051\u3067\u3082 [&hellip;]<\/p>\n","protected":false},"author":184,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[93,123],"class_list":["post-16651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-ai","tag-deep-learning"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/16651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/users\/184"}],"replies":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/comments?post=16651"}],"version-history":[{"count":3,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/16651\/revisions"}],"predecessor-version":[{"id":16681,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/16651\/revisions\/16681"}],"wp:attachment":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/media?parent=16651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/categories?post=16651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/tags?post=16651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}