{"id":113,"date":"2019-11-15T15:51:36","date_gmt":"2019-11-15T06:51:36","guid":{"rendered":"http:\/\/aiacademy.jp\/media\/?p=113"},"modified":"2024-08-06T16:26:27","modified_gmt":"2024-08-06T07:26:27","slug":"%e3%80%90%e5%88%9d%e5%bf%83%e8%80%85%e5%90%91%e3%81%91%e3%80%91python%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%87%e3%82%a3%e3%83%bc%e3%83%97%e3%83%a9%e3%83%bc%e3%83%8b%e3%83%b3%e3%82%b0%e3%81%ab","status":"publish","type":"post","link":"https:\/\/aiacademy.jp\/media\/?p=113","title":{"rendered":"\u3010\u521d\u5fc3\u8005\u5411\u3051\u3011Python\u3092\u4f7f\u3063\u3066\u30c7\u30a3\u30fc\u30d7\u30e9\u30fc\u30cb\u30f3\u30b0\u306b\u3088\u308b\u753b\u50cf\u5206\u985e\u3092\u4f53\u9a13\u3057\u3066\u307f\u3088\u3046\uff01"},"content":{"rendered":"<div id=\"sgb-css-id-1\">\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-font-size is-style-fill has-medium-font-size\"><a class=\"wp-block-button__link has-vivid-green-cyan-background-color has-background wp-element-button\" href=\"https:\/\/lin.ee\/3E4GzWk\" rel=\"nofollow noopener\" target=\"_blank\">LINE\u53cb\u3060\u3061\u767b\u9332 \u25b6 \u6a5f\u68b0\u5b66\u7fd2\u30b3\u30fc\u30b9 \u25b6 \u53d7\u8b1b\u5272\u5f15\u30af\u30fc\u30dd\u30f3 \u7121\u6599\u52d5\u753b<\/a><\/div>\n<\/div>\n<\/div>\n\n<div class=\"toc\">    <div id=\"toc_container\" class=\"sgb-toc--no-bullets js-smooth-scroll\" data-dialog-title=\"Table of Contents\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">\u306f\u3058\u3081\u306b<\/a>  <\/li>  <li>    <a href=\"#i-1\">Google Colaboratory\u3067\u6df1\u5c64\u5b66\u7fd2\u3092\u306f\u3058\u3081\u3088\u3046\uff01<\/a>  <\/li>  <li>    <a href=\"#i-2\">\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u306e\u4f5c\u6210<\/a>  <\/li>  <li>    <a href=\"#i-3\">GPU\u3092\u4f7f\u3063\u3066\u307f\u308b<\/a>  <\/li>  <li>    <a href=\"#i-4\">\u6df1\u5c64\u5b66\u7fd2\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u4f53\u9a13<\/a>  <\/li>  <li>    <a href=\"#i-5\">\u6ce8\u610f\u70b9<\/a>  <\/li>  <li class=\"last\">    <a href=\"#i-6\">\u307e\u3068\u3081<\/a>  <\/li><\/ul>\n      \n    <\/div><\/div><div class=\"toc\"><p><\/p>\n<\/div><h2 id=\"i-0\">\u306f\u3058\u3081\u306b<\/h2>\n<p><strong>\u3053\u306e\u30c6\u30ad\u30b9\u30c8(\u7ae0)\u306f\u3001\u624b\u3063\u53d6\u308a\u65e9\u304f\u6df1\u5c64\u5b66\u7fd2\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u4f53\u9a13\u3059\u308b\u3053\u3068\u3092\u76ee\u7684\u3068\u3057\u3066\u3044\u307e\u3059\u3002<\/strong><br>\u305d\u306e\u305f\u3081\u3001<strong><em>Python\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u57fa\u672c\u6587\u6cd5\u53ca\u3073\u3001scikit-learn\u3084numpy\u3084pandas\u3001matplotlib\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3084\u3001TensorFlow\u307e\u305f\u306fKeras\u306a\u3069\u306e\u6df1\u5c64\u5b66\u7fd2\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u8aac\u660e\u3084\u5c02\u9580\u7528\u8a9e\u7b49\u306e\u8aac\u660e\u306f\u5225\u306e\u30c6\u30ad\u30b9\u30c8\u306b\u8b72\u308a\u3001\u3053\u306e\u30c6\u30ad\u30b9\u30c8\u3067\u306f\u8aac\u660e\u3057\u3066\u304a\u308a\u307e\u305b\u3093\u306e\u3067\u3054\u4e86\u627f\u304f\u3060\u3055\u3044\u3002<\/em><\/strong><\/p>\n<h2 id=\"i-1\">Google Colaboratory\u3067\u6df1\u5c64\u5b66\u7fd2\u3092\u306f\u3058\u3081\u3088\u3046\uff01<\/h2>\n<p>Google\u304c\u6a5f\u68b0\u5b66\u7fd2\u306e\u6559\u80b2\u53ca\u3073\u7814\u7a76\u7528\u306b\u63d0\u4f9b\u3057\u3066\u3044\u308bGoogle Colaboratory\uff08\u30b0\u30fc\u30b0\u30eb\u30fb\u30b3\u30e9\u30dc\u30ec\u30a4\u30c8\u30ea\u30fc\uff09\u306e\u4f7f\u3044\u65b9\u3092\u8aac\u660e\u3057\u3001Python\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3068\u6a5f\u68b0\u5b66\u7fd2\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u884c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<br><strong><em>Colaboratory\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u4e0d\u8981\u304b\u3064\u3001\u3059\u3050\u306bPython\u74b0\u5883\u3092\u6574\u3048\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/em><\/strong><br>(Python\u3068\u6a5f\u68b0\u5b66\u7fd2\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001Python\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u305b\u305a\u306b\u6e08\u307f\u307e\u3059\u3002)<br>\u8cbb\u7528\u306f\u7121\u6599\u3067CPU\u53ca\u3073GPU(1\u56de12\u6642\u9593)\u306e\u74b0\u5883\u304c\u5229\u7528\u53ef\u80fd\u3067\u3001\u7528\u610f\u3059\u308b\u3082\u306e\u306f\u3001Google\u30a2\u30ab\u30a6\u30f3\u30c8\u3055\u3048\u3042\u308c\u3070\u5229\u7528\u3067\u304d\u307e\u3059\u3002<br>\u307e\u305f\u3001\u4e0b\u8a18\u306e\u4ee3\u8868\u7684\u306a\u6df1\u5c64\u5b66\u7fd2\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u52d5\u304b\u3059\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<br><strong>TensorFlow\/Keras\/Chainer\/PyTorch<\/strong><br>Colaboratory\u3092\u4f7f\u3046\u306b\u306f\u4e0b\u8a18\u306eURL\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3060\u3051\u3067\u3059\u3002<br>\u3067\u306f\u65e9\u901f\u4f7f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br>Google\u30a2\u30ab\u30a6\u30f3\u30c8\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u5f8c\u306b\u3001\u4e0b\u8a18\u30ea\u30f3\u30af\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br><a href=\"https:\/\/colab.research.google.com\/\" rel=\"nofollow noopener\" target=\"_blank\">Google Colaboratory<\/a><\/p>\n<h2 id=\"i-2\">\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u306e\u4f5c\u6210<\/h2>\n<p>\u300c\u6700\u8fd1\u306e\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u300d\u306e\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u753b\u9762\u306e\u5de6\u4e0b\u304b\u3089\u300cPYTHON3\u306e\u65b0\u3057\u3044\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u300d\u3092\u9078\u3073\u30af\u30ea\u30c3\u30af\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br>\u307e\u305f\u306f\u3001\u5de6\u4e0a\u30e1\u30cb\u30e5\u30fc\u306e\u300ePython3 \u306e\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u3092\u65b0\u898f\u4f5c\u6210\u300f\u3067\u3082\u540c\u3058\u3067\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/qiita-image-store.s3.amazonaws.com\/0\/171715\/53225540-1e3d-0a31-e6b9-e1c7e20e78a8.png\" alt=\"\"><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/qiita-image-store.s3.amazonaws.com\/0\/171715\/c12c88b1-d17b-5b2b-418e-647d8dfdc79a.png\" alt=\"\"><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/qiita-image-store.s3.amazonaws.com\/0\/171715\/3e4ef4f9-9838-642d-4d5c-6f31a322dd08.png\" alt=\"\"><\/p>\n<p>\u30fb\u5de6\u4e0a\u30e1\u30cb\u30e5\u30fc\u306e\u300ePython3 \u306e\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u3092\u65b0\u898f\u4f5c\u6210\u300f\u306e\u5834\u5408<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/qiita-image-store.s3.amazonaws.com\/0\/171715\/a49ad7ce-990f-58fb-6873-7f81ee627a2b.png\" alt=\"\"><\/p>\n<p>Colaboratory\u306e\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3067\u3057\u3087\u3046\u304b\uff1f<br>\u3055\u3066\u3001\u9ed2\u4e38\u306e\u4e09\u89d2\u306e\u5b9f\u884c\u30dc\u30bf\u30f3\u306e\u53f3\u6a2a\u306b\u3042\u308b\u8584\u3044\u9752\u8272\u306e\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001<br>\u305d\u3053\u306b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre><code>print(\"hello Python\")\n<\/code><\/pre>\n<p>\u59cb\u3081\u306f\u5c11\u3057\u6642\u9593\u304c\u304b\u304b\u308a\u307e\u3059\u304c\u3001\u5c11\u3057\u5f85\u3064\u3068\u7d50\u679c\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br>\u3061\u306a\u307f\u306b\u4f5c\u6210\u3057\u305f\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u306f\u3001\u81ea\u52d5\u7684\u306bGoogle Drive\u306b\u4fdd\u5b58\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/qiita-image-store.s3.amazonaws.com\/0\/171715\/a4802774-a67c-5bfc-eb92-5f6831abcb2b.png\" alt=\"\"><\/p>\n\n<h2 id=\"i-3\">GPU\u3092\u4f7f\u3063\u3066\u307f\u308b<\/h2>\n<p>\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u4f5c\u6210\u6642\u306b\u306f\u3001GPU\u3067\u306f\u306a\u3044\u305f\u3081\u3001\u4e0b\u8a18\u64cd\u4f5c\u306b\u3066GPU\u3092\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u4e0a\u90e8\u30e1\u30cb\u30e5\u30fc\u306e\u3000\u30e9\u30f3\u30bf\u30a4\u30e0 &gt; \u30e9\u30f3\u30bf\u30a4\u30e0\u306e\u30bf\u30a4\u30d7\u3092\u5909\u66f4\u3092\u9078\u629e\u3002<br>\u30cf\u30fc\u30c9\u30a6\u30a7\u30a2\u30a2\u30af\u30bb\u30e9\u30ec\u30fc\u30bf \u3092 None \u304b\u3089 GPU \u306b\u5909\u66f4\u3057\u3066\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/qiita-image-store.s3.amazonaws.com\/0\/171715\/3b808540-7d1f-1053-9914-dd6fede30777.png\" alt=\"\"><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/qiita-image-store.s3.amazonaws.com\/0\/171715\/dd14549b-fcb1-7489-db30-fda946a245c9.png\" alt=\"\"><\/p>\n<p>\u3055\u3066\u3001\u4e0b\u8a18\u3092\u5b9f\u884c\u3057<strong>\u2018\/device:GPU:0\u2019<\/strong>\u3068\u51fa\u529b\u3055\u308c\u3066\u3044\u308c\u3070GPU\u304c\u5229\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/qiita-image-store.s3.amazonaws.com\/0\/171715\/3def1337-3338-01e4-b2e6-0a324b7faac6.png\" alt=\"\"><\/p>\n<p>\u307e\u305f\u3001<\/p>\n<pre><code>!cat \/proc\/cpuinfo\n<\/code><\/pre>\n<p>\u53ca\u3073\u3001<\/p>\n<pre><code>!cat \/proc\/meminfo\n<\/code><\/pre>\n<p>\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001Colaboratory\u306e\u30de\u30b7\u30f3\u30b9\u30da\u30c3\u30af\u3092\u8abf\u3079\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/qiita-image-store.s3.amazonaws.com\/0\/171715\/d9af58e9-dd89-022f-4b5b-93b660aea506.png\" alt=\"\"><\/p>\n<h2 id=\"i-4\">\u6df1\u5c64\u5b66\u7fd2\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u4f53\u9a13<\/h2>\n<p>\u4eca\u56de\u306fKeras\u3092\u4f7f\u3063\u3066\u3001\u72ac\u3092\u8a8d\u8b58\u3059\u308b\u30e2\u30c7\u30eb\u3092\u4f5c\u308a\u307e\u3059\u3002<br>\u672c\u6765\u30e2\u30c7\u30eb\u3092\u4f5c\u308b\u5834\u5408\u306b\u306f\u3001\u5927\u91cf\u306e\u30c7\u30fc\u30bf\u3092\u6e96\u5099\u3057\u3001\u30cb\u30e5\u30fc\u30e9\u30eb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u5b66\u7fd2\u3092\u884c\u3044\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u4eca\u56de\u306f\u624b\u8efd\u306b\u6df1\u5c64\u5b66\u7fd2\u3092\u4f53\u9a13\u3057\u3066\u3082\u3089\u3046\u305f\u3081\u306b<strong><em>VGG16<\/em><\/strong>\u3068\u3044\u3046\u5b66\u7fd2\u6e08\u307f\u306e\u30e2\u30c7\u30eb\u3092\u4f7f\u3044\u307e\u3059\u3002<br><strong>VGG16\u306fImageNet\u3068\u3044\u3046100\u4e07\u679a\u3092\u8d85\u3048\u308b\u30c7\u30fc\u30bf\u3067\u3059\u3067\u306b\u5b66\u7fd2\u3055\u308c\u305f\u5b66\u7fd2\u6e08\u307f\u30e2\u30c7\u30eb\u3067\u3059\u3002<\/strong><br>\u5b66\u7fd2\u6e08\u307f\u30e2\u30c7\u30eb\u306b\u65b0\u3057\u304f\u753b\u50cf\u30c7\u30fc\u30bf\u3092\u4e0e\u3048\u308b\u3068\u5b66\u7fd2\u306b\u57fa\u3065\u3044\u305f\u4e88\u6e2c\u7d50\u679c\u3092\u8fd4\u3057\u307e\u3059\u3002<br>\u4eca\u56de\u306f\u3001\u72ac\u306e\u753b\u50cf\u3092\u4e0e\u3048\u308b\u3053\u3068\u3067\u6b63\u3057\u304f\u8a8d\u8b58\u3067\u304d\u308b\u304b\u3092\u8a66\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>from keras.applications.vgg16 import VGG16<\/strong>\u3067VGG16\u3092\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u4e0b\u8a18\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30b3\u30d4\u30fc&amp;\u30da\u30fc\u30b9\u30c8\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><code class=\"python:\"># Google Colab\u3067\u5b9f\u884c\u306e\u969b\u306b\u3001\u4e0b\u8a18\u306e\u30b3\u30fc\u30c9\u306b\u3066\u3001\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092TensorFlow\u3000\u30d0\u30fc\u30b8\u30e7\u30f31\u7cfb\u3067\u52d5\u4f5c\u3055\u305b\u308b\u305f\u3081\u306e\u30b3\u30de\u30f3\u30c9\u3067\u3059\u3002\n%tensorflow_version 1.x\n\n# TensorFlow \u30d0\u30fc\u30b8\u30e7\u30f32\u7cfb\u3067\u5b9f\u884c\u3057\u305f\u3044\u5834\u5408\u306f\u4e0b\u8a18\u306eColab(URL)\u3092\u3054\u78ba\u8a8d\u304f\u3060\u3055\u3044\u3002\n# https:\/\/colab.research.google.com\/notebooks\/tensorflow_version.ipynb\n\n# \u5fc5\u8981\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\nfrom keras.applications.vgg16 import VGG16, decode_predictions,preprocess_input\nfrom keras.preprocessing import image\nfrom PIL import Image\nimport numpy as np\nimport urllib.request as urllib\n\n# \u624b\u5143\u306e\u74b0\u5883\u3067\u5b9f\u884c\u3055\u305b\u305f\u3044\u5834\u5408\u306f\u4e0b\u8a182\u3064\u3082\u8aad\u307f\u8fbc\u3093\u3067\u304f\u3060\u3055\u3044\u3002\n# import tensorflow\n# import keras\n\n\n\"\"\"\nfilename: \u5224\u5b9a\u3057\u305f\u3044\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\nsize: \u4e88\u6e2c\u3057\u305f\u7d50\u679c\u3092\u4f55\u4ef6\u307e\u3067\u8868\u793a\u3055\u305b\u305f\u3044\u304b(\u521d\u671f\u502410\u4ef6)\n\"\"\"\ndef predict(filename, size=5):\n\n    filename = urllib.urlopen(filename) # \u5165\u529b\u753b\u50cf\u3092Web\u304b\u3089\u53d6\u5f97\n    img = image.load_img(filename, target_size=(224, 224)) # \u753b\u50cf\u3092\u8aad\u307f\u8fbc\u307f\n    x = image.img_to_array(img) # \u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3092\u6570\u5024\u306b\u5909\u63db\n    x = np.expand_dims(x, axis=0) # \u6b21\u5143\u3092\u5897\u3084\u3059\n    pred = model.predict(preprocess_input(x)) # \u4e00\u5f8b\u306b\u5e73\u5747\u5024\u3092\u5f15\u3044\u3066\u3044\u308b\u51e6\u7406\n    results = decode_predictions(pred, top=size)[0] # VGG16\u306e1000\u30af\u30e9\u30b9\u306fdecode_predictions()\u3067\u6587\u5b57\u5217\u306b\u5909\u63db\n    return results\n\n# VGG16\u3092\u4f7f\u7528\nmodel = VGG16(weights=\"imagenet\")\n\n# \u72ac\u306e\u5224\u5b9a\u51e6\u7406\nfilename = \"https:\/\/aiacademy.jp\/dataset\/dog1.jpg\"\n\nresults = predict(filename, 10)\nfor result in results:\n    print(result)\n<\/code><\/pre>\n<p>https:\/\/aiacademy.jp\/dataset\/dog1.jpg<br>\u306e\u753b\u50cf\u306f\u3001\u4e0b\u8a18\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/qiita-image-store.s3.amazonaws.com\/0\/171715\/b9ed288d-ac03-0db0-9fbe-61ef4ba2c320.jpeg\" alt=\"dog1 16.51.59.jpg\"><\/p>\n<p><img decoding=\"async\" src=\"\/assets\/images_test\/123_16bbc4a5a7b.png\" alt=\"\"><\/p>\n<p>\u7d50\u679c\u306f\u78ba\u7387\u3068\u3057\u3066\u8fd4\u3063\u3066\u304d\u307e\u3059\u3002\u307e\u305f\u3001\u4eca\u56de\u306f\u78ba\u7387\u306e\u4e0a\u4f4d10\u4f4d\u307e\u3067\u3092\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<br>\u4eca\u56de\u306e\u30c7\u30fc\u30bf\u306f79%\u306e\u78ba\u7387\u3067<strong>golden_retriever<\/strong>\u3068\u3044\u3046\u4e88\u6e2c\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>ImageNet\u306f\u72ac\u4ee5\u5916\u306e\u591a\u304f\u306e\u30c7\u30fc\u30bf\u3082\u542b\u3080\u305f\u3081\u4ed6\u306e\u52d5\u7269\u306a\u3069\u3082\u4e88\u6e2c\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<br>\u8208\u5473\u306e\u3042\u308b\u65b9\u306f\u4ee5\u4e0b\u306e\u624b\u9806\u306b\u5f93\u3044\u3001\u4ed6\u306e\u52d5\u7269\u306a\u3069\u306e\u30c7\u30fc\u30bf\u3067\u3082\u6b63\u3057\u304f\u4e88\u6e2c\u3067\u304d\u308b\u304b\u3092\u8a66\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u30ed\u30fc\u30ab\u30eb\u306b\u3042\u308b\u753b\u50cf\u30c7\u30fc\u30bf\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"python:\">from google.colab import files\nuploaded = files.upload()\n<\/code><\/pre>\n<p>\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u305f\u3089\u4e0b\u8a18\u306e\u30b3\u30fc\u30c9\u306e\u300cfilename\u300d\u3068\u3044\u3046\u3044\u3046\u5909\u6570\u306b\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u8a18\u8ff0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><code class=\"python:\"># \u30d5\u30a1\u30a4\u30eb\u30cd\u30fc\u30e0\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u8a18\u8ff0\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n# filename=\"elephant.png\"\nfilename = \"\"\n\ndef predict(filename, size=5):\n\n    img = image.load_img(filename, target_size=(224, 224)) # \u753b\u50cf\u3092\u8aad\u307f\u8fbc\u307f\n    x = image.img_to_array(img) # \u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3092\u6570\u5024\u306b\u5909\u63db\n    x = np.expand_dims(x, axis=0) # \u6b21\u5143\u3092\u5897\u3084\u3059\n    pred = model.predict(preprocess_input(x)) # \u4e00\u5f8b\u306b\u5e73\u5747\u5024\u3092\u5f15\u3044\u3066\u3044\u308b\u51e6\u7406\n    results = decode_predictions(pred, top=size)[0] # VGG16\u306e1000\u30af\u30e9\u30b9\u306fdecode_predictions()\u3067\u6587\u5b57\u5217\u306b\u5909\u63db\n    return results\n\nresults = predict(filename, 10)\nfor result in results:\n    print(result)\n<\/code><\/pre>\n<h2 id=\"i-5\">\u6ce8\u610f\u70b9<\/h2>\n<p>90\u5206\u307b\u3069\u64cd\u4f5c\u3057\u306a\u3044\u72b6\u614b\u304c\u7d9a\u304f\u5834\u5408\u3001\u4eee\u60f3\u30de\u30b7\u30f3\u306f\u505c\u6b62\u3057\u3001\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u30c7\u30fc\u30bf\u3084\u30e9\u30a4\u30d6\u30e9\u30ea\u306f\u521d\u671f\u5316\u3055\u308c\u308b\u4ed5\u69d8\u306b\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u3002<br>\u305d\u306e\u70b9\u306f\u30c7\u30e1\u30ea\u30c3\u30c8\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u3001\u7121\u6599\u3067\u30d6\u30e9\u30a6\u30b6\u304b\u3089Python\u3084\u305d\u306e\u4ed6\u306e\u6a5f\u68b0\u5b66\u7fd2\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u6700\u521d\u304b\u3089\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u4eee\u60f3\u30de\u30b7\u30f3\u3092\u5229\u7528\u3067\u304d\u308b\u30e1\u30ea\u30c3\u30c8\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2 id=\"i-6\">\u307e\u3068\u3081<\/h2>\n<p>Google Colaboratory\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u7121\u6599\u3067\u74b0\u5883\u69cb\u7bc9\u306a\u3057\u306b\u3001GPU\u74b0\u5883\u306b\u3066\u6a5f\u68b0\u5b66\u7fd2\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u304c\u3067\u304d\u307e\u3059\u3002<br>\u30af\u30e9\u30a6\u30c9\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u306a\u304f\u3001TensorFlow\u3084Keras\u306a\u3069\u306e\u4ee3\u8868\u7684\u306a\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3082\u52d5\u304b\u3059\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"aiacademy.jp\/bootcamp\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"341\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-1024x341.png\" alt=\"\" class=\"wp-image-691\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-1024x341.png 1024w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-300x100.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-768x256.png 768w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-940x313.png 940w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b21 \u306f\u3058\u3081\u306b Google Colaboratory\u3067\u6df1\u5c64\u5b66\u7fd2\u3092\u306f\u3058\u3081\u3088\u3046\uff01 \u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u306e\u4f5c\u6210 GPU\u3092\u4f7f\u3063\u3066\u307f\u308b \u6df1\u5c64\u5b66\u7fd2\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u4f53\u9a13 \u6ce8\u610f\u70b9 \u307e\u3068\u3081 \u306f\u3058\u3081\u306b \u3053\u306e\u30c6\u30ad\u30b9\u30c8(\u7ae0)\u306f\u3001\u624b\u3063\u53d6\u308a\u65e9\u304f\u6df1\u5c64\u5b66\u7fd2\u30d7\u30ed &#8230; <\/p>\n","protected":false},"author":1,"featured_media":487,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85,88,87],"tags":[],"class_list":{"0":"post-113","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python","8":"category-88","9":"category-87"},"_links":{"self":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=113"}],"version-history":[{"count":7,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/113\/revisions"}],"predecessor-version":[{"id":4740,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/113\/revisions\/4740"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/media\/487"}],"wp:attachment":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}