{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":5441,"databundleVersionId":38425,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-07-25T11:38:27.938682Z","iopub.execute_input":"2025-07-25T11:38:27.938933Z","iopub.status.idle":"2025-07-25T11:38:28.339265Z","shell.execute_reply.started":"2025-07-25T11:38:27.938912Z","shell.execute_reply":"2025-07-25T11:38:28.338224Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Dogs and cats","metadata":{}},{"cell_type":"code","source":"import zipfile\nimport os\nimport tensorflow as tf\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom PIL import Image\nimport glob\nfrom sklearn.model_selection import train_test_split\nimport shutil\nfrom tensorflow.keras import layers, models\nfrom tensorflow.keras.applications import EfficientNetB3\nfrom tensorflow.keras.callbacks import EarlyStopping\nimport random","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-25T11:38:28.340166Z","iopub.execute_input":"2025-07-25T11:38:28.340446Z","iopub.status.idle":"2025-07-25T11:38:28.359557Z","shell.execute_reply.started":"2025-07-25T11:38:28.340426Z","shell.execute_reply":"2025-07-25T11:38:28.358562Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"with zipfile.ZipFile('/kaggle/input/dogs-vs-cats-redux-kernels-edition/train.zip', 'r') as zip_ref:\n    zip_ref.extractall('/kaggle/working/')\n\n\nwith zipfile.ZipFile('/kaggle/input/dogs-vs-cats-redux-kernels-edition/test.zip', 'r') as zip_ref:\n    zip_ref.extractall('/kaggle/working/')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-25T11:38:28.360660Z","iopub.execute_input":"2025-07-25T11:38:28.361136Z","iopub.status.idle":"2025-07-25T11:38:39.654059Z","shell.execute_reply.started":"2025-07-25T11:38:28.361103Z","shell.execute_reply":"2025-07-25T11:38:39.653177Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"file_list = os.listdir('/kaggle/working')\nprint(file_list)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-25T11:39:23.490102Z","iopub.execute_input":"2025-07-25T11:39:23.491160Z","iopub.status.idle":"2025-07-25T11:39:23.497580Z","shell.execute_reply.started":"2025-07-25T11:39:23.491121Z","shell.execute_reply":"2025-07-25T11:39:23.496285Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 解凍済みの画像フォルダ\nimg_dir = '/kaggle/working/train'\n\n# 画像ファイル名一覧（JPEGのみ）\nall_images = [f for f in os.listdir(img_dir) if f.endswith('.jpg')]\n\n# 猫と犬のファイルを分ける\ncat_images = [f for f in all_images if f.startswith('cat')]\ndog_images = [f for f in all_images if f.startswith('dog')]\n\n# 猫・犬からそれぞれランダムに3枚ずつ\nsample_cats = random.sample(cat_images, 3)\nsample_dogs = random.sample(dog_images, 3)\n\n# 画像表示（3枚 × 2行）\nplt.figure(figsize=(12, 6))\n\n# 猫画像（1行目）\nfor i, fname in enumerate(sample_cats):\n    img_path = os.path.join(img_dir, fname)\n    img = Image.open(img_path)\n    plt.subplot(2, 3, i + 1)\n    plt.imshow(img)\n    plt.title(f\"Cat: {fname}\")\n    plt.axis('off')\n\n# 犬画像（2行目）\nfor i, fname in enumerate(sample_dogs):\n    img_path = os.path.join(img_dir, fname)\n    img = Image.open(img_path)\n    plt.subplot(2, 3, i + 4)\n    plt.imshow(img)\n    plt.title(f\"Dog: {fname}\")\n    plt.axis('off')\n\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-25T11:39:38.636456Z","iopub.execute_input":"2025-07-25T11:39:38.637338Z","iopub.status.idle":"2025-07-25T11:39:39.997819Z","shell.execute_reply.started":"2025-07-25T11:39:38.637299Z","shell.execute_reply":"2025-07-25T11:39:39.996173Z"}},"outputs":[],"execution_count":null}]}