{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"collapsed_sections": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
""
]
},
{
"cell_type": "code",
"metadata": {
"id": "zAg2Ukl4zSCN"
},
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "v5F7KOZIzWE3"
},
"source": [
"from tensorflow.keras.applications import ResNet50\n",
"from tensorflow.keras.applications.resnet50 import preprocess_input\n",
"from tensorflow.keras.preprocessing.image import load_img, img_to_array"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "-OB0gc2z6lAy"
},
"source": [
"### 1. 讀入資料集"
]
},
{
"cell_type": "code",
"source": [
"!wget --no-check-certificate \\\n",
" https://github.com/yenlung/Python-AI-Book/raw/main/dataset/Cooper_img.zip \\\n",
" -O /content/Cooper.zip"
],
"metadata": {
"id": "wYZOufOsXdkS",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "38c26d8b-7eff-4476-a882-72971e34aae8"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"--2022-08-16 04:09:13-- https://github.com/yenlung/Python-AI-Book/raw/main/dataset/Cooper_img.zip\n",
"Resolving github.com (github.com)... 20.205.243.166\n",
"Connecting to github.com (github.com)|20.205.243.166|:443... connected.\n",
"HTTP request sent, awaiting response... 302 Found\n",
"Location: https://raw.githubusercontent.com/yenlung/Python-AI-Book/main/dataset/Cooper_img.zip [following]\n",
"--2022-08-16 04:09:13-- https://raw.githubusercontent.com/yenlung/Python-AI-Book/main/dataset/Cooper_img.zip\n",
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.111.133, 185.199.110.133, ...\n",
"Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 1023448 (999K) [application/zip]\n",
"Saving to: ‘/content/Cooper.zip’\n",
"\n",
"\r/content/Cooper.zip 0%[ ] 0 --.-KB/s \r/content/Cooper.zip 100%[===================>] 999.46K --.-KB/s in 0.008s \n",
"\n",
"2022-08-16 04:09:13 (129 MB/s) - ‘/content/Cooper.zip’ saved [1023448/1023448]\n",
"\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"import os\n",
"import zipfile\n",
"\n",
"local_zip = '/content/Cooper.zip'\n",
"zip_ref = zipfile.ZipFile(local_zip, 'r')\n",
"zip_ref.extractall('/content')\n",
"zip_ref.close()"
],
"metadata": {
"id": "HzEj9J40uUmG"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"base_dir = '/content/'\n",
"cooper_dir = 'Cooper/'\n",
"thedir = base_dir + cooper_dir"
],
"metadata": {
"id": "D36cSpkC1eYj"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"cooper = [f\"{cooper_dir}/cooper0{i}.jpg\" for i in range(1, 7)]"
],
"metadata": {
"id": "z5SVzJVLCTdp"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "3icBxNl68NG9"
},
"source": [
"### 2. 讀入一隻 Cooper 試試"
]
},
{
"cell_type": "code",
"metadata": {
"id": "P5nukG2h8Yhb",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 286
},
"outputId": "74fad76e-4621-4d76-b7b2-50be9058dbdb"
},
"source": [
"img = load_img(cooper[2], target_size = (224, 224))\n",
"plt.imshow(img)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
""
]
},
"metadata": {},
"execution_count": 16
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"