feat: make notebook dual-compatible (Colab + local)
- Add IS_COLAB auto-detection (try/except google.colab) - Guard all /content/ paths behind IS_COLAB check - Local paths resolve relative to Machine_Learning/ directory - Remove unused imports (tarfile, pathlib, duplicate PIL) - Consolidate sklearn imports into cell 2 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
e791a71425
commit
ddced09bbc
1 file changed
+160
-526
+160
-526
@@ -15,14 +15,131 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "n6mBf6uO1VS6"
|
"id": "n6mBf6uO1VS6"
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Requirement already satisfied: tensorflow==2.19.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from -r requirements.txt (line 1)) (2.19.0)\n",
|
||||||
|
"Requirement already satisfied: tensorflowjs==4.22.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from -r requirements.txt (line 2)) (4.22.0)\n",
|
||||||
|
"Requirement already satisfied: numpy in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from -r requirements.txt (line 3)) (2.1.3)\n",
|
||||||
|
"Collecting matplotlib (from -r requirements.txt (line 4))\n",
|
||||||
|
" Using cached matplotlib-3.10.9-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.metadata (52 kB)\n",
|
||||||
|
"Collecting seaborn (from -r requirements.txt (line 5))\n",
|
||||||
|
" Using cached seaborn-0.13.2-py3-none-any.whl.metadata (5.4 kB)\n",
|
||||||
|
"Collecting pillow (from -r requirements.txt (line 6))\n",
|
||||||
|
" Using cached pillow-12.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.metadata (8.8 kB)\n",
|
||||||
|
"Collecting split-folders (from -r requirements.txt (line 7))\n",
|
||||||
|
" Using cached split_folders-0.6.1-py3-none-any.whl.metadata (11 kB)\n",
|
||||||
|
"Collecting scikit-learn (from -r requirements.txt (line 8))\n",
|
||||||
|
" Using cached scikit_learn-1.9.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.metadata (11 kB)\n",
|
||||||
|
"Requirement already satisfied: tf2onnx in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from -r requirements.txt (line 9)) (1.17.0)\n",
|
||||||
|
"Requirement already satisfied: onnxruntime in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from -r requirements.txt (line 10)) (1.26.0)\n",
|
||||||
|
"Requirement already satisfied: absl-py>=1.0.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (2.4.0)\n",
|
||||||
|
"Requirement already satisfied: astunparse>=1.6.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (1.6.3)\n",
|
||||||
|
"Requirement already satisfied: flatbuffers>=24.3.25 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (25.12.19)\n",
|
||||||
|
"Requirement already satisfied: gast!=0.5.0,!=0.5.1,!=0.5.2,>=0.2.1 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (0.7.0)\n",
|
||||||
|
"Requirement already satisfied: google-pasta>=0.1.1 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (0.2.0)\n",
|
||||||
|
"Requirement already satisfied: libclang>=13.0.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (18.1.1)\n",
|
||||||
|
"Requirement already satisfied: opt-einsum>=2.3.2 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (3.4.0)\n",
|
||||||
|
"Requirement already satisfied: packaging in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (23.2)\n",
|
||||||
|
"Requirement already satisfied: protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0dev,>=3.20.3 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (5.29.6)\n",
|
||||||
|
"Requirement already satisfied: requests<3,>=2.21.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (2.34.2)\n",
|
||||||
|
"Requirement already satisfied: setuptools in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (82.0.1)\n",
|
||||||
|
"Requirement already satisfied: six>=1.12.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (1.17.0)\n",
|
||||||
|
"Requirement already satisfied: termcolor>=1.1.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (3.3.0)\n",
|
||||||
|
"Requirement already satisfied: typing-extensions>=3.6.6 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (4.15.0)\n",
|
||||||
|
"Requirement already satisfied: wrapt>=1.11.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (2.2.1)\n",
|
||||||
|
"Requirement already satisfied: grpcio<2.0,>=1.24.3 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (1.81.1)\n",
|
||||||
|
"Requirement already satisfied: tensorboard~=2.19.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (2.19.0)\n",
|
||||||
|
"Requirement already satisfied: keras>=3.5.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (3.14.1)\n",
|
||||||
|
"Requirement already satisfied: h5py>=3.11.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (3.14.0)\n",
|
||||||
|
"Requirement already satisfied: ml-dtypes<1.0.0,>=0.5.1 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow==2.19.0->-r requirements.txt (line 1)) (0.5.4)\n",
|
||||||
|
"Requirement already satisfied: flax>=0.7.2 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflowjs==4.22.0->-r requirements.txt (line 2)) (0.12.7)\n",
|
||||||
|
"Requirement already satisfied: importlib_resources>=5.9.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflowjs==4.22.0->-r requirements.txt (line 2)) (7.1.0)\n",
|
||||||
|
"Requirement already satisfied: jax>=0.4.13 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflowjs==4.22.0->-r requirements.txt (line 2)) (0.10.1)\n",
|
||||||
|
"Requirement already satisfied: jaxlib>=0.4.13 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflowjs==4.22.0->-r requirements.txt (line 2)) (0.10.1)\n",
|
||||||
|
"Requirement already satisfied: tf-keras>=2.13.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflowjs==4.22.0->-r requirements.txt (line 2)) (2.19.0)\n",
|
||||||
|
"Requirement already satisfied: tensorflow-decision-forests>=1.5.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflowjs==4.22.0->-r requirements.txt (line 2)) (1.12.0)\n",
|
||||||
|
"Requirement already satisfied: tensorflow-hub>=0.16.1 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflowjs==4.22.0->-r requirements.txt (line 2)) (0.16.1)\n",
|
||||||
|
"Requirement already satisfied: charset_normalizer<4,>=2 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from requests<3,>=2.21.0->tensorflow==2.19.0->-r requirements.txt (line 1)) (3.4.7)\n",
|
||||||
|
"Requirement already satisfied: idna<4,>=2.5 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from requests<3,>=2.21.0->tensorflow==2.19.0->-r requirements.txt (line 1)) (3.18)\n",
|
||||||
|
"Requirement already satisfied: urllib3<3,>=1.26 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from requests<3,>=2.21.0->tensorflow==2.19.0->-r requirements.txt (line 1)) (2.7.0)\n",
|
||||||
|
"Requirement already satisfied: certifi>=2023.5.7 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from requests<3,>=2.21.0->tensorflow==2.19.0->-r requirements.txt (line 1)) (2026.5.20)\n",
|
||||||
|
"Requirement already satisfied: markdown>=2.6.8 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorboard~=2.19.0->tensorflow==2.19.0->-r requirements.txt (line 1)) (3.10.2)\n",
|
||||||
|
"Requirement already satisfied: tensorboard-data-server<0.8.0,>=0.7.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorboard~=2.19.0->tensorflow==2.19.0->-r requirements.txt (line 1)) (0.7.2)\n",
|
||||||
|
"Requirement already satisfied: werkzeug>=1.0.1 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorboard~=2.19.0->tensorflow==2.19.0->-r requirements.txt (line 1)) (3.1.8)\n",
|
||||||
|
"Collecting contourpy>=1.0.1 (from matplotlib->-r requirements.txt (line 4))\n",
|
||||||
|
" Using cached contourpy-1.3.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.metadata (5.5 kB)\n",
|
||||||
|
"Collecting cycler>=0.10 (from matplotlib->-r requirements.txt (line 4))\n",
|
||||||
|
" Using cached cycler-0.12.1-py3-none-any.whl.metadata (3.8 kB)\n",
|
||||||
|
"Collecting fonttools>=4.22.0 (from matplotlib->-r requirements.txt (line 4))\n",
|
||||||
|
" Using cached fonttools-4.63.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.metadata (118 kB)\n",
|
||||||
|
"Collecting kiwisolver>=1.3.1 (from matplotlib->-r requirements.txt (line 4))\n",
|
||||||
|
" Using cached kiwisolver-1.5.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.metadata (5.1 kB)\n",
|
||||||
|
"Collecting pyparsing>=3 (from matplotlib->-r requirements.txt (line 4))\n",
|
||||||
|
" Using cached pyparsing-3.3.2-py3-none-any.whl.metadata (5.8 kB)\n",
|
||||||
|
"Requirement already satisfied: python-dateutil>=2.7 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from matplotlib->-r requirements.txt (line 4)) (2.9.0.post0)\n",
|
||||||
|
"Requirement already satisfied: pandas>=1.2 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from seaborn->-r requirements.txt (line 5)) (3.0.3)\n",
|
||||||
|
"Requirement already satisfied: scipy>=1.10.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from scikit-learn->-r requirements.txt (line 8)) (1.17.1)\n",
|
||||||
|
"Collecting joblib>=1.4.0 (from scikit-learn->-r requirements.txt (line 8))\n",
|
||||||
|
" Using cached joblib-1.5.3-py3-none-any.whl.metadata (5.5 kB)\n",
|
||||||
|
"Collecting narwhals>=2.0.1 (from scikit-learn->-r requirements.txt (line 8))\n",
|
||||||
|
" Using cached narwhals-2.22.1-py3-none-any.whl.metadata (15 kB)\n",
|
||||||
|
"Collecting threadpoolctl>=3.5.0 (from scikit-learn->-r requirements.txt (line 8))\n",
|
||||||
|
" Using cached threadpoolctl-3.6.0-py3-none-any.whl.metadata (13 kB)\n",
|
||||||
|
"Requirement already satisfied: onnx>=1.14.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tf2onnx->-r requirements.txt (line 9)) (1.21.0)\n",
|
||||||
|
"Requirement already satisfied: wheel<1.0,>=0.23.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from astunparse>=1.6.0->tensorflow==2.19.0->-r requirements.txt (line 1)) (0.45.1)\n",
|
||||||
|
"Requirement already satisfied: msgpack in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (1.2.0)\n",
|
||||||
|
"Requirement already satisfied: optax in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (0.2.8)\n",
|
||||||
|
"Requirement already satisfied: orbax-checkpoint in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (0.12.0)\n",
|
||||||
|
"Requirement already satisfied: tensorstore in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (0.1.84)\n",
|
||||||
|
"Requirement already satisfied: rich>=11.1 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (15.0.0)\n",
|
||||||
|
"Requirement already satisfied: PyYAML>=5.4.1 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (6.0.3)\n",
|
||||||
|
"Requirement already satisfied: treescope>=0.1.7 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (0.1.10)\n",
|
||||||
|
"Requirement already satisfied: namex in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from keras>=3.5.0->tensorflow==2.19.0->-r requirements.txt (line 1)) (0.1.0)\n",
|
||||||
|
"Requirement already satisfied: optree in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from keras>=3.5.0->tensorflow==2.19.0->-r requirements.txt (line 1)) (0.19.1)\n",
|
||||||
|
"Requirement already satisfied: markdown-it-py>=2.2.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from rich>=11.1->flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (4.2.0)\n",
|
||||||
|
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from rich>=11.1->flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (2.20.0)\n",
|
||||||
|
"Requirement already satisfied: mdurl~=0.1 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from markdown-it-py>=2.2.0->rich>=11.1->flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (0.1.2)\n",
|
||||||
|
"Requirement already satisfied: wurlitzer in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow-decision-forests>=1.5.0->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (3.1.1)\n",
|
||||||
|
"Requirement already satisfied: ydf>=0.11.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from tensorflow-decision-forests>=1.5.0->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (0.16.0)\n",
|
||||||
|
"Requirement already satisfied: markupsafe>=2.1.1 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from werkzeug>=1.0.1->tensorboard~=2.19.0->tensorflow==2.19.0->-r requirements.txt (line 1)) (3.0.3)\n",
|
||||||
|
"Requirement already satisfied: etils[epath,epy] in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from orbax-checkpoint->flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (1.14.0)\n",
|
||||||
|
"Requirement already satisfied: prometheus-client>=0.20.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from orbax-checkpoint->flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (0.25.0)\n",
|
||||||
|
"Requirement already satisfied: aiofiles in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from orbax-checkpoint->flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (25.1.0)\n",
|
||||||
|
"Requirement already satisfied: humanize in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from orbax-checkpoint->flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (4.15.0)\n",
|
||||||
|
"Requirement already satisfied: simplejson>=3.16.0 in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from orbax-checkpoint->flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (4.1.1)\n",
|
||||||
|
"Requirement already satisfied: psutil in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from orbax-checkpoint->flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (7.2.2)\n",
|
||||||
|
"Requirement already satisfied: uvloop in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from orbax-checkpoint->flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (0.22.1)\n",
|
||||||
|
"Requirement already satisfied: fsspec in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from etils[epath,epy]->orbax-checkpoint->flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (2026.4.0)\n",
|
||||||
|
"Requirement already satisfied: zipp in /home/asephs/ZeaVis-Edu/.venv/lib/python3.12/site-packages (from etils[epath,epy]->orbax-checkpoint->flax>=0.7.2->tensorflowjs==4.22.0->-r requirements.txt (line 2)) (4.1.0)\n",
|
||||||
|
"Using cached matplotlib-3.10.9-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (8.8 MB)\n",
|
||||||
|
"Using cached seaborn-0.13.2-py3-none-any.whl (294 kB)\n",
|
||||||
|
"Using cached pillow-12.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (7.1 MB)\n",
|
||||||
|
"Using cached split_folders-0.6.1-py3-none-any.whl (13 kB)\n",
|
||||||
|
"Using cached scikit_learn-1.9.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (9.1 MB)\n",
|
||||||
|
"Using cached contourpy-1.3.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (362 kB)\n",
|
||||||
|
"Using cached cycler-0.12.1-py3-none-any.whl (8.3 kB)\n",
|
||||||
|
"Using cached fonttools-4.63.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (5.0 MB)\n",
|
||||||
|
"Using cached joblib-1.5.3-py3-none-any.whl (309 kB)\n",
|
||||||
|
"Using cached kiwisolver-1.5.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (1.5 MB)\n",
|
||||||
|
"Using cached narwhals-2.22.1-py3-none-any.whl (454 kB)\n",
|
||||||
|
"Using cached pyparsing-3.3.2-py3-none-any.whl (122 kB)\n",
|
||||||
|
"Using cached threadpoolctl-3.6.0-py3-none-any.whl (18 kB)\n",
|
||||||
|
"Installing collected packages: threadpoolctl, split-folders, pyparsing, pillow, narwhals, kiwisolver, joblib, fonttools, cycler, contourpy, scikit-learn, matplotlib, seaborn\n",
|
||||||
|
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13/13\u001b[0m [seaborn]2/13\u001b[0m [seaborn]ib]n]\n",
|
||||||
|
"\u001b[1A\u001b[2KSuccessfully installed contourpy-1.3.3 cycler-0.12.1 fonttools-4.63.0 joblib-1.5.3 kiwisolver-1.5.0 matplotlib-3.10.9 narwhals-2.22.1 pillow-12.2.0 pyparsing-3.3.2 scikit-learn-1.9.0 seaborn-0.13.2 split-folders-0.6.1 threadpoolctl-3.6.0\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"!pip install -q split-folders"
|
"!pip install -r requirements.txt"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/"
|
"base_uri": "https://localhost:8080/"
|
||||||
@@ -30,38 +147,8 @@
|
|||||||
"id": "dNC9QMXh1mWq",
|
"id": "dNC9QMXh1mWq",
|
||||||
"outputId": "132f1b20-f2b3-4acc-a0f5-7464e74ca613"
|
"outputId": "132f1b20-f2b3-4acc-a0f5-7464e74ca613"
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
"source": "import os\nimport shutil\nimport zipfile\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport splitfolders\nfrom PIL import Image\n\nimport tensorflow as tf\nfrom tensorflow.keras import layers, models, callbacks\nfrom tensorflow.keras.applications import EfficientNetV2B0\nfrom sklearn.metrics import classification_report, confusion_matrix, multilabel_confusion_matrix\n\n# Detect environment: Colab or local\ntry:\n from google.colab import drive\nLine truncated
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"TensorFlow Version: 2.20.0\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"import os\n",
|
|
||||||
"import shutil\n",
|
|
||||||
"import numpy as np\n",
|
|
||||||
"import matplotlib.pyplot as plt\n",
|
|
||||||
"import seaborn as sns\n",
|
|
||||||
"import splitfolders\n",
|
|
||||||
"import tarfile\n",
|
|
||||||
"import zipfile\n",
|
|
||||||
"from PIL import Image\n",
|
|
||||||
"\n",
|
|
||||||
"from pathlib import Path\n",
|
|
||||||
"from PIL import Image\n",
|
|
||||||
"from google.colab import drive\n",
|
|
||||||
"\n",
|
|
||||||
"\n",
|
|
||||||
"import tensorflow as tf\n",
|
|
||||||
"from tensorflow.keras import layers, models, callbacks\n",
|
|
||||||
"from tensorflow.keras.applications import EfficientNetV2B0\n",
|
|
||||||
"from sklearn.metrics import classification_report, confusion_matrix\n",
|
|
||||||
"\n",
|
|
||||||
"print(f\"TensorFlow Version: {tf.__version__}\")"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
@@ -74,7 +161,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/"
|
"base_uri": "https://localhost:8080/"
|
||||||
@@ -82,46 +169,8 @@
|
|||||||
"id": "bsGJEEFs7Flg",
|
"id": "bsGJEEFs7Flg",
|
||||||
"outputId": "30228ce8-1b64-47f5-93f7-30632b2af1c5"
|
"outputId": "30228ce8-1b64-47f5-93f7-30632b2af1c5"
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
"source": "if IS_COLAB:\n drive.mount('/content/drive')\n archive_path = '/content/drive/MyDrive/jagung/dataset_jagung.zip'\n destination_path = '/content/dataset_jagung.zip'\n extract_path = '/content/dataset'\nelse:\n # Local: dataset assumed at Machine_Learning/dataset_jagung.zip\n base = os.getcwd()\n archive_path = os.path.join(base, 'dataset_jagung.zip')\n destination_path = archive_path # no copy needed\n extract_path = os.path.join(base, 'dataset')\n\nif oLine truncated
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Mounted at /content/drive\n",
|
|
||||||
"Moving ZIP file to /content...\n",
|
|
||||||
"File successfully moved.\n",
|
|
||||||
"Extracting dataset...\n",
|
|
||||||
"Extraction completed!\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"drive.mount('/content/drive')\n",
|
|
||||||
"\n",
|
|
||||||
"archive_path = '/content/drive/MyDrive/jagung/dataset_jagung.zip'\n",
|
|
||||||
"destination_path = '/content/dataset_jagung.zip'\n",
|
|
||||||
"extract_path = '/content/dataset'\n",
|
|
||||||
"\n",
|
|
||||||
"if os.path.exists(archive_path):\n",
|
|
||||||
" print(\"Moving ZIP file to /content...\")\n",
|
|
||||||
" shutil.copy(archive_path, destination_path)\n",
|
|
||||||
" print(\"File successfully moved.\")\n",
|
|
||||||
"else:\n",
|
|
||||||
" print(f\"Error: File not found at {archive_path}\")\n",
|
|
||||||
"\n",
|
|
||||||
"if os.path.exists(destination_path):\n",
|
|
||||||
" if not os.path.exists(extract_path) or len(os.listdir(extract_path)) == 0:\n",
|
|
||||||
" os.makedirs(extract_path, exist_ok=True)\n",
|
|
||||||
" print(\"Extracting dataset...\")\n",
|
|
||||||
" try:\n",
|
|
||||||
" with zipfile.ZipFile(destination_path, 'r') as zip_ref:\n",
|
|
||||||
" zip_ref.extractall(path=extract_path)\n",
|
|
||||||
" print(\"Extraction completed!\")\n",
|
|
||||||
" except Exception as e:\n",
|
|
||||||
" print(f\"Extraction failed: {e}\")\n",
|
|
||||||
" else:\n",
|
|
||||||
" print(\"Dataset is already extracted and ready for use.\")\n"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
@@ -134,7 +183,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/"
|
"base_uri": "https://localhost:8080/"
|
||||||
@@ -142,42 +191,8 @@
|
|||||||
"id": "bIPb9DIX1spd",
|
"id": "bIPb9DIX1spd",
|
||||||
"outputId": "422957b6-c1e7-4f65-8834-14673b50a70e"
|
"outputId": "422957b6-c1e7-4f65-8834-14673b50a70e"
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
"source": "if IS_COLAB:\n dataset_path = \"/content/dataset/dataset_jagung_v1\"\nelse:\n dataset_path = os.path.join(extract_path, \"dataset_jagung_v1\")\n\ndef clean_image_data(directory):\n removed_count = 0\n for root, dirs, files in os.walk(directory):\n for file in files:\n file_path = os.path.join(root, file)\n try:\n img = Image.open(file_path)\n img.verify()\n\n img = Image.open(file_path)\n Line truncated
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Starting data cleanup process...\n",
|
|
||||||
"Cleanup completed. Total of 0 problematic files removed.\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"dataset_path = \"/content/dataset/dataset_jagung_v1\"\n",
|
|
||||||
"\n",
|
|
||||||
"def clean_image_data(directory):\n",
|
|
||||||
" removed_count = 0\n",
|
|
||||||
" for root, dirs, files in os.walk(directory):\n",
|
|
||||||
" for file in files:\n",
|
|
||||||
" file_path = os.path.join(root, file)\n",
|
|
||||||
" try:\n",
|
|
||||||
" img = Image.open(file_path)\n",
|
|
||||||
" img.verify()\n",
|
|
||||||
"\n",
|
|
||||||
" img = Image.open(file_path)\n",
|
|
||||||
" if img.mode != 'RGB':\n",
|
|
||||||
" img = img.convert('RGB')\n",
|
|
||||||
" img.save(file_path)\n",
|
|
||||||
" except Exception as e:\n",
|
|
||||||
" print(f\"Removing corrupt/invalid file: {file_path}\")\n",
|
|
||||||
" os.remove(file_path)\n",
|
|
||||||
" removed_count += 1\n",
|
|
||||||
" return removed_count\n",
|
|
||||||
"\n",
|
|
||||||
"print(\"Starting data cleanup process...\")\n",
|
|
||||||
"removed = clean_image_data(dataset_path)\n",
|
|
||||||
"print(f\"Cleanup completed. Total of {removed} problematic files removed.\")\n"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
@@ -190,7 +205,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/"
|
"base_uri": "https://localhost:8080/"
|
||||||
@@ -198,52 +213,8 @@
|
|||||||
"id": "8Zg2hJw4a3RJ",
|
"id": "8Zg2hJw4a3RJ",
|
||||||
"outputId": "3daeef44-6e99-48d4-da8e-53f7f431a550"
|
"outputId": "3daeef44-6e99-48d4-da8e-53f7f431a550"
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
"source": "if IS_COLAB:\n output_dir = \"/content/dataset_split\"\nelse:\n output_dir = os.path.join(os.getcwd(), \"dataset_split\")\n\nif os.path.exists(output_dir):\n shutil.rmtree(output_dir)\n\nprint(\"Splitting dataset into Train, Validation, and Test...\")\nsplitfolders.ratio(dataset_path, output=output_dir,\n seed=42, ratio=(0.7, 0.15, 0.15),\n group_prefix=None, move=False)\nprint(\"Dataset splitting completed.\")\n\ntrain_dir = os.path.joLine truncated
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Splitting dataset into Train, Validation, and Test...\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Copying files: 7106 files [01:11, 99.29 files/s] "
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Dataset splitting completed.\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"output_dir = \"/content/dataset_split\"\n",
|
|
||||||
"\n",
|
|
||||||
"if os.path.exists(output_dir):\n",
|
|
||||||
" shutil.rmtree(output_dir)\n",
|
|
||||||
"\n",
|
|
||||||
"print(\"Splitting dataset into Train, Validation, and Test...\")\n",
|
|
||||||
"splitfolders.ratio(dataset_path, output=output_dir,\n",
|
|
||||||
" seed=42, ratio=(0.7, 0.15, 0.15),\n",
|
|
||||||
" group_prefix=None, move=False)\n",
|
|
||||||
"print(\"Dataset splitting completed.\")\n",
|
|
||||||
"\n",
|
|
||||||
"train_dir = os.path.join(output_dir, 'train')\n",
|
|
||||||
"val_dir = os.path.join(output_dir, 'val')\n",
|
|
||||||
"test_dir = os.path.join(output_dir, 'test')"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
@@ -256,7 +227,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/"
|
"base_uri": "https://localhost:8080/"
|
||||||
@@ -264,19 +235,7 @@
|
|||||||
"id": "rNU4YGv61wFX",
|
"id": "rNU4YGv61wFX",
|
||||||
"outputId": "beda9f63-d52a-46dd-a28c-6d1ac17e7169"
|
"outputId": "beda9f63-d52a-46dd-a28c-6d1ac17e7169"
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Found 4973 files belonging to 4 classes.\n",
|
|
||||||
"Found 1063 files belonging to 4 classes.\n",
|
|
||||||
"Found 1070 files belonging to 4 classes.\n",
|
|
||||||
"Number of classes: 4\n",
|
|
||||||
"Class names: ['Bercak Daun', 'Daun Sehat', 'Karat Daun', 'hawar daun']\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"BATCH_SIZE = 32\n",
|
"BATCH_SIZE = 32\n",
|
||||||
"IMG_SIZE = (224, 224)\n",
|
"IMG_SIZE = (224, 224)\n",
|
||||||
@@ -328,7 +287,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 7,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/",
|
"base_uri": "https://localhost:8080/",
|
||||||
@@ -337,18 +296,7 @@
|
|||||||
"id": "tc8SYmZH3lGS",
|
"id": "tc8SYmZH3lGS",
|
||||||
"outputId": "44f07316-12d9-41a7-8069-5b108a335a18"
|
"outputId": "44f07316-12d9-41a7-8069-5b108a335a18"
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"image/png": "iVBORw0KGgoAAAANSUhEUgAABJEAAAJRCAYAAAD1diY8AAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQABAABJREFUeJzs/XncJVdV74+/91DTGZ+55/SQhIQMBJAwJ+RKICiIoheviMogiIAoeuGlX1/K5O/q66oXFbwXwQE1CFdBRECZrkRmMAgkkBBCku4kPfczn7GGvffvj111nqfTTToJGFqtD68m3efUqdq1q2rVWp/9WWsJ55yjRo0aNWrUqFGjRo0aNWrUqFGjRo17gfxuD6BGjRo1atSoUaNGjRo1atSoUaPG2Y+aRKpRo0aNGjVq1KhRo0aNGjVq1KhxRtQkUo0aNWrUqFGjRo0aNWrUqFGjRo0zoiaRatSoUaNGjLine truncated
|
|
||||||
"text/plain": [
|
|
||||||
"<Figure size 1200x600 with 8 Axes>"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "display_data"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"plt.figure(figsize=(12, 6))\n",
|
"plt.figure(figsize=(12, 6))\n",
|
||||||
"for images, labels in train_ds.take(1):\n",
|
"for images, labels in train_ds.take(1):\n",
|
||||||
@@ -383,7 +331,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 8,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/",
|
"base_uri": "https://localhost:8080/",
|
||||||
@@ -392,203 +340,8 @@
|
|||||||
"id": "iswHWuZb3pZj",
|
"id": "iswHWuZb3pZj",
|
||||||
"outputId": "a83c5bc3-e512-4e01-c359-0766daaa608c"
|
"outputId": "a83c5bc3-e512-4e01-c359-0766daaa608c"
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
"source": "if IS_COLAB:\n checkpoint_path = '/content/best_model/best_model.keras'\nelse:\n checkpoint_path = os.path.join(os.getcwd(), 'best_model', 'best_model.keras')\n\nif os.path.exists(checkpoint_path):\n print(f\"Loading weights from model checkpoint: {checkpoint_path}...\")\n try:\n model = models.load_model(checkpoint_path)\n except Exception as e:\n print(f\"Failed to load checkpoint model: {e}.\")\n model, base_model = build_model(NUM_CLASSES)\nLine truncated
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"No checkpoint found.\n",
|
|
||||||
"Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/efficientnet_v2/efficientnetv2-b0_notop.h5\n",
|
|
||||||
"\u001b[1m24274472/24274472\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 0us/step\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/html": [
|
|
||||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">Model: \"functional_1\"</span>\n",
|
|
||||||
"</pre>\n"
|
|
||||||
],
|
|
||||||
"text/plain": [
|
|
||||||
"\u001b[1mModel: \"functional_1\"\u001b[0m\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "display_data"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/html": [
|
|
||||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\n",
|
|
||||||
"┃<span style=\"font-weight: bold\"> Layer (type) </span>┃<span style=\"font-weight: bold\"> Output Shape </span>┃<span style=\"font-weight: bold\"> Param # </span>┃\n",
|
|
||||||
"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\n",
|
|
||||||
"│ input_layer_2 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">InputLayer</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">224</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">224</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>) │ <span style=\"color: #00af00; text-decoration-color: #0Line truncated
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ data_augmentation (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Sequential</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">224</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">224</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>) │ <span style=\"color: #00af00; text-decoration-color: #0Line truncated
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ efficientnetv2-b0 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Functional</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">7</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">7</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">1280</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">Line truncated
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ conv2d (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Conv2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">7</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">7</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">512</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">Line truncated
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ batch_normalization │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">7</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">7</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">512</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">2,048</span> │\n",
|
|
||||||
"│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ max_pooling2d (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">MaxPooling2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">512</span>) │ <span style=\"color: #00af00; text-decoration-color: #0Line truncated
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ dropout (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dropout</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">512</span>) │ <span style=\"color: #00af00; text-decoration-color: #0Line truncated
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ conv2d_1 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Conv2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">Line truncated
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ batch_normalization_1 │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">1,024</span> │\n",
|
|
||||||
"│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ global_average_pooling2d │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
|
|
||||||
"│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">GlobalAveragePooling2D</span>) │ │ │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ dropout_1 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dropout</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ dense (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">1024</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">263,168</span> │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ batch_normalization_2 │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">1024</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">4,096</span> │\n",
|
|
||||||
"│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ dropout_2 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dropout</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">1024</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ dense_1 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">4</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">4,100</span> │\n",
|
|
||||||
"└─────────────────────────────────┴────────────────────────┴───────────────┘\n",
|
|
||||||
"</pre>\n"
|
|
||||||
],
|
|
||||||
"text/plain": [
|
|
||||||
"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\n",
|
|
||||||
"┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\n",
|
|
||||||
"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\n",
|
|
||||||
"│ input_layer_2 (\u001b[38;5;33mInputLayer\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m224\u001b[0m, \u001b[38;5;34m224\u001b[0m, \u001b[38;5;34m3\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ data_augmentation (\u001b[38;5;33mSequential\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m224\u001b[0m, \u001b[38;5;34m224\u001b[0m, \u001b[38;5;34m3\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ efficientnetv2-b0 (\u001b[38;5;33mFunctional\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m7\u001b[0m, \u001b[38;5;34m7\u001b[0m, \u001b[38;5;34m1280\u001b[0m) │ \u001b[38;5;34m5,919,312\u001b[0m │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ conv2d (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m7\u001b[0m, \u001b[38;5;34m7\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m5,898,752\u001b[0m │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ batch_normalization │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m7\u001b[0m, \u001b[38;5;34m7\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │\n",
|
|
||||||
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ max_pooling2d (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3\u001b[0m, \u001b[38;5;34m3\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ dropout (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3\u001b[0m, \u001b[38;5;34m3\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ conv2d_1 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3\u001b[0m, \u001b[38;5;34m3\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,179,904\u001b[0m │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ batch_normalization_1 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3\u001b[0m, \u001b[38;5;34m3\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,024\u001b[0m │\n",
|
|
||||||
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ global_average_pooling2d │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
|
|
||||||
"│ (\u001b[38;5;33mGlobalAveragePooling2D\u001b[0m) │ │ │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ dropout_1 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ dense (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m263,168\u001b[0m │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ batch_normalization_2 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m4,096\u001b[0m │\n",
|
|
||||||
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ dropout_2 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
|
|
||||||
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
|
||||||
"│ dense_1 (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m4\u001b[0m) │ \u001b[38;5;34m4,100\u001b[0m │\n",
|
|
||||||
"└─────────────────────────────────┴────────────────────────┴───────────────┘\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "display_data"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/html": [
|
|
||||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Total params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">13,272,404</span> (50.63 MB)\n",
|
|
||||||
"</pre>\n"
|
|
||||||
],
|
|
||||||
"text/plain": [
|
|
||||||
"\u001b[1m Total params: \u001b[0m\u001b[38;5;34m13,272,404\u001b[0m (50.63 MB)\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "display_data"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/html": [
|
|
||||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">7,349,508</span> (28.04 MB)\n",
|
|
||||||
"</pre>\n"
|
|
||||||
],
|
|
||||||
"text/plain": [
|
|
||||||
"\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m7,349,508\u001b[0m (28.04 MB)\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "display_data"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/html": [
|
|
||||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Non-trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">5,922,896</span> (22.59 MB)\n",
|
|
||||||
"</pre>\n"
|
|
||||||
],
|
|
||||||
"text/plain": [
|
|
||||||
"\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m5,922,896\u001b[0m (22.59 MB)\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "display_data"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"def build_model(num_classes):\n",
|
|
||||||
" base_model = EfficientNetV2B0(\n",
|
|
||||||
" input_shape=IMG_SIZE + (3,),\n",
|
|
||||||
" include_top=False,\n",
|
|
||||||
" weights='imagenet',\n",
|
|
||||||
" )\n",
|
|
||||||
" base_model.trainable = False\n",
|
|
||||||
"\n",
|
|
||||||
" inputs = tf.keras.Input(shape=IMG_SIZE + (3,))\n",
|
|
||||||
"\n",
|
|
||||||
" x = data_augmentation(inputs)\n",
|
|
||||||
" x = base_model(x, training=False)\n",
|
|
||||||
"\n",
|
|
||||||
" x = layers.Conv2D(512, (3, 3), padding='same', activation='swish')(x)\n",
|
|
||||||
" x = layers.BatchNormalization()(x)\n",
|
|
||||||
" x = layers.MaxPooling2D((2, 2))(x)\n",
|
|
||||||
" x = layers.Dropout(0.2)(x)\n",
|
|
||||||
"\n",
|
|
||||||
" x = layers.Conv2D(256, (3, 3), padding='same', activation='swish')(x)\n",
|
|
||||||
" x = layers.BatchNormalization()(x)\n",
|
|
||||||
"\n",
|
|
||||||
" x = layers.GlobalAveragePooling2D()(x)\n",
|
|
||||||
" x = layers.Dropout(0.3)(x)\n",
|
|
||||||
"\n",
|
|
||||||
" x = layers.Dense(1024, activation='swish')(x)\n",
|
|
||||||
" x = layers.BatchNormalization()(x)\n",
|
|
||||||
" x = layers.Dropout(0.4)(x)\n",
|
|
||||||
"\n",
|
|
||||||
" outputs = layers.Dense(num_classes, activation='sigmoid', dtype='float32')(x)\n",
|
|
||||||
"\n",
|
|
||||||
" model = models.Model(inputs, outputs)\n",
|
|
||||||
" return model, base_model\n",
|
|
||||||
"\n",
|
|
||||||
"checkpoint_path = '/content/best_model/best_model.keras'\n",
|
|
||||||
"\n",
|
|
||||||
"if os.path.exists(checkpoint_path):\n",
|
|
||||||
" print(f\"Loading weights from model checkpoint: {checkpoint_path}...\")\n",
|
|
||||||
" try:\n",
|
|
||||||
" model = models.load_model(checkpoint_path)\n",
|
|
||||||
" except Exception as e:\n",
|
|
||||||
" print(f\"Failed to load checkpoint model: {e}.\")\n",
|
|
||||||
" model, base_model = build_model(NUM_CLASSES)\n",
|
|
||||||
"else:\n",
|
|
||||||
" print(\"No checkpoint found.\")\n",
|
|
||||||
" model, base_model = build_model(NUM_CLASSES)\n",
|
|
||||||
"\n",
|
|
||||||
"model.summary()\n"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
@@ -601,7 +354,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 9,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "s4Trlvno3wny"
|
"id": "s4Trlvno3wny"
|
||||||
},
|
},
|
||||||
@@ -644,7 +397,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 10,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/"
|
"base_uri": "https://localhost:8080/"
|
||||||
@@ -652,49 +405,7 @@
|
|||||||
"id": "cq5rllO63zXA",
|
"id": "cq5rllO63zXA",
|
||||||
"outputId": "0d3c03c8-d354-4b8b-befb-ecbb68b18735"
|
"outputId": "0d3c03c8-d354-4b8b-befb-ecbb68b18735"
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Training...\n",
|
|
||||||
"Epoch 1/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m207s\u001b[0m 1s/step - accuracy: 0.9153 - loss: 0.2220 - val_accuracy: 0.9459 - val_loss: 0.1425 - learning_rate: 0.0010\n",
|
|
||||||
"Epoch 2/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m186s\u001b[0m 1s/step - accuracy: 0.9512 - loss: 0.1323 - val_accuracy: 0.9781 - val_loss: 0.0640 - learning_rate: 0.0010\n",
|
|
||||||
"Epoch 3/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m191s\u001b[0m 1s/step - accuracy: 0.9649 - loss: 0.0948 - val_accuracy: 0.9730 - val_loss: 0.0645 - learning_rate: 0.0010\n",
|
|
||||||
"Epoch 4/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m180s\u001b[0m 1s/step - accuracy: 0.9707 - loss: 0.0796 - val_accuracy: 0.9748 - val_loss: 0.0763 - learning_rate: 0.0010\n",
|
|
||||||
"Epoch 5/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 958ms/step - accuracy: 0.9725 - loss: 0.0770\n",
|
|
||||||
"Epoch 5: ReduceLROnPlateau reducing learning rate to 0.00020000000949949026.\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m191s\u001b[0m 1s/step - accuracy: 0.9733 - loss: 0.0757 - val_accuracy: 0.9661 - val_loss: 0.0838 - learning_rate: 0.0010\n",
|
|
||||||
"Epoch 6/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m185s\u001b[0m 1s/step - accuracy: 0.9778 - loss: 0.0564 - val_accuracy: 0.9824 - val_loss: 0.0445 - learning_rate: 2.0000e-04\n",
|
|
||||||
"Epoch 7/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m179s\u001b[0m 1s/step - accuracy: 0.9786 - loss: 0.0557 - val_accuracy: 0.9857 - val_loss: 0.0419 - learning_rate: 2.0000e-04\n",
|
|
||||||
"Epoch 8/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m167s\u001b[0m 1s/step - accuracy: 0.9804 - loss: 0.0534 - val_accuracy: 0.9880 - val_loss: 0.0354 - learning_rate: 2.0000e-04\n",
|
|
||||||
"Epoch 9/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m171s\u001b[0m 1s/step - accuracy: 0.9807 - loss: 0.0495 - val_accuracy: 0.9882 - val_loss: 0.0317 - learning_rate: 2.0000e-04\n",
|
|
||||||
"Epoch 10/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m179s\u001b[0m 1s/step - accuracy: 0.9842 - loss: 0.0427 - val_accuracy: 0.9894 - val_loss: 0.0319 - learning_rate: 2.0000e-04\n",
|
|
||||||
"Epoch 11/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m173s\u001b[0m 1s/step - accuracy: 0.9833 - loss: 0.0452 - val_accuracy: 0.9892 - val_loss: 0.0293 - learning_rate: 2.0000e-04\n",
|
|
||||||
"Epoch 12/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m214s\u001b[0m 1s/step - accuracy: 0.9839 - loss: 0.0413 - val_accuracy: 0.9889 - val_loss: 0.0320 - learning_rate: 2.0000e-04\n",
|
|
||||||
"Epoch 13/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m181s\u001b[0m 1s/step - accuracy: 0.9864 - loss: 0.0393 - val_accuracy: 0.9880 - val_loss: 0.0329 - learning_rate: 2.0000e-04\n",
|
|
||||||
"Epoch 14/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 1s/step - accuracy: 0.9878 - loss: 0.0355\n",
|
|
||||||
"Epoch 14: ReduceLROnPlateau reducing learning rate to 4.0000001899898055e-05.\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m246s\u001b[0m 1s/step - accuracy: 0.9877 - loss: 0.0358 - val_accuracy: 0.9885 - val_loss: 0.0340 - learning_rate: 2.0000e-04\n",
|
|
||||||
"Epoch 15/15\n",
|
|
||||||
"\u001b[1m156/156\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m176s\u001b[0m 1s/step - accuracy: 0.9866 - loss: 0.0358 - val_accuracy: 0.9897 - val_loss: 0.0326 - learning_rate: 4.0000e-05\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"model.compile(\n",
|
"model.compile(\n",
|
||||||
" optimizer=tf.keras.optimizers.Adam(learning_rate=1e-3),\n",
|
" optimizer=tf.keras.optimizers.Adam(learning_rate=1e-3),\n",
|
||||||
@@ -724,7 +435,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 11,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/",
|
"base_uri": "https://localhost:8080/",
|
||||||
@@ -733,18 +444,7 @@
|
|||||||
"id": "wOW7f13UD4wy",
|
"id": "wOW7f13UD4wy",
|
||||||
"outputId": "eff4a3d7-9ddc-4992-da43-0ab09631e47d"
|
"outputId": "eff4a3d7-9ddc-4992-da43-0ab09631e47d"
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"image/png": "iVBORw0KGgoAAAANSUhEUgAABRQAAAIQCAYAAADw0OJwAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQABAABJREFUeJzs3Xd4VGXax/HvpPeEFFIgEAglhBakKUpxF6Uoq4iAyEpRcEXBVdaGq4jsq1iQRdEF1wIuiNgQOwgIKohUKUqRHtJp6X3mvH9MMjAkQAJJJgm/z3XNNTNnnjnnPpMoJ/c8z32bDMMwEBEREREREREREakAJ0cHICIiIiIiIiIiInWHEooiIiIiIiIiIiJSYUooioiIiIiIiIiISIUpoSgiIiIiIiIiIiIVpoSiiIiIiIiIiIiIVJgSiiIiIiIiIiIiIlJhSiiKiIiIiIiIiIhIhSmhKCIiIiIiIiIiILine truncated
|
|
||||||
"text/plain": [
|
|
||||||
"<Figure size 1600x600 with 2 Axes>"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "display_data"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"def plot_history(history_1, initial_epochs):\n",
|
"def plot_history(history_1, initial_epochs):\n",
|
||||||
" acc = history_1.history['accuracy']\n",
|
" acc = history_1.history['accuracy']\n",
|
||||||
@@ -781,7 +481,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 12,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/"
|
"base_uri": "https://localhost:8080/"
|
||||||
@@ -789,23 +489,7 @@
|
|||||||
"id": "5vnDCrqLD5hT",
|
"id": "5vnDCrqLD5hT",
|
||||||
"outputId": "b4e04c95-c570-4817-cf1f-37321560c89c"
|
"outputId": "b4e04c95-c570-4817-cf1f-37321560c89c"
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Evaluating model using TTA (Test-Time Augmentation) for Multi-Label...\n",
|
|
||||||
"TTA Step 1/5\n",
|
|
||||||
"TTA Step 2/5\n",
|
|
||||||
"TTA Step 3/5\n",
|
|
||||||
"TTA Step 4/5\n",
|
|
||||||
"TTA Step 5/5\n",
|
|
||||||
"\n",
|
|
||||||
"Subset Accuracy (Exact Match) on Test Set (with TTA): 97.20%\n",
|
|
||||||
"Binary Accuracy (Per-Class Average) on Test Set (with TTA): 98.86%\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"Evaluating model using TTA (Test-Time Augmentation) for Multi-Label...\")\n",
|
"print(\"Evaluating model using TTA (Test-Time Augmentation) for Multi-Label...\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -851,7 +535,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 13,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/",
|
"base_uri": "https://localhost:8080/",
|
||||||
@@ -860,68 +544,8 @@
|
|||||||
"id": "4ea9-S50EtQ6",
|
"id": "4ea9-S50EtQ6",
|
||||||
"outputId": "f1632cab-a233-4072-d0ec-70f141f83757"
|
"outputId": "f1632cab-a233-4072-d0ec-70f141f83757"
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
"source": "print(\"\\nClassification Report (Multi-Label):\\n\")\nprint(classification_report(test_labels_true, test_preds_binary, target_names=class_names))\n\nmcm = multilabel_confusion_matrix(test_labels_true, test_preds_binary)\n\nfig, axes = plt.subplots(2, 2, figsize=(12, 10))\naxes = axes.ravel()\n\nfor i, class_name in enumerate(class_names):\n sns.heatmap(mcm[i], annot=True, fmt='d', cmap='Blues', ax=axes[i], cbar=False,\n xticklabels=['Negative', 'Positive'], yticLine truncated
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"\n",
|
|
||||||
"Classification Report (Multi-Label):\n",
|
|
||||||
"\n",
|
|
||||||
" precision recall f1-score support\n",
|
|
||||||
"\n",
|
|
||||||
" Bercak Daun 0.96 0.94 0.95 224\n",
|
|
||||||
" Daun Sehat 0.99 1.00 1.00 345\n",
|
|
||||||
" Karat Daun 0.97 0.98 0.98 259\n",
|
|
||||||
" hawar daun 0.98 0.97 0.98 242\n",
|
|
||||||
"\n",
|
|
||||||
" micro avg 0.98 0.98 0.98 1070\n",
|
|
||||||
" macro avg 0.98 0.97 0.97 1070\n",
|
|
||||||
"weighted avg 0.98 0.98 0.98 1070\n",
|
|
||||||
" samples avg 0.97 0.98 0.98 1070\n",
|
|
||||||
"\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stderr",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"/usr/local/lib/python3.12/dist-packages/sklearn/metrics/_classification.py:1565: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in samples with no predicted labels. Use `zero_division` parameter to control this behavior.\n",
|
|
||||||
" _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKUAAAPeCAYAAADd/6nHAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQAAqppJREFUeJzs3Xd0VOX69vFrEsikkQIk0kM10hTFQi+CRgFFEBERCUiXohQF9UiJCIqKFKXooRMUkSLNQxGQIgdRikjv/JQoHQwBAsnz/sGbOQyTwASSPRP8ftZiLeaZZ/a+92SY3Fyz59k2Y4wRAAAAAAAAYCEfTxcAAAAAAACAfx5CKQAAAAAAAFiOUAoAAAAAAACWI5QCAAAAAACA5QilAAAAAAAAYDlCKQAAAAAAAFiOUAoAAAAAAACWI5QCAAAAAACA5QilAAAAAAAAYDlCKcAL7N27V48//rhCQ0Nls9k0bLine truncated
|
|
||||||
"text/plain": [
|
|
||||||
"<Figure size 1200x1000 with 4 Axes>"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "display_data"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"from sklearn.metrics import multilabel_confusion_matrix\n",
|
|
||||||
"\n",
|
|
||||||
"print(\"\\nClassification Report (Multi-Label):\\n\")\n",
|
|
||||||
"print(classification_report(test_labels_true, test_preds_binary, target_names=class_names))\n",
|
|
||||||
"\n",
|
|
||||||
"mcm = multilabel_confusion_matrix(test_labels_true, test_preds_binary)\n",
|
|
||||||
"\n",
|
|
||||||
"fig, axes = plt.subplots(2, 2, figsize=(12, 10))\n",
|
|
||||||
"axes = axes.ravel()\n",
|
|
||||||
"\n",
|
|
||||||
"for i, class_name in enumerate(class_names):\n",
|
|
||||||
" sns.heatmap(mcm[i], annot=True, fmt='d', cmap='Blues', ax=axes[i], cbar=False,\n",
|
|
||||||
" xticklabels=['Negative', 'Positive'], yticklabels=['Negative', 'Positive'])\n",
|
|
||||||
" axes[i].set_title(f'Confusion Matrix: {class_name}')\n",
|
|
||||||
" axes[i].set_xlabel('Predicted')\n",
|
|
||||||
" axes[i].set_ylabel('True')\n",
|
|
||||||
"\n",
|
|
||||||
"plt.tight_layout()\n",
|
|
||||||
"plt.show()"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
@@ -931,11 +555,21 @@
|
|||||||
"provenance": []
|
"provenance": []
|
||||||
},
|
},
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "Python 3",
|
"display_name": ".venv",
|
||||||
|
"language": "python",
|
||||||
"name": "python3"
|
"name": "python3"
|
||||||
},
|
},
|
||||||
"language_info": {
|
"language_info": {
|
||||||
"name": "python"
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.12.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
Reference in new issue
Block a user