{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# coding: utf-8\n# Dogs vs. Cats\n#匯入所需函式庫\n%matplotlib inline\nfrom keras.applications.vgg16 import VGG16, preprocess_input, decode_predictions\nfrom keras.preprocessing import image\nfrom PIL import Image\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport sys\n# 載入完成學習的模型VGG16\nmodel = VGG16(weights='imagenet')\n\n\n# 用來判斷影像的函式\ndef predict(filename, featuresize):\n    img = image.load_img(filename, target_size=(224, 224))\n    x = image.img_to_array(img)\n    x = np.expand_dims(x, axis=0)\n    preds = model.predict(preprocess_input(x))\n    results = decode_predictions(preds, top=featuresize)[0]\n    return results\n\n# 用來顯示影像的函式\ndef showimg(filename, title, i):\n    im = Image.open(filename)\n    im_list = np.asarray(im)\n    plt.subplot(2, 5, i)\n    plt.title(title)\n    plt.axis(\"off\")\n    plt.imshow(im_list)\n\n# 判斷影像\nfilename = \"./train/cat.103.jpg\"\nplt.figure(figsize=(20, 10))\nfor i in range(1):\n    showimg(filename, \"query\", i+1)\n    plt.show()\n    results = predict(filename, 10)\nfor result in results:\n    print(result)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# ! unzip file.zip","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}