{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","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":31040,"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-04T07:31:13.308600Z","iopub.execute_input":"2025-07-04T07:31:13.308922Z","iopub.status.idle":"2025-07-04T07:31:14.040315Z","shell.execute_reply.started":"2025-07-04T07:31:13.308898Z","shell.execute_reply":"2025-07-04T07:31:14.039349Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport os, glob, time, copy, zipfile\nfrom PIL import Image\nfrom sklearn.model_selection import train_test_split\nfrom tqdm import tqdm\nimport torch\nimport torch.nn as nn\nimport torch.optim as optim\nimport torch.utils.data as data\nimport torch.nn.functional as F\nfrom torchvision import models, transforms","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-04T07:31:14.041153Z","iopub.execute_input":"2025-07-04T07:31:14.041510Z","iopub.status.idle":"2025-07-04T07:31:25.818137Z","shell.execute_reply.started":"2025-07-04T07:31:14.041488Z","shell.execute_reply":"2025-07-04T07:31:25.817392Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"size = 224 #画像サイズ\nmean = (0.485, 0.456, 0.406) #ImageNetデータセットの平均値\nstd = (0.229, 0.224, 0.225)  #ImageNetデータセットの標準偏差\nbatch_size = 32 #バッチサイズ\ndevice = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\nnum_epoch = 10 #学習回数","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-04T07:31:25.819792Z","iopub.execute_input":"2025-07-04T07:31:25.820176Z","iopub.status.idle":"2025-07-04T07:31:25.828908Z","shell.execute_reply.started":"2025-07-04T07:31:25.820154Z","shell.execute_reply":"2025-07-04T07:31:25.827823Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!rm -rf ../data","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-04T07:31:25.829881Z","iopub.execute_input":"2025-07-04T07:31:25.830157Z","iopub.status.idle":"2025-07-04T07:31:25.985151Z","shell.execute_reply.started":"2025-07-04T07:31:25.830134Z","shell.execute_reply":"2025-07-04T07:31:25.983994Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"base_dir = '../input/dogs-vs-cats-redux-kernels-edition'\ntrain_dir = './data/train'\ntest_dir = './data/test'\n\n# 解凍先のフォルダを作成（すでにあってもOK）\nos.makedirs('./data', exist_ok=True)\nos.makedirs(train_dir, exist_ok=True)\nos.makedirs(test_dir, exist_ok=True)\n\n\n\n# 学習データの解凍\nwith zipfile.ZipFile(os.path.join(base_dir, 'train.zip')) as train_zip:\n    train_zip.extractall('./data')\n    \n#推論データの解凍\nwith zipfile.ZipFile(os.path.join(base_dir, 'test.zip')) as test_zip:\n    test_zip.extractall('./data')\n\n\ntrain_list = glob.glob(os.path.join(train_dir, '*.jpg'))\ntest_list = glob.glob(os.path.join(test_dir, '*.jpg'))\n\n# 学習データから検証データを分割(8:2)\ntrain_list, val_list = train_test_split(train_list, test_size=0.2)\nprint(\"clear\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-04T07:31:53.919571Z","iopub.execute_input":"2025-07-04T07:31:53.919925Z","iopub.status.idle":"2025-07-04T07:32:06.175110Z","shell.execute_reply.started":"2025-07-04T07:31:53.919899Z","shell.execute_reply":"2025-07-04T07:32:06.174007Z"}},"outputs":[],"execution_count":null}]}