diff --git a/notebooks/script_demo.ipynb b/notebooks/script_demo.ipynb new file mode 100644 index 0000000..9f33253 --- /dev/null +++ b/notebooks/script_demo.ipynb @@ -0,0 +1,1987 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "XixWrEy_T8zQ" + }, + "source": [ + "## Setup" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "pIf4bQSJ0rnw" + }, + "source": [ + "## Run this if running on colab" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "DvkM9h3i_H4B" + }, + "outputs": [], + "source": [ + "from IPython.display import clear_output; token = input(); clear_output()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "KJUIdEY5xJuu", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "598d8c9b-fb0c-4212-cf45-df517395dee4" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Cloning into 'Deep4Life'...\n", + "remote: Enumerating objects: 680, done.\u001b[K\n", + "remote: Counting objects: 100% (412/412), done.\u001b[K\n", + "remote: Compressing objects: 100% (213/213), done.\u001b[K\n", + "remote: Total 680 (delta 244), reused 298 (delta 186), pack-reused 268\u001b[K\n", + "Receiving objects: 100% (680/680), 49.99 MiB | 7.37 MiB/s, done.\n", + "Resolving deltas: 100% (385/385), done.\n" + ] + } + ], + "source": [ + "! git clone https://$token@github.com/SzymonLukasik/Deep4Life.git" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "3kVT4bDZGm8x", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "f86e9bfc-1010-4471-c838-e65a952f7e41" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "/content/Deep4Life\n" + ] + } + ], + "source": [ + "%cd /content/Deep4Life" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Co0OYAPqKA-w", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "436b0aef-468a-4b39-ae9f-90b8510a6d81" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Collecting anndata\n", + " Downloading anndata-0.10.7-py3-none-any.whl (122 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m122.4/122.4 kB\u001b[0m \u001b[31m2.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting array-api-compat!=1.5,>1.4 (from anndata)\n", + " Downloading array_api_compat-1.6-py3-none-any.whl (36 kB)\n", + "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anndata) (1.2.1)\n", + "Requirement already satisfied: h5py>=3.1 in /usr/local/lib/python3.10/dist-packages (from anndata) (3.9.0)\n", + "Requirement already satisfied: natsort in /usr/local/lib/python3.10/dist-packages (from anndata) (8.4.0)\n", + "Requirement already satisfied: numpy>=1.23 in /usr/local/lib/python3.10/dist-packages (from anndata) (1.25.2)\n", + "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from anndata) (24.0)\n", + "Requirement already satisfied: pandas!=2.1.0rc0,!=2.1.2,>=1.4 in /usr/local/lib/python3.10/dist-packages (from anndata) (2.0.3)\n", + "Requirement already satisfied: scipy>1.8 in /usr/local/lib/python3.10/dist-packages (from anndata) (1.11.4)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas!=2.1.0rc0,!=2.1.2,>=1.4->anndata) (2.8.2)\n", + "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas!=2.1.0rc0,!=2.1.2,>=1.4->anndata) (2023.4)\n", + "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas!=2.1.0rc0,!=2.1.2,>=1.4->anndata) (2024.1)\n", + "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas!=2.1.0rc0,!=2.1.2,>=1.4->anndata) (1.16.0)\n", + "Installing collected packages: array-api-compat, anndata\n", + "Successfully installed anndata-0.10.7 array-api-compat-1.6\n" + ] + } + ], + "source": [ + "!pip install anndata" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "ThUmXuQuL7-9", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "2b7198a1-ca30-4397-9cc2-6a1fc93328cb" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Collecting pyometiff\n", + " Downloading pyometiff-1.0.0-py3-none-any.whl (37 kB)\n", + "Requirement already satisfied: lxml in /usr/local/lib/python3.10/dist-packages (from pyometiff) (4.9.4)\n", + "Requirement already satisfied: tifffile>2020.10.1 in /usr/local/lib/python3.10/dist-packages (from pyometiff) (2024.4.24)\n", + "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from pyometiff) (1.25.2)\n", + "Collecting imagecodecs (from pyometiff)\n", + " Downloading imagecodecs-2024.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (39.6 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m39.6/39.6 MB\u001b[0m \u001b[31m16.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hInstalling collected packages: imagecodecs, pyometiff\n", + "Successfully installed imagecodecs-2024.1.1 pyometiff-1.0.0\n" + ] + } + ], + "source": [ + "! pip install pyometiff" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "WecCC3T4bBKm" + }, + "source": [ + "## Imports" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "6ZeTWyb0Gd8q" + }, + "outputs": [], + "source": [ + "import pandas as pd\n", + "from pandas import DataFrame\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import scipy.stats as stats\n", + "import plotly.express as px\n", + "import plotly.graph_objects as go\n", + "import plotly.subplots as sp\n", + "import pyometiff\n", + "import os\n", + "import gdown\n", + "import json\n", + "from pathlib import Path\n", + "from sklearn.preprocessing import LabelEncoder\n", + "from sklearn.preprocessing import MinMaxScaler\n", + "from sklearn.svm import SVC, LinearSVC, NuSVC\n", + "from sklearn.model_selection import GridSearchCV\n", + "\n", + "from typing import List\n", + "from src.datasets import load_d4ls\n", + "from sklearn.model_selection import train_test_split\n", + "\n", + "pd.set_option('display.max_columns', None)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "jPucakCpTCJd" + }, + "outputs": [], + "source": [ + "%load_ext autoreload\n", + "%autoreload 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "pkmKFdXLZMcW" + }, + "outputs": [], + "source": [ + "!mkdir data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Z1K42lFyT8gM", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "a4d0641e-9907-498f-e3e8-55e919330c19" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Downloading...\n", + "From (original): https://drive.google.com/uc?id=1-0YOHE1VoTRWqfBJLHQorGcHmkhCYvqW\n", + "From (redirected): https://drive.google.com/uc?id=1-0YOHE1VoTRWqfBJLHQorGcHmkhCYvqW&confirm=t&uuid=c30ccd15-8c19-47d8-a204-1ad95489127f\n", + "To: /content/Deep4Life/train.zip\n", + "100% 843M/843M [00:15<00:00, 54.2MB/s]\n" + ] + } + ], + "source": [ + "!gdown 1-0YOHE1VoTRWqfBJLHQorGcHmkhCYvqW" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "dAlRfkGVZiGn", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "e3aacaf1-0497-4353-fdfb-cfa69c86d517" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "PosixPath('/content/Deep4Life/data')" + ] + }, + "metadata": {}, + "execution_count": 13 + } + ], + "source": [ + "load_d4ls.DATA_PATH" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "9gA56_S5UZw2", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "6865d290-2159-434c-e8d3-bdf3e09acaab" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Archive: train.zip\n", + " creating: /content/Deep4Life/data/train/\n", + " inflating: /content/Deep4Life/data/train/cell_data.h5ad \n", + " creating: /content/Deep4Life/data/train/images_masks/\n", + " creating: /content/Deep4Life/data/train/images_masks/img/\n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_LUNG_10041507-LUNG-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20201113_10062587-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_LUNG_10019062-LUNG-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_2022_WFLOW_10071582-SPECT-VAR-TIS-01-IMC-01_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20201113_10042701-GU-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20211215_10068187-SPECT-VAR-TIS-UNST-03_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210506_10062969-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10062155-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10075016-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220309_S-220107-00002_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_WFLOW_Batch20210304_10043243-GI-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220309_S-220204-00002_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210304_10057310-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220309_10086612-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210921_UPSTREAM_S-210622-00008_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220908_S-220715-00002_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210304_10067466-SPECT-VAR-TIS-UNST-03_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_10032890-THOR-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10035190-THOR-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220609_S-220218-00008_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10074830-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_LUNG_10040835-LUNG-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_UPSTREAM_10064805-E1559-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210304_10061072-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_SPECTA_LUNG_S-210607-00002_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_S-210531-00008_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_UPSTREAM_S-210510-00044_005.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210304_10069532-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210506_10074064-SPECT-VAR-TIS-UNST-03_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_S-200120-00002_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_10037785-GI-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210921_UPSTREAM_S-210622-00014_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_LUNG_10018938-LUNG-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210921_LUNG_10041543-LUNG-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_10037401-BREAS-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_2022_WFLOW_10074350-SPECT-VAR-TIS-UNST-03_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_10037093-GU-VAR-TIS-01-IMC-01_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20211215_10074348-SPECT-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_S-210531-00020_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220609_10086471-SPECT-VAR-TIS-UNST-03_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_LUNG_10022146-LUNG-VAR-TIS-01-IMC-01_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_10034293-GI-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_SPECTA_LUNG_S-210416-03057_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20201113_10041761-GU-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_UPSTREAM_S-210510-00032_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10071584-SPECT-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220908_S-220513-00020_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_UPSTREAM_S-210510-00044_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_batch20191023_10032145-THOR-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220309_S-220114-00026_005.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210304_10070084-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_2022_WFLOW_10072131-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20191023_S-190701-00035_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210506_10068594-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_2022_WFLOW_10063152-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_2022_WFLOW_10034294-GI-VAR-TIS-UNST-03_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_S-210510-00002_005.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_10037390-THOR-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_LUNG_10041517-LUNG-VAR-TIS-01-IMC-01_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220609_10089094-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210921_UPSTREAM_S-210621-00014_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_10040557-GU-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220309_S-220114-00032_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210506_UPSTREAM_10064683-E1559-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210304_10051390-GI-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20201113_10033282-GU-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_UPSTREAM_S-210510-00068_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_LUNG_10022152-LUNG-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20201113_10034034-THOR-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210506_10074065-SPECT-VAR-TIS-UNST-03_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20211215_10083973-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_SPECTA_LUNG_S-210531-00014_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20201113_10052392-BREAS-VAR-TIS-UNST-03_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_S-210531-00002_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220908_S-220729-00002_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210921_UPSTREAM_S-210622-00020_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_LUNG_10018889-LUNG-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210506_10063153-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20211215_10078052-SPECT-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210921_LUNG_10041562-LUNG-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_10037092-GU-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20201113_10041962-BREAS-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20201113_10041973-THOR-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220609_10090350-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10075572-SPECT-VAR-TIS-UNST-03_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220309_S-220204-00008_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10069534-SPECT-VAR-TIS-UNST-03_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20211215_10074347-SPECT-VAR-TIS-UNST-03_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20211215_10082071-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220609_S-220506-00008_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_10040556-GU-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_UPSTREAM_S-210413-01997_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220309_S-220121-00002_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_2022_WFLOW_10074349-SPECT-VAR-TIS-UNST-03_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10073145-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210921_UPSTREAM_S-210622-00002_007.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210506_10037407-GI-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210506_10037409-GI-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20191023_S-190805-00002_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210921_10079800-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_S-200309-00002_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20211215_10083920-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220309_10084032-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10075573-SPECT-VAR-TIS-UNST-03_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210506_UPSTREAM_10064754-E1559-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210506_10032400-GU-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20191023_10032401-HN-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210921_LUNG_10041580-LUNG-VAR-TIS-01-IMC-01_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20211215_S-210924-02654_005.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_10042698-GU-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10052390-BREAS-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210506_10070599-SPECT-VAR-TIS-01-IMC-01_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210921_LUNG_10041542-LUNG-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20211215_10083215-SPECT-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10071581-SPECT-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_LUNG_10041504-LUNG-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210921_LUNG_10041565-LUNG-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10067447-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/10068190-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_WFLOW_Batch20210304_10067564-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20200528_10037094-GU-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220908_S-220513-00020_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_2022_WFLOW_10061074-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20220609_10089821-SPECT-VAR-TIS-UNST-03_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/img/IMMUcan_Batch20210701_10071592-SPECT-VAR-TIS-UNST-03_003.tiff \n", + " creating: /content/Deep4Life/data/train/images_masks/masks/\n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_LUNG_10041507-LUNG-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20201113_10062587-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_LUNG_10019062-LUNG-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_2022_WFLOW_10071582-SPECT-VAR-TIS-01-IMC-01_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20201113_10042701-GU-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20211215_10068187-SPECT-VAR-TIS-UNST-03_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210506_10062969-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10062155-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10075016-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220309_S-220107-00002_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_WFLOW_Batch20210304_10043243-GI-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220309_S-220204-00002_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210304_10057310-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220309_10086612-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210921_UPSTREAM_S-210622-00008_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220908_S-220715-00002_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210304_10067466-SPECT-VAR-TIS-UNST-03_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_10032890-THOR-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10035190-THOR-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220609_S-220218-00008_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10074830-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_LUNG_10040835-LUNG-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_UPSTREAM_10064805-E1559-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210304_10061072-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_SPECTA_LUNG_S-210607-00002_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_S-210531-00008_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_UPSTREAM_S-210510-00044_005.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210304_10069532-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210506_10074064-SPECT-VAR-TIS-UNST-03_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_S-200120-00002_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_10037785-GI-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210921_UPSTREAM_S-210622-00014_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_LUNG_10018938-LUNG-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210921_LUNG_10041543-LUNG-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_10037401-BREAS-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_2022_WFLOW_10074350-SPECT-VAR-TIS-UNST-03_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_10037093-GU-VAR-TIS-01-IMC-01_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20211215_10074348-SPECT-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_S-210531-00020_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220609_10086471-SPECT-VAR-TIS-UNST-03_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_LUNG_10022146-LUNG-VAR-TIS-01-IMC-01_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_10034293-GI-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_SPECTA_LUNG_S-210416-03057_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20201113_10041761-GU-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_UPSTREAM_S-210510-00032_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10071584-SPECT-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220908_S-220513-00020_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_UPSTREAM_S-210510-00044_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_batch20191023_10032145-THOR-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220309_S-220114-00026_005.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210304_10070084-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_2022_WFLOW_10072131-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20191023_S-190701-00035_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210506_10068594-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_2022_WFLOW_10063152-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_2022_WFLOW_10034294-GI-VAR-TIS-UNST-03_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_S-210510-00002_005.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_10037390-THOR-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_LUNG_10041517-LUNG-VAR-TIS-01-IMC-01_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220609_10089094-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210921_UPSTREAM_S-210621-00014_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_10040557-GU-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220309_S-220114-00032_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210506_UPSTREAM_10064683-E1559-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210304_10051390-GI-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20201113_10033282-GU-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_UPSTREAM_S-210510-00068_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_LUNG_10022152-LUNG-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20201113_10034034-THOR-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210506_10074065-SPECT-VAR-TIS-UNST-03_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20211215_10083973-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_SPECTA_LUNG_S-210531-00014_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20201113_10052392-BREAS-VAR-TIS-UNST-03_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_S-210531-00002_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220908_S-220729-00002_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210921_UPSTREAM_S-210622-00020_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_LUNG_10018889-LUNG-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210506_10063153-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20211215_10078052-SPECT-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210921_LUNG_10041562-LUNG-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_10037092-GU-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20201113_10041962-BREAS-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20201113_10041973-THOR-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220609_10090350-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10075572-SPECT-VAR-TIS-UNST-03_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220309_S-220204-00008_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10069534-SPECT-VAR-TIS-UNST-03_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20211215_10074347-SPECT-VAR-TIS-UNST-03_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20211215_10082071-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220609_S-220506-00008_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_10040556-GU-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_UPSTREAM_S-210413-01997_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220309_S-220121-00002_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_2022_WFLOW_10074349-SPECT-VAR-TIS-UNST-03_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10073145-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210921_UPSTREAM_S-210622-00002_007.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210506_10037407-GI-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210506_10037409-GI-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20191023_S-190805-00002_006.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210921_10079800-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_S-200309-00002_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20211215_10083920-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220309_10084032-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10075573-SPECT-VAR-TIS-UNST-03_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210506_UPSTREAM_10064754-E1559-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210506_10032400-GU-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20191023_10032401-HN-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210921_LUNG_10041580-LUNG-VAR-TIS-01-IMC-01_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20211215_S-210924-02654_005.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_10042698-GU-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10052390-BREAS-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210506_10070599-SPECT-VAR-TIS-01-IMC-01_004.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210921_LUNG_10041542-LUNG-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20211215_10083215-SPECT-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10071581-SPECT-VAR-TIS-UNST-03_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_LUNG_10041504-LUNG-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210921_LUNG_10041565-LUNG-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10067447-SPECT-VAR-TIS-01-IMC-01_003.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/10068190-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_WFLOW_Batch20210304_10067564-SPECT-VAR-TIS-01-IMC-01_002.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20200528_10037094-GU-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220908_S-220513-00020_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_2022_WFLOW_10061074-SPECT-VAR-TIS-01-IMC-01_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20220609_10089821-SPECT-VAR-TIS-UNST-03_001.tiff \n", + " inflating: /content/Deep4Life/data/train/images_masks/masks/IMMUcan_Batch20210701_10071592-SPECT-VAR-TIS-UNST-03_003.tiff \n" + ] + } + ], + "source": [ + "!unzip train.zip -d $load_d4ls.DATA_PATH" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "A99FOYv_bGxs" + }, + "source": [ + "## Load anndata" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "NStLJgH0U77A" + }, + "outputs": [], + "source": [ + "train_anndata = load_d4ls.load_full_anndata()" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Training from the command line" + ], + "metadata": { + "id": "y_Nh0KkiEzxl" + } + }, + { + "cell_type": "code", + "source": [ + "! git checkout lukass/svm_baseline" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "U7_nZwbdE47O", + "outputId": "0730b70e-d17b-4725-ae9f-24326bb7f639" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Branch 'lukass/svm_baseline' set up to track remote branch 'lukass/svm_baseline' from 'origin'.\n", + "Switched to a new branch 'lukass/svm_baseline'\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "! git pull origin" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "lmhRP67ItPcV", + "outputId": "b81f8d64-9f99-4172-d131-a13c728ac6df" + }, + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "remote: Enumerating objects: 109, done.\u001b[K\n", + "remote: Counting objects: 1% (1/90)\u001b[K\rremote: Counting objects: 2% (2/90)\u001b[K\rremote: Counting objects: 3% (3/90)\u001b[K\rremote: Counting objects: 4% (4/90)\u001b[K\rremote: Counting objects: 5% (5/90)\u001b[K\rremote: Counting objects: 6% (6/90)\u001b[K\rremote: Counting objects: 7% (7/90)\u001b[K\rremote: Counting objects: 8% (8/90)\u001b[K\rremote: Counting objects: 10% (9/90)\u001b[K\rremote: Counting objects: 11% (10/90)\u001b[K\rremote: Counting objects: 12% (11/90)\u001b[K\rremote: Counting objects: 13% (12/90)\u001b[K\rremote: Counting objects: 14% (13/90)\u001b[K\rremote: Counting objects: 15% (14/90)\u001b[K\rremote: Counting objects: 16% (15/90)\u001b[K\rremote: Counting objects: 17% (16/90)\u001b[K\rremote: Counting objects: 18% (17/90)\u001b[K\rremote: Counting objects: 20% (18/90)\u001b[K\rremote: Counting objects: 21% (19/90)\u001b[K\rremote: Counting objects: 22% (20/90)\u001b[K\rremote: Counting objects: 23% (21/90)\u001b[K\rremote: Counting objects: 24% (22/90)\u001b[K\rremote: Counting objects: 25% (23/90)\u001b[K\rremote: Counting objects: 26% (24/90)\u001b[K\rremote: Counting objects: 27% (25/90)\u001b[K\rremote: Counting objects: 28% (26/90)\u001b[K\rremote: Counting objects: 30% (27/90)\u001b[K\rremote: Counting objects: 31% (28/90)\u001b[K\rremote: Counting objects: 32% (29/90)\u001b[K\rremote: Counting objects: 33% (30/90)\u001b[K\rremote: Counting objects: 34% (31/90)\u001b[K\rremote: Counting objects: 35% (32/90)\u001b[K\rremote: Counting objects: 36% (33/90)\u001b[K\rremote: Counting objects: 37% (34/90)\u001b[K\rremote: Counting objects: 38% (35/90)\u001b[K\rremote: Counting objects: 40% (36/90)\u001b[K\rremote: Counting objects: 41% (37/90)\u001b[K\rremote: Counting objects: 42% (38/90)\u001b[K\rremote: Counting objects: 43% (39/90)\u001b[K\rremote: Counting objects: 44% (40/90)\u001b[K\rremote: Counting objects: 45% (41/90)\u001b[K\rremote: Counting objects: 46% (42/90)\u001b[K\rremote: Counting objects: 47% (43/90)\u001b[K\rremote: Counting objects: 48% (44/90)\u001b[K\rremote: Counting objects: 50% (45/90)\u001b[K\rremote: Counting objects: 51% (46/90)\u001b[K\rremote: Counting objects: 52% (47/90)\u001b[K\rremote: Counting objects: 53% (48/90)\u001b[K\rremote: Counting objects: 54% (49/90)\u001b[K\rremote: Counting objects: 55% (50/90)\u001b[K\rremote: Counting objects: 56% (51/90)\u001b[K\rremote: Counting objects: 57% (52/90)\u001b[K\rremote: Counting objects: 58% (53/90)\u001b[K\rremote: Counting objects: 60% (54/90)\u001b[K\rremote: Counting objects: 61% (55/90)\u001b[K\rremote: Counting objects: 62% (56/90)\u001b[K\rremote: Counting objects: 63% (57/90)\u001b[K\rremote: Counting objects: 64% (58/90)\u001b[K\rremote: Counting objects: 65% (59/90)\u001b[K\rremote: Counting objects: 66% (60/90)\u001b[K\rremote: Counting objects: 67% (61/90)\u001b[K\rremote: Counting objects: 68% (62/90)\u001b[K\rremote: Counting objects: 70% (63/90)\u001b[K\rremote: Counting objects: 71% (64/90)\u001b[K\rremote: Counting objects: 72% (65/90)\u001b[K\rremote: Counting objects: 73% (66/90)\u001b[K\rremote: Counting objects: 74% (67/90)\u001b[K\rremote: Counting objects: 75% (68/90)\u001b[K\rremote: Counting objects: 76% (69/90)\u001b[K\rremote: Counting objects: 77% (70/90)\u001b[K\rremote: Counting objects: 78% (71/90)\u001b[K\rremote: Counting objects: 80% (72/90)\u001b[K\rremote: Counting objects: 81% (73/90)\u001b[K\rremote: Counting objects: 82% (74/90)\u001b[K\rremote: Counting objects: 83% (75/90)\u001b[K\rremote: Counting objects: 84% (76/90)\u001b[K\rremote: Counting objects: 85% (77/90)\u001b[K\rremote: Counting objects: 86% (78/90)\u001b[K\rremote: Counting objects: 87% (79/90)\u001b[K\rremote: Counting objects: 88% (80/90)\u001b[K\rremote: Counting objects: 90% (81/90)\u001b[K\rremote: Counting objects: 91% (82/90)\u001b[K\rremote: Counting objects: 92% (83/90)\u001b[K\rremote: Counting objects: 93% (84/90)\u001b[K\rremote: Counting objects: 94% (85/90)\u001b[K\rremote: Counting objects: 95% (86/90)\u001b[K\rremote: Counting objects: 96% (87/90)\u001b[K\rremote: Counting objects: 97% (88/90)\u001b[K\rremote: Counting objects: 98% (89/90)\u001b[K\rremote: Counting objects: 100% (90/90)\u001b[K\rremote: Counting objects: 100% (90/90), done.\u001b[K\n", + "remote: Compressing objects: 4% (1/25)\u001b[K\rremote: Compressing objects: 8% (2/25)\u001b[K\rremote: Compressing objects: 12% (3/25)\u001b[K\rremote: Compressing objects: 16% (4/25)\u001b[K\rremote: Compressing objects: 20% (5/25)\u001b[K\rremote: Compressing objects: 24% (6/25)\u001b[K\rremote: Compressing objects: 28% (7/25)\u001b[K\rremote: Compressing objects: 32% (8/25)\u001b[K\rremote: Compressing objects: 36% (9/25)\u001b[K\rremote: Compressing objects: 40% (10/25)\u001b[K\rremote: Compressing objects: 44% (11/25)\u001b[K\rremote: Compressing objects: 48% (12/25)\u001b[K\rremote: Compressing objects: 52% (13/25)\u001b[K\rremote: Compressing objects: 56% (14/25)\u001b[K\rremote: Compressing objects: 60% (15/25)\u001b[K\rremote: Compressing objects: 64% (16/25)\u001b[K\rremote: Compressing objects: 68% (17/25)\u001b[K\rremote: Compressing objects: 72% (18/25)\u001b[K\rremote: Compressing objects: 76% (19/25)\u001b[K\rremote: Compressing objects: 80% (20/25)\u001b[K\rremote: Compressing objects: 84% (21/25)\u001b[K\rremote: Compressing objects: 88% (22/25)\u001b[K\rremote: Compressing objects: 92% (23/25)\u001b[K\rremote: Compressing objects: 96% (24/25)\u001b[K\rremote: Compressing objects: 100% (25/25)\u001b[K\rremote: Compressing objects: 100% (25/25), done.\u001b[K\n", + "remote: Total 55 (delta 39), reused 40 (delta 26), pack-reused 0\u001b[K\n", + "Unpacking objects: 1% (1/55)\rUnpacking objects: 3% (2/55)\rUnpacking objects: 5% (3/55)\rUnpacking objects: 7% (4/55)\rUnpacking objects: 9% (5/55)\rUnpacking objects: 10% (6/55)\rUnpacking objects: 12% (7/55)\rUnpacking objects: 14% (8/55)\rUnpacking objects: 16% (9/55)\rUnpacking objects: 18% (10/55)\rUnpacking objects: 20% (11/55)\rUnpacking objects: 21% (12/55)\rUnpacking objects: 23% (13/55)\rUnpacking objects: 25% (14/55)\rUnpacking objects: 27% (15/55)\rUnpacking objects: 29% (16/55)\rUnpacking objects: 30% (17/55)\rUnpacking objects: 32% (18/55)\rUnpacking objects: 34% (19/55)\rUnpacking objects: 36% (20/55)\rUnpacking objects: 38% (21/55)\rUnpacking objects: 40% (22/55)\rUnpacking objects: 41% (23/55)\rUnpacking objects: 43% (24/55)\rUnpacking objects: 45% (25/55)\rUnpacking objects: 47% (26/55)\rUnpacking objects: 49% (27/55)\rUnpacking objects: 50% (28/55)\rUnpacking objects: 52% (29/55)\rUnpacking objects: 54% (30/55)\rUnpacking objects: 56% (31/55)\rUnpacking objects: 58% (32/55)\rUnpacking objects: 60% (33/55)\rUnpacking objects: 61% (34/55)\rUnpacking objects: 63% (35/55)\rUnpacking objects: 65% (36/55)\rUnpacking objects: 67% (37/55)\rUnpacking objects: 69% (38/55)\rUnpacking objects: 70% (39/55)\rUnpacking objects: 72% (40/55)\rUnpacking objects: 74% (41/55)\rUnpacking objects: 76% (42/55)\rUnpacking objects: 78% (43/55)\rUnpacking objects: 80% (44/55)\rUnpacking objects: 81% (45/55)\rUnpacking objects: 83% (46/55)\rUnpacking objects: 85% (47/55)\rUnpacking objects: 87% (48/55)\rUnpacking objects: 89% (49/55)\rUnpacking objects: 90% (50/55)\rUnpacking objects: 92% (51/55)\rUnpacking objects: 94% (52/55)\rUnpacking objects: 96% (53/55)\rUnpacking objects: 98% (54/55)\rUnpacking objects: 100% (55/55)\rUnpacking objects: 100% (55/55), 6.31 KiB | 170.00 KiB/s, done.\n", + "From https://github.com/SzymonLukasik/Deep4Life\n", + " ad7ee6b..4116c2b lukass/svm_baseline -> origin/lukass/svm_baseline\n", + " 0f7725c..efaae07 ab/stellarv2 -> origin/ab/stellarv2\n", + " 03cb31a..548f7e6 eda -> origin/eda\n", + " 3715e70..a5bd4d9 master -> origin/master\n", + "Updating ad7ee6b..4116c2b\n", + "Fast-forward\n", + " README.md | 78 \u001b[32m+++++++++++++++++++++++\u001b[m\u001b[31m-------------------------------\u001b[m\n", + " requirements.txt | 4 \u001b[32m+\u001b[m\u001b[31m--\u001b[m\n", + " src/config/sklearn_svm/svc/linear.yaml | 2 \u001b[32m+\u001b[m\u001b[31m-\u001b[m\n", + " src/config/sklearn_svm/svc/rbf.yaml | 2 \u001b[32m+\u001b[m\u001b[31m-\u001b[m\n", + " src/main.py | 2 \u001b[32m++\u001b[m\n", + " src/models/sklearn_svm.py | 3 \u001b[32m+++\u001b[m\n", + " src/train_and_validate.py | 59 \u001b[32m++++++++++++++++++++++++++++++++\u001b[m\u001b[31m---------\u001b[m\n", + " 7 files changed, 89 insertions(+), 61 deletions(-)\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "! git status" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "c90lotwxtNgr", + "outputId": "194aa12d-7cb4-46a0-c8b3-c3e669484749" + }, + "execution_count": 19, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "On branch lukass/svm_baseline\n", + "Your branch is up to date with 'origin/lukass/svm_baseline'.\n", + "\n", + "Untracked files:\n", + " (use \"git add ...\" to include in what will be committed)\n", + "\t\u001b[31mtrain.zip\u001b[m\n", + "\n", + "nothing added to commit but untracked files present (use \"git add\" to track)\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "! git checkout -- src/models/sklearn_svm.py" + ], + "metadata": { + "id": "XCY0AODmuQFY" + }, + "execution_count": 15, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "! git branch" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "7b-ETsduHvws", + "outputId": "2888093e-2082-4eac-a735-66e7ded13c21" + }, + "execution_count": 20, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "* \u001b[32mlukass/svm_baseline\u001b[m\n", + " master\u001b[m\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "! pip install scanpy" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "xJl5AJxuLeR1", + "outputId": "b520d0fb-0cf4-43c6-edbf-50343c4cc998" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Collecting scanpy\n", + " Downloading scanpy-1.10.1-py3-none-any.whl (2.1 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m10.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: anndata>=0.8 in /usr/local/lib/python3.10/dist-packages (from scanpy) (0.10.7)\n", + "Requirement already satisfied: h5py>=3.1 in /usr/local/lib/python3.10/dist-packages (from scanpy) (3.9.0)\n", + "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from scanpy) (1.4.2)\n", + "Collecting legacy-api-wrap>=1.4 (from scanpy)\n", + " Downloading legacy_api_wrap-1.4-py3-none-any.whl (15 kB)\n", + "Requirement already satisfied: matplotlib>=3.6 in /usr/local/lib/python3.10/dist-packages (from scanpy) (3.7.1)\n", + "Requirement already satisfied: natsort in /usr/local/lib/python3.10/dist-packages (from scanpy) (8.4.0)\n", + "Requirement already satisfied: networkx>=2.7 in /usr/local/lib/python3.10/dist-packages (from scanpy) (3.3)\n", + "Requirement already satisfied: numba>=0.56 in /usr/local/lib/python3.10/dist-packages (from scanpy) (0.58.1)\n", + "Requirement already satisfied: numpy>=1.23 in /usr/local/lib/python3.10/dist-packages (from scanpy) (1.25.2)\n", + "Requirement already satisfied: packaging>=21.3 in /usr/local/lib/python3.10/dist-packages (from scanpy) (24.0)\n", + "Requirement already satisfied: pandas>=1.5 in /usr/local/lib/python3.10/dist-packages (from scanpy) (2.0.3)\n", + "Requirement already satisfied: patsy in /usr/local/lib/python3.10/dist-packages (from scanpy) (0.5.6)\n", + "Collecting pynndescent>=0.5 (from scanpy)\n", + " Downloading pynndescent-0.5.12-py3-none-any.whl (56 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.8/56.8 kB\u001b[0m \u001b[31m6.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: scikit-learn>=0.24 in /usr/local/lib/python3.10/dist-packages (from scanpy) (1.2.2)\n", + "Requirement already satisfied: scipy>=1.8 in /usr/local/lib/python3.10/dist-packages (from scanpy) (1.11.4)\n", + "Requirement already satisfied: seaborn>=0.13 in /usr/local/lib/python3.10/dist-packages (from scanpy) (0.13.1)\n", + "Collecting session-info (from scanpy)\n", + " Downloading session_info-1.0.0.tar.gz (24 kB)\n", + " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + "Requirement already satisfied: statsmodels>=0.13 in /usr/local/lib/python3.10/dist-packages (from scanpy) (0.14.2)\n", + "Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from scanpy) (4.66.4)\n", + "Collecting umap-learn!=0.5.0,>=0.5 (from scanpy)\n", + " Downloading umap_learn-0.5.6-py3-none-any.whl (85 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m85.7/85.7 kB\u001b[0m \u001b[31m7.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: array-api-compat!=1.5,>1.4 in /usr/local/lib/python3.10/dist-packages (from anndata>=0.8->scanpy) (1.6)\n", + "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anndata>=0.8->scanpy) (1.2.1)\n", + "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.6->scanpy) (1.2.1)\n", + "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.6->scanpy) (0.12.1)\n", + "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.6->scanpy) (4.51.0)\n", + "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.6->scanpy) (1.4.5)\n", + "Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.6->scanpy) (9.4.0)\n", + "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.6->scanpy) (3.1.2)\n", + "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib>=3.6->scanpy) (2.8.2)\n", + "Requirement already satisfied: llvmlite<0.42,>=0.41.0dev0 in /usr/local/lib/python3.10/dist-packages (from numba>=0.56->scanpy) (0.41.1)\n", + "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=1.5->scanpy) (2023.4)\n", + "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=1.5->scanpy) (2024.1)\n", + "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=0.24->scanpy) (3.5.0)\n", + "Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from patsy->scanpy) (1.16.0)\n", + "Collecting stdlib_list (from session-info->scanpy)\n", + " Downloading stdlib_list-0.10.0-py3-none-any.whl (79 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m79.8/79.8 kB\u001b[0m \u001b[31m9.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hBuilding wheels for collected packages: session-info\n", + " Building wheel for session-info (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + " Created wheel for session-info: filename=session_info-1.0.0-py3-none-any.whl size=8026 sha256=1198ad6ab3f3ef7b1b1dcec280e1c78b4fc62cc2459591eee8c4caa460f09dd0\n", + " Stored in directory: /root/.cache/pip/wheels/6a/aa/b9/eb5d4031476ec10802795b97ccf937b9bd998d68a9b268765a\n", + "Successfully built session-info\n", + "Installing collected packages: stdlib_list, legacy-api-wrap, session-info, pynndescent, umap-learn, scanpy\n", + "Successfully installed legacy-api-wrap-1.4 pynndescent-0.5.12 scanpy-1.10.1 session-info-1.0.0 stdlib_list-0.10.0 umap-learn-0.5.6\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "! pip install scikit_learn==1.4.2" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 356 + }, + "id": "7pa_EJIihoZK", + "outputId": "2f32c4d3-6842-473f-d4f6-8db837dc16c4" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Collecting scikit_learn==1.4.2\n", + " Downloading scikit_learn-1.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.1 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.1/12.1 MB\u001b[0m \u001b[31m35.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: numpy>=1.19.5 in /usr/local/lib/python3.10/dist-packages (from scikit_learn==1.4.2) (1.25.2)\n", + "Requirement already satisfied: scipy>=1.6.0 in /usr/local/lib/python3.10/dist-packages (from scikit_learn==1.4.2) (1.11.4)\n", + "Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.10/dist-packages (from scikit_learn==1.4.2) (1.4.2)\n", + "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit_learn==1.4.2) (3.5.0)\n", + "Installing collected packages: scikit_learn\n", + " Attempting uninstall: scikit_learn\n", + " Found existing installation: scikit-learn 1.2.2\n", + " Uninstalling scikit-learn-1.2.2:\n", + " Successfully uninstalled scikit-learn-1.2.2\n", + "Successfully installed scikit_learn-1.4.2\n" + ] + }, + { + "output_type": "display_data", + "data": { + "application/vnd.colab-display-data+json": { + "pip_warning": { + "packages": [ + "sklearn" + ] + }, + "id": "8e79f244a94d455983fc95dd61b9b3ff" + } + }, + "metadata": {} + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "PmOxKYgQ8Gfz" + }, + "source": [ + "## SVM Baseline" + ] + }, + { + "cell_type": "code", + "source": [ + "!python3 src/train_and_validate.py --method sklearn_svm/svc --config linear" + ], + "metadata": { + "id": "Xv81r_beGUZi", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "4da57c12-c779-4baf-94db-cac3fc6cbbfd" + }, + "execution_count": 18, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Validation accuracy of 0 fold: 0.9403075405720434\n", + "Validation accuracy of 1 fold: 0.9252561247216036\n", + "Validation accuracy of 2 fold: 0.9370896391152503\n", + "Validation accuracy of 3 fold: 0.954309122420041\n", + "Validation accuracy of 4 fold: 0.9147199970123056\n", + "Config saved to: /content/Deep4Life/results/sklearn_svm/svc/linear_2024-05-08_20-33-44_seed_42_folds_5/config.yaml\n", + "Metrics saved to: /content/Deep4Life/results/sklearn_svm/svc/linear_2024-05-08_20-33-44_seed_42_folds_5/metrics.json\n", + "Retraining model...\n", + "Model saved to: /content/Deep4Life/results/sklearn_svm/svc/linear_2024-05-08_20-33-44_seed_42_folds_5/saved_model.joblib\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!python3 src/train_and_validate.py --method sklearn_svm/svc --config linear" + ], + "metadata": { + "id": "lnB8t7nqBG0O" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Other methods" + ], + "metadata": { + "id": "vZ3omETaC0Ne" + } + }, + { + "cell_type": "code", + "source": [ + "! git fetch origin master" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "i4-a0n-JC51Q", + "outputId": "2013b64e-4a3b-43af-ac8e-73fa753d8aee" + }, + "execution_count": 274, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "From https://github.com/SzymonLukasik/Deep4Life\n", + " * branch master -> FETCH_HEAD\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!python3 src/train_and_validate.py --method xgboost --config standard" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "c9QpTjjMC_kQ", + "outputId": "c20d7916-78b6-42d2-c07f-07552cc897df" + }, + "execution_count": 24, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Validation accuracy of 0 fold: 0.9465614632834215\n", + "Validation accuracy of 1 fold: 0.9298663697104677\n", + "Validation accuracy of 2 fold: 0.949499417927823\n", + "Validation accuracy of 3 fold: 0.9634866866236017\n", + "Validation accuracy of 4 fold: 0.9142905159374825\n", + "Config saved to: /content/Deep4Life/results/xgboost/standard_2024-05-08_21-15-37_seed_42_folds_5/config.yaml\n", + "Metrics saved to: /content/Deep4Life/results/xgboost/standard_2024-05-08_21-15-37_seed_42_folds_5/metrics.json\n", + "Retraining model...\n", + "Model saved to: /content/Deep4Life/results/xgboost/standard_2024-05-08_21-15-37_seed_42_folds_5/saved_model.json\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!python3 src/train_and_validate.py --method sklearn_mlp --config standard" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "uxLsqYmUEipi", + "outputId": "02b657d6-85c6-4534-f723-9a3cac479d1e" + }, + "execution_count": 25, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Iteration 1, loss = 0.31067227\n", + "Validation score: 0.931054\n", + "Iteration 2, loss = 0.18925858\n", + "Validation score: 0.941773\n", + "Iteration 3, loss = 0.16341107\n", + "Validation score: 0.944271\n", + "Iteration 4, loss = 0.14912965\n", + "Validation score: 0.949579\n", + "Iteration 5, loss = 0.13604193\n", + "Validation score: 0.954782\n", + "/usr/local/lib/python3.10/dist-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (5) reached and the optimization hasn't converged yet.\n", + " warnings.warn(\n", + "Validation accuracy of 0 fold: 0.9371693714695598\n", + "Iteration 1, loss = 0.29911168\n", + "Validation score: 0.932986\n", + "Iteration 2, loss = 0.18063588\n", + "Validation score: 0.936686\n", + "Iteration 3, loss = 0.15690637\n", + "Validation score: 0.944971\n", + "Iteration 4, loss = 0.14170221\n", + "Validation score: 0.950130\n", + "Iteration 5, loss = 0.13136569\n", + "Validation score: 0.948775\n", + "/usr/local/lib/python3.10/dist-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (5) reached and the optimization hasn't converged yet.\n", + " warnings.warn(\n", + "Validation accuracy of 1 fold: 0.9191314031180401\n", + "Iteration 1, loss = 0.30200358\n", + "Validation score: 0.930720\n", + "Iteration 2, loss = 0.18364342\n", + "Validation score: 0.937684\n", + "Iteration 3, loss = 0.15999960\n", + "Validation score: 0.937942\n", + "Iteration 4, loss = 0.14541076\n", + "Validation score: 0.949342\n", + "Iteration 5, loss = 0.13417762\n", + "Validation score: 0.948001\n", + "/usr/local/lib/python3.10/dist-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (5) reached and the optimization hasn't converged yet.\n", + " warnings.warn(\n", + "Validation accuracy of 2 fold: 0.9343189755529686\n", + "Iteration 1, loss = 0.33051585\n", + "Validation score: 0.930008\n", + "Iteration 2, loss = 0.20270504\n", + "Validation score: 0.930330\n", + "Iteration 3, loss = 0.17788215\n", + "Validation score: 0.939791\n", + "Iteration 4, loss = 0.15982958\n", + "Validation score: 0.942748\n", + "Iteration 5, loss = 0.15075608\n", + "Validation score: 0.944361\n", + "/usr/local/lib/python3.10/dist-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (5) reached and the optimization hasn't converged yet.\n", + " warnings.warn(\n", + "Validation accuracy of 3 fold: 0.9568693871120214\n", + "Iteration 1, loss = 0.28750749\n", + "Validation score: 0.936750\n", + "Iteration 2, loss = 0.17089837\n", + "Validation score: 0.943462\n", + "Iteration 3, loss = 0.14947571\n", + "Validation score: 0.945318\n", + "Iteration 4, loss = 0.13550672\n", + "Validation score: 0.951703\n", + "Iteration 5, loss = 0.12424149\n", + "Validation score: 0.955850\n", + "/usr/local/lib/python3.10/dist-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (5) reached and the optimization hasn't converged yet.\n", + " warnings.warn(\n", + "Validation accuracy of 4 fold: 0.9063357795081508\n", + "Config saved to: /content/Deep4Life/results/sklearn_mlp/standard_2024-05-08_21-20-31_seed_42_folds_5/config.yaml\n", + "Metrics saved to: /content/Deep4Life/results/sklearn_mlp/standard_2024-05-08_21-20-31_seed_42_folds_5/metrics.json\n", + "Retraining model...\n", + "Iteration 1, loss = 0.28656257\n", + "Validation score: 0.928927\n", + "Iteration 2, loss = 0.18062103\n", + "Validation score: 0.938682\n", + "Iteration 3, loss = 0.15653032\n", + "Validation score: 0.949620\n", + "Iteration 4, loss = 0.14140152\n", + "Validation score: 0.948860\n", + "Iteration 5, loss = 0.13147049\n", + "Validation score: 0.950633\n", + "/usr/local/lib/python3.10/dist-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (5) reached and the optimization hasn't converged yet.\n", + " warnings.warn(\n", + "Model saved to: /content/Deep4Life/results/sklearn_mlp/standard_2024-05-08_21-20-31_seed_42_folds_5/saved_model.joblib\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!python3 src/train_and_validate.py --method torch_mlp --config standard" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "do1SWPEeGH4Z", + "outputId": "c99d9ea3-4e75-4b62-c34c-64bb7f56dd89" + }, + "execution_count": 26, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + " 0m: epoch 1 [################### ] 99% train loss = 0.3690642094 Validation score: 0.928713\n", + " 0m: epoch 2 [################### ] 99% train loss = 0.1922636195 Validation score: 0.939120\n", + " 0m: epoch 3 [################### ] 99% train loss = 0.1660849914 Validation score: 0.940785\n", + " 0m: epoch 4 [################### ] 99% train loss = 0.1519366081 Validation score: 0.941565\n", + " 0m: epoch 5 [################### ] 99% train loss = 0.1391868441 Validation score: 0.947757\n", + " 0m: epoch 6 [################### ] 99% train loss = 0.1322276416 Validation score: 0.951192\n", + " 0m: epoch 7 [################### ] 99% train loss = 0.1241243638 Validation score: 0.953429\n", + " 1m: epoch 8 [################### ] 99% train loss = 0.1194663133 Validation score: 0.955875\n", + " 1m: epoch 9 [################### ] 99% train loss = 0.1152636276 Validation score: 0.951764\n", + " 1m: epoch 10 [################### ] 99% train loss = 0.1106805969 Validation score: 0.957488\n", + " 1m: epoch 11 [################### ] 99% train loss = 0.1084681425 Validation score: 0.956395\n", + " 1m: epoch 12 [################### ] 99% train loss = 0.1044164556 Validation score: 0.956967\n", + " 2m: epoch 13 [################### ] 99% train loss = 0.1035649535 Validation score: 0.952076\n", + " 2m: epoch 14 [################### ] 99% train loss = 0.1015115638 Validation score: 0.958476\n", + " 2m: epoch 15 [################### ] 99% train loss = 0.0986585236 Validation score: 0.956239\n", + " 2m: epoch 16 [################### ] 99% train loss = 0.0975362928 Validation score: 0.957436\n", + " 2m: epoch 17 [################### ] 99% train loss = 0.0961759771 Validation score: 0.962171\n", + " 3m: epoch 18 [################### ] 99% train loss = 0.0927045626 Validation score: 0.960402\n", + " 3m: epoch 19 [################### ] 99% train loss = 0.0922924610 Validation score: 0.959829\n", + " 3m: epoch 20 [################### ] 99% train loss = 0.0911534113 Validation score: 0.962795\n", + " 3m: epoch 21 [################### ] 99% train loss = 0.0898393456 Validation score: 0.961026\n", + " 4m: epoch 22 [################### ] 99% train loss = 0.0883251462 Validation score: 0.962691\n", + " 4m: epoch 23 [################### ] 99% train loss = 0.0869652731 Validation score: 0.961755\n", + " 4m: epoch 24 [################### ] 99% train loss = 0.0864962192 Validation score: 0.962119\n", + " 4m: epoch 25 [################### ] 99% train loss = 0.0857826720 Validation score: 0.963368\n", + " 5m: epoch 26 [################### ] 99% train loss = 0.0846564113 Validation score: 0.963368\n", + " 5m: epoch 27 [################### ] 99% train loss = 0.0830171835 Validation score: 0.964460\n", + " 5m: epoch 28 [################### ] 99% train loss = 0.0832006829 Validation score: 0.962483\n", + " 5m: epoch 29 [################### ] 99% train loss = 0.0815865801 Validation score: 0.963888\n", + " 5m: epoch 30 [################### ] 99% train loss = 0.0805790852 Validation score: 0.963316\n", + " 6m: epoch 31 [################### ] 99% train loss = 0.0798843175 Validation score: 0.963732\n", + " 6m: epoch 32 [################### ] 99% train loss = 0.0788749308 Validation score: 0.963368\n", + " 6m: epoch 33 [################### ] 99% train loss = 0.0782745815 Validation score: 0.960818\n", + " 6m: epoch 34 [################### ] 99% train loss = 0.0780739915 Validation score: 0.961703\n", + " 6m: epoch 35 [################### ] 99% train loss = 0.0764040869 Validation score: 0.962535\n", + " 7m: epoch 36 [################### ] 99% train loss = 0.0769019479 Validation score: 0.965241\n", + " 7m: epoch 37 [################### ] 99% train loss = 0.0762382226 Validation score: 0.964200\n", + " 7m: epoch 38 [################### ] 99% train loss = 0.0758281892 Validation score: 0.963368\n", + " 7m: epoch 39 [################### ] 99% train loss = 0.0757977795 Validation score: 0.963264\n", + " 7m: epoch 40 [################### ] 99% train loss = 0.0747456052 Validation score: 0.962795\n", + "Validation accuracy of 0 fold: 0.9436474491168295\n", + " 0m: epoch 1 [################### ] 99% train loss = 0.3523827726 Validation score: 0.927462\n", + " 0m: epoch 2 [################### ] 99% train loss = 0.1878484221 Validation score: 0.941584\n", + " 0m: epoch 3 [################### ] 99% train loss = 0.1607356696 Validation score: 0.948359\n", + " 0m: epoch 4 [################### ] 99% train loss = 0.1439467343 Validation score: 0.946899\n", + " 0m: epoch 5 [################### ] 99% train loss = 0.1340393234 Validation score: 0.950756\n", + " 0m: epoch 6 [################### ] 99% train loss = 0.1268211885 Validation score: 0.952058\n", + " 0m: epoch 7 [################### ] 99% train loss = 0.1201363332 Validation score: 0.952423\n", + " 1m: epoch 8 [################### ] 99% train loss = 0.1148620862 Validation score: 0.956853\n", + " 1m: epoch 9 [################### ] 99% train loss = 0.1109501616 Validation score: 0.955967\n", + " 1m: epoch 10 [################### ] 99% train loss = 0.1076980103 Validation score: 0.955550\n", + " 1m: epoch 11 [################### ] 99% train loss = 0.1059168493 Validation score: 0.958937\n", + " 2m: epoch 12 [################### ] 99% train loss = 0.1023049580 Validation score: 0.961282\n", + " 2m: epoch 13 [################### ] 99% train loss = 0.0999869433 Validation score: 0.961230\n", + " 2m: epoch 14 [################### ] 99% train loss = 0.0976145907 Validation score: 0.959614\n", + " 2m: epoch 15 [################### ] 99% train loss = 0.0960763392 Validation score: 0.959406\n", + " 2m: epoch 16 [################### ] 99% train loss = 0.0944048663 Validation score: 0.954455\n", + " 3m: epoch 17 [################### ] 99% train loss = 0.0937541133 Validation score: 0.958781\n", + " 3m: epoch 18 [################### ] 99% train loss = 0.0910958480 Validation score: 0.960813\n", + " 3m: epoch 19 [################### ] 99% train loss = 0.0898618932 Validation score: 0.959302\n", + " 3m: epoch 20 [################### ] 99% train loss = 0.0877893181 Validation score: 0.958781\n", + " 4m: epoch 21 [################### ] 99% train loss = 0.0866027100 Validation score: 0.962533\n", + " 4m: epoch 22 [################### ] 99% train loss = 0.0859231518 Validation score: 0.958260\n", + " 4m: epoch 23 [################### ] 99% train loss = 0.0841525770 Validation score: 0.961438\n", + " 4m: epoch 24 [################### ] 99% train loss = 0.0833285526 Validation score: 0.963366\n", + " 5m: epoch 25 [################### ] 99% train loss = 0.0831453381 Validation score: 0.960657\n", + " 5m: epoch 26 [################### ] 99% train loss = 0.0822592022 Validation score: 0.961438\n", + " 5m: epoch 27 [################### ] 99% train loss = 0.0806672982 Validation score: 0.960240\n", + " 5m: epoch 28 [################### ] 99% train loss = 0.0799173701 Validation score: 0.964930\n", + " 5m: epoch 29 [################### ] 99% train loss = 0.0792148095 Validation score: 0.962011\n", + " 6m: epoch 30 [################### ] 99% train loss = 0.0779401071 Validation score: 0.965503\n", + " 6m: epoch 31 [################### ] 99% train loss = 0.0772009508 Validation score: 0.961959\n", + " 6m: epoch 32 [################### ] 99% train loss = 0.0762530363 Validation score: 0.960188\n", + " 6m: epoch 33 [################### ] 99% train loss = 0.0763947451 Validation score: 0.957999\n", + " 6m: epoch 34 [################### ] 99% train loss = 0.0747613538 Validation score: 0.966806\n", + " 7m: epoch 35 [################### ] 99% train loss = 0.0748809698 Validation score: 0.964356\n", + " 7m: epoch 36 [################### ] 99% train loss = 0.0742600308 Validation score: 0.963679\n", + " 7m: epoch 37 [################### ] 99% train loss = 0.0731461109 Validation score: 0.965816\n", + " 7m: epoch 38 [################### ] 99% train loss = 0.0734233149 Validation score: 0.965138\n", + " 8m: epoch 39 [################### ] 99% train loss = 0.0717869024 Validation score: 0.960761\n", + " 8m: epoch 40 [################### ] 99% train loss = 0.0713453308 Validation score: 0.965503\n", + "Validation accuracy of 1 fold: 0.9310913140311804\n", + " 0m: epoch 1 [################### ] 99% train loss = 0.3575856291 Validation score: 0.928863\n", + " 0m: epoch 2 [################### ] 99% train loss = 0.1911885052 Validation score: 0.938973\n", + " 0m: epoch 3 [################### ] 99% train loss = 0.1641307020 Validation score: 0.945680\n", + " 0m: epoch 4 [################### ] 99% train loss = 0.1490906928 Validation score: 0.946247\n", + " 0m: epoch 5 [################### ] 99% train loss = 0.1386919303 Validation score: 0.950426\n", + " 0m: epoch 6 [################### ] 99% train loss = 0.1304690580 Validation score: 0.951406\n", + " 0m: epoch 7 [################### ] 99% train loss = 0.1249359298 Validation score: 0.955997\n", + " 1m: epoch 8 [################### ] 99% train loss = 0.1209288259 Validation score: 0.957080\n", + " 1m: epoch 9 [################### ] 99% train loss = 0.1164651084 Validation score: 0.957183\n", + " 1m: epoch 10 [################### ] 99% train loss = 0.1126953790 Validation score: 0.952437\n", + " 1m: epoch 11 [################### ] 99% train loss = 0.1112673015 Validation score: 0.957441\n", + " 1m: epoch 12 [################### ] 99% train loss = 0.1077788949 Validation score: 0.958937\n", + " 1m: epoch 13 [################### ] 99% train loss = 0.1054304294 Validation score: 0.958060\n", + " 2m: epoch 14 [################### ] 99% train loss = 0.1033717689 Validation score: 0.959453\n", + " 2m: epoch 15 [################### ] 99% train loss = 0.1013673145 Validation score: 0.958318\n", + " 2m: epoch 16 [################### ] 99% train loss = 0.1003308795 Validation score: 0.959453\n", + " 2m: epoch 17 [################### ] 99% train loss = 0.0984715094 Validation score: 0.961981\n", + " 2m: epoch 18 [################### ] 99% train loss = 0.0963671881 Validation score: 0.961826\n", + " 3m: epoch 19 [################### ] 99% train loss = 0.0946062027 Validation score: 0.961517\n", + " 3m: epoch 20 [################### ] 99% train loss = 0.0933503148 Validation score: 0.961929\n", + " 3m: epoch 21 [################### ] 99% train loss = 0.0928453441 Validation score: 0.958267\n", + " 3m: epoch 22 [################### ] 99% train loss = 0.0909533049 Validation score: 0.961568\n", + " 3m: epoch 23 [################### ] 99% train loss = 0.0896899480 Validation score: 0.964096\n", + " 4m: epoch 24 [################### ] 99% train loss = 0.0883948565 Validation score: 0.963735\n", + " 4m: epoch 25 [################### ] 99% train loss = 0.0870950741 Validation score: 0.963632\n", + " 4m: epoch 26 [################### ] 99% train loss = 0.0864948371 Validation score: 0.960588\n", + " 4m: epoch 27 [################### ] 99% train loss = 0.0857158196 Validation score: 0.961878\n", + " 4m: epoch 28 [################### ] 99% train loss = 0.0849612434 Validation score: 0.963064\n", + " 5m: epoch 29 [################### ] 99% train loss = 0.0842999036 Validation score: 0.962497\n", + " 5m: epoch 30 [################### ] 99% train loss = 0.0830738783 Validation score: 0.964870\n", + " 5m: epoch 31 [################### ] 99% train loss = 0.0821268466 Validation score: 0.964148\n", + " 5m: epoch 32 [################### ] 99% train loss = 0.0801525599 Validation score: 0.963941\n", + " 5m: epoch 33 [################### ] 99% train loss = 0.0805423358 Validation score: 0.962084\n", + " 5m: epoch 34 [################### ] 99% train loss = 0.0796464848 Validation score: 0.963477\n", + " 6m: epoch 35 [################### ] 99% train loss = 0.0799256090 Validation score: 0.966778\n", + " 6m: epoch 36 [################### ] 99% train loss = 0.0782601802 Validation score: 0.965128\n", + " 6m: epoch 37 [################### ] 99% train loss = 0.0777467134 Validation score: 0.966159\n", + " 6m: epoch 38 [################### ] 99% train loss = 0.0772866815 Validation score: 0.966933\n", + " 6m: epoch 39 [################### ] 99% train loss = 0.0762576043 Validation score: 0.965282\n", + " 6m: epoch 40 [################### ] 99% train loss = 0.0767887786 Validation score: 0.966263\n", + "Validation accuracy of 2 fold: 0.9376717112922003\n", + " 0m: epoch 1 [################### ] 99% train loss = 0.3957240220 Validation score: 0.927105\n", + " 0m: epoch 2 [################### ] 99% train loss = 0.2095750497 Validation score: 0.931620\n", + " 0m: epoch 3 [################### ] 99% train loss = 0.1823880127 Validation score: 0.937910\n", + " 0m: epoch 4 [################### ] 99% train loss = 0.1655021089 Validation score: 0.943447\n", + " 0m: epoch 5 [################### ] 99% train loss = 0.1545252761 Validation score: 0.947640\n", + " 0m: epoch 6 [################### ] 99% train loss = 0.1454380569 Validation score: 0.942856\n", + " 0m: epoch 7 [################### ] 99% train loss = 0.1380567238 Validation score: 0.946726\n", + " 0m: epoch 8 [################### ] 99% train loss = 0.1322509562 Validation score: 0.950866\n", + " 1m: epoch 9 [################### ] 99% train loss = 0.1275999724 Validation score: 0.953768\n", + " 1m: epoch 10 [################### ] 99% train loss = 0.1233028458 Validation score: 0.954736\n", + " 1m: epoch 11 [################### ] 99% train loss = 0.1192134129 Validation score: 0.954736\n", + " 1m: epoch 12 [################### ] 99% train loss = 0.1162136388 Validation score: 0.953983\n", + " 2m: epoch 13 [################### ] 99% train loss = 0.1129960422 Validation score: 0.953177\n", + " 2m: epoch 14 [################### ] 99% train loss = 0.1108455882 Validation score: 0.948930\n", + " 2m: epoch 15 [################### ] 99% train loss = 0.1098729514 Validation score: 0.957424\n", + " 2m: epoch 16 [################### ] 99% train loss = 0.1067172579 Validation score: 0.958768\n", + " 3m: epoch 17 [################### ] 99% train loss = 0.1044424214 Validation score: 0.957961\n", + " 3m: epoch 18 [################### ] 99% train loss = 0.1038549210 Validation score: 0.960219\n", + " 3m: epoch 19 [################### ] 99% train loss = 0.1022748143 Validation score: 0.955381\n", + " 3m: epoch 20 [################### ] 99% train loss = 0.0996931573 Validation score: 0.956725\n", + " 3m: epoch 21 [################### ] 99% train loss = 0.0988675902 Validation score: 0.957101\n", + " 4m: epoch 22 [################### ] 99% train loss = 0.0973892629 Validation score: 0.959359\n", + " 4m: epoch 23 [################### ] 99% train loss = 0.0976905602 Validation score: 0.960434\n", + " 4m: epoch 24 [################### ] 99% train loss = 0.0948719266 Validation score: 0.958069\n", + " 4m: epoch 25 [################### ] 99% train loss = 0.0936481745 Validation score: 0.958499\n", + " 5m: epoch 26 [################### ] 99% train loss = 0.0943828342 Validation score: 0.956026\n", + " 5m: epoch 27 [################### ] 99% train loss = 0.0920856832 Validation score: 0.959037\n", + " 5m: epoch 28 [################### ] 99% train loss = 0.0904638397 Validation score: 0.956456\n", + " 5m: epoch 29 [################### ] 99% train loss = 0.0907290399 Validation score: 0.959843\n", + " 6m: epoch 30 [################### ] 99% train loss = 0.0888983919 Validation score: 0.961886\n", + " 6m: epoch 31 [################### ] 99% train loss = 0.0879100656 Validation score: 0.958445\n", + " 6m: epoch 32 [################### ] 99% train loss = 0.0880837689 Validation score: 0.957263\n", + " 6m: epoch 33 [################### ] 99% train loss = 0.0877435953 Validation score: 0.961617\n", + " 6m: epoch 34 [################### ] 99% train loss = 0.0851805629 Validation score: 0.962853\n", + " 7m: epoch 35 [################### ] 99% train loss = 0.0846686962 Validation score: 0.960112\n", + " 7m: epoch 36 [################### ] 99% train loss = 0.0848608919 Validation score: 0.961725\n", + " 7m: epoch 37 [################### ] 99% train loss = 0.0828977355 Validation score: 0.962423\n", + " 7m: epoch 38 [################### ] 99% train loss = 0.0833722252 Validation score: 0.962531\n", + " 7m: epoch 39 [################### ] 99% train loss = 0.0828597295 Validation score: 0.960166\n", + " 8m: epoch 40 [############ ] 60% train loss = 0.0823054559Traceback (most recent call last):\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 255, in \n", + " main()\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 60, in main\n", + " cross_validation_metrics = cross_validation(\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 143, in cross_validation\n", + " model.train(train_data)\n", + " File \"/content/Deep4Life/src/models/torch_mlp.py\", line 40, in train\n", + " self._train(X_train, y_train, log=True, early_stopping=True)\n", + " File \"/content/Deep4Life/src/models/torch_mlp.py\", line 133, in _train\n", + " pred = self.mlp(input)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1511, in _wrapped_call_impl\n", + " return self._call_impl(*args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1520, in _call_impl\n", + " return forward_call(*args, **kwargs)\n", + " File \"/content/Deep4Life/src/models/torch_mlp.py\", line 29, in forward\n", + " return self.layers(input)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1511, in _wrapped_call_impl\n", + " return self._call_impl(*args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1520, in _call_impl\n", + " return forward_call(*args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/container.py\", line 217, in forward\n", + " input = module(input)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1511, in _wrapped_call_impl\n", + " return self._call_impl(*args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1520, in _call_impl\n", + " return forward_call(*args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/linear.py\", line 116, in forward\n", + " return F.linear(input, self.weight, self.bias)\n", + "KeyboardInterrupt\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!python3 src/train_and_validate.py --method stellar --config standard" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "EdDN-VxINcx7", + "outputId": "8ff2dc79-58cb-4017-f9fc-bcdb792f0f1a" + }, + "execution_count": 27, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Training - epoch 0: 100% 100/100 [00:02<00:00, 36.37it/s, Loss=1.19, Accuracy=0.664]\n", + "Training - epoch 1: 100% 100/100 [00:02<00:00, 39.72it/s, Loss=0.483, Accuracy=0.848]\n", + "Training - epoch 2: 100% 100/100 [00:02<00:00, 40.13it/s, Loss=0.366, Accuracy=0.883]\n", + "Training - epoch 3: 100% 100/100 [00:02<00:00, 38.32it/s, Loss=0.345, Accuracy=0.889]\n", + "Training - epoch 4: 100% 100/100 [00:03<00:00, 25.21it/s, Loss=0.297, Accuracy=0.902]\n", + "Training - epoch 5: 100% 100/100 [00:03<00:00, 32.56it/s, Loss=0.285, Accuracy=0.904]\n", + "Training - epoch 6: 100% 100/100 [00:02<00:00, 39.81it/s, Loss=0.251, Accuracy=0.916]\n", + "Training - epoch 7: 100% 100/100 [00:02<00:00, 39.29it/s, Loss=0.269, Accuracy=0.91]\n", + "Training - epoch 8: 100% 100/100 [00:02<00:00, 37.82it/s, Loss=0.262, Accuracy=0.911]\n", + "Training - epoch 9: 100% 100/100 [00:03<00:00, 26.76it/s, Loss=0.246, Accuracy=0.916]\n", + "Training - epoch 10: 100% 100/100 [00:03<00:00, 32.73it/s, Loss=0.235, Accuracy=0.92]\n", + "Training - epoch 11: 100% 100/100 [00:02<00:00, 36.60it/s, Loss=0.222, Accuracy=0.923]\n", + "Training - epoch 12: 100% 100/100 [00:02<00:00, 38.65it/s, Loss=0.229, Accuracy=0.921]\n", + "Training - epoch 13: 100% 100/100 [00:02<00:00, 40.16it/s, Loss=0.234, Accuracy=0.919]\n", + "Training - epoch 14: 100% 100/100 [00:03<00:00, 28.21it/s, Loss=0.221, Accuracy=0.924]\n", + "Training - epoch 15: 100% 100/100 [00:02<00:00, 35.85it/s, Loss=0.202, Accuracy=0.931]\n", + "Training - epoch 16: 100% 100/100 [00:02<00:00, 36.51it/s, Loss=0.207, Accuracy=0.929]\n", + "Training - epoch 17: 100% 100/100 [00:02<00:00, 36.93it/s, Loss=0.2, Accuracy=0.931]\n", + "Training - epoch 18: 100% 100/100 [00:02<00:00, 41.41it/s, Loss=0.186, Accuracy=0.936]\n", + "Training - epoch 19: 100% 100/100 [00:03<00:00, 29.03it/s, Loss=0.194, Accuracy=0.933]\n", + "Validation accuracy of 0 fold: 0.9027391733165965\n", + "Training - epoch 0: 100% 100/100 [00:02<00:00, 35.48it/s, Loss=1.15, Accuracy=0.671]\n", + "Training - epoch 1: 100% 100/100 [00:02<00:00, 36.78it/s, Loss=0.49, Accuracy=0.849]\n", + "Training - epoch 2: 100% 100/100 [00:02<00:00, 36.74it/s, Loss=0.387, Accuracy=0.877]\n", + "Training - epoch 3: 100% 100/100 [00:02<00:00, 38.19it/s, Loss=0.322, Accuracy=0.896]\n", + "Training - epoch 4: 100% 100/100 [00:03<00:00, 27.10it/s, Loss=0.302, Accuracy=0.901]\n", + "Training - epoch 5: 100% 100/100 [00:02<00:00, 33.92it/s, Loss=0.279, Accuracy=0.907]\n", + "Training - epoch 6: 100% 100/100 [00:02<00:00, 39.95it/s, Loss=0.26, Accuracy=0.913]\n", + "Training - epoch 7: 100% 100/100 [00:02<00:00, 37.22it/s, Loss=0.279, Accuracy=0.908]\n", + "Training - epoch 8: 100% 100/100 [00:02<00:00, 40.69it/s, Loss=0.242, Accuracy=0.919]\n", + "Training - epoch 9: 100% 100/100 [00:03<00:00, 30.28it/s, Loss=0.242, Accuracy=0.92]\n", + "Training - epoch 10: 100% 100/100 [00:03<00:00, 31.44it/s, Loss=0.223, Accuracy=0.925]\n", + "Training - epoch 11: 100% 100/100 [00:02<00:00, 39.19it/s, Loss=0.217, Accuracy=0.926]\n", + "Training - epoch 12: 100% 100/100 [00:02<00:00, 39.06it/s, Loss=0.219, Accuracy=0.925]\n", + "Training - epoch 13: 100% 100/100 [00:02<00:00, 39.31it/s, Loss=0.217, Accuracy=0.925]\n", + "Training - epoch 14: 100% 100/100 [00:03<00:00, 29.12it/s, Loss=0.212, Accuracy=0.927]\n", + "Training - epoch 15: 100% 100/100 [00:03<00:00, 30.74it/s, Loss=0.219, Accuracy=0.926]\n", + "Training - epoch 16: 100% 100/100 [00:02<00:00, 38.67it/s, Loss=0.2, Accuracy=0.932]\n", + "Training - epoch 17: 100% 100/100 [00:02<00:00, 40.44it/s, Loss=0.188, Accuracy=0.936]\n", + "Training - epoch 18: 100% 100/100 [00:02<00:00, 37.33it/s, Loss=0.214, Accuracy=0.926]\n", + "Training - epoch 19: 100% 100/100 [00:03<00:00, 31.45it/s, Loss=0.199, Accuracy=0.931]\n", + "Validation accuracy of 1 fold: 0.913162583518931\n", + "Training - epoch 0: 100% 100/100 [00:03<00:00, 27.90it/s, Loss=1.06, Accuracy=0.691]\n", + "Training - epoch 1: 100% 100/100 [00:02<00:00, 36.51it/s, Loss=0.479, Accuracy=0.848]\n", + "Training - epoch 2: 100% 100/100 [00:02<00:00, 37.85it/s, Loss=0.378, Accuracy=0.879]\n", + "Training - epoch 3: 100% 100/100 [00:03<00:00, 30.02it/s, Loss=0.313, Accuracy=0.898]\n", + "Training - epoch 4: 100% 100/100 [00:03<00:00, 25.12it/s, Loss=0.326, Accuracy=0.893]\n", + "Training - epoch 5: 100% 100/100 [00:03<00:00, 27.54it/s, Loss=0.279, Accuracy=0.907]\n", + "Training - epoch 6: 100% 100/100 [00:02<00:00, 39.48it/s, Loss=0.271, Accuracy=0.908]\n", + "Training - epoch 7: 100% 100/100 [00:02<00:00, 37.58it/s, Loss=0.269, Accuracy=0.911]\n", + "Training - epoch 8: 100% 100/100 [00:02<00:00, 36.85it/s, Loss=0.249, Accuracy=0.915]\n", + "Training - epoch 9: 29% 29/100 [00:00<00:01, 40.49it/s, Loss=0.251, Accuracy=0.917]\n", + "Traceback (most recent call last):\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 255, in \n", + " main()\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 60, in main\n", + " cross_validation_metrics = cross_validation(\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 143, in cross_validation\n", + " model.train(train_data)\n", + " File \"/content/Deep4Life/src/models/vanilla_stellar.py\", line 420, in train\n", + " self._train(train_data_loader, self.cfg.epochs)\n", + " File \"/content/Deep4Life/src/models/vanilla_stellar.py\", line 482, in _train\n", + " loss.backward()\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/_tensor.py\", line 522, in backward\n", + " torch.autograd.backward(\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/autograd/__init__.py\", line 266, in backward\n", + " Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass\n", + "KeyboardInterrupt\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!python3 src/train_and_validate.py --method stellar --config custom" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "JPAsdRGTORNG", + "outputId": "76c7a310-4c56-42dc-98fe-0f1a3df712bc" + }, + "execution_count": 28, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Training - epoch 0: 100% 100/100 [00:06<00:00, 14.86it/s, Loss=0.855, Accuracy=0.751]\n", + "Training - epoch 1: 100% 100/100 [00:08<00:00, 11.90it/s, Loss=0.408, Accuracy=0.874]\n", + "Training - epoch 2: 100% 100/100 [00:06<00:00, 14.52it/s, Loss=0.334, Accuracy=0.895]\n", + "Training - epoch 3: 100% 100/100 [00:08<00:00, 11.96it/s, Loss=0.324, Accuracy=0.897]\n", + "Training - epoch 4: 100% 100/100 [00:06<00:00, 15.19it/s, Loss=0.288, Accuracy=0.904]\n", + "Training - epoch 5: 100% 100/100 [00:08<00:00, 12.36it/s, Loss=0.279, Accuracy=0.907]\n", + "Training - epoch 6: 100% 100/100 [00:07<00:00, 13.67it/s, Loss=0.292, Accuracy=0.903]\n", + "Training - epoch 7: 100% 100/100 [00:07<00:00, 12.91it/s, Loss=0.247, Accuracy=0.916]\n", + "Training - epoch 8: 100% 100/100 [00:07<00:00, 13.68it/s, Loss=0.267, Accuracy=0.912]\n", + "Training - epoch 9: 100% 100/100 [00:09<00:00, 10.94it/s, Loss=0.23, Accuracy=0.924]\n", + "Training - epoch 10: 100% 100/100 [00:07<00:00, 13.49it/s, Loss=0.21, Accuracy=0.929]\n", + "Training - epoch 11: 100% 100/100 [00:07<00:00, 12.69it/s, Loss=0.24, Accuracy=0.919]\n", + "Training - epoch 12: 100% 100/100 [00:07<00:00, 12.55it/s, Loss=0.209, Accuracy=0.928]\n", + "Training - epoch 13: 100% 100/100 [00:07<00:00, 13.06it/s, Loss=0.207, Accuracy=0.929]\n", + "Training - epoch 14: 100% 100/100 [00:10<00:00, 9.66it/s, Loss=0.194, Accuracy=0.933]\n", + "Training - epoch 15: 100% 100/100 [00:08<00:00, 12.36it/s, Loss=0.197, Accuracy=0.931]\n", + "Training - epoch 16: 100% 100/100 [00:15<00:00, 6.40it/s, Loss=0.19, Accuracy=0.935]\n", + "Training - epoch 17: 100% 100/100 [00:23<00:00, 4.33it/s, Loss=0.192, Accuracy=0.933]\n", + "Training - epoch 18: 100% 100/100 [00:26<00:00, 3.79it/s, Loss=0.18, Accuracy=0.937]\n", + "Training - epoch 19: 100% 100/100 [00:28<00:00, 3.50it/s, Loss=0.193, Accuracy=0.933]\n", + "Validation accuracy of 0 fold: 0.9218147583609791\n", + "Training - epoch 0: 100% 100/100 [00:07<00:00, 12.89it/s, Loss=0.835, Accuracy=0.765]\n", + "Training - epoch 1: 100% 100/100 [00:06<00:00, 15.39it/s, Loss=0.403, Accuracy=0.876]\n", + "Training - epoch 2: 100% 100/100 [00:07<00:00, 12.61it/s, Loss=0.34, Accuracy=0.891]\n", + "Training - epoch 3: 100% 100/100 [00:06<00:00, 15.56it/s, Loss=0.313, Accuracy=0.898]\n", + "Training - epoch 4: 100% 100/100 [00:07<00:00, 12.87it/s, Loss=0.281, Accuracy=0.908]\n", + "Training - epoch 5: 100% 100/100 [00:06<00:00, 14.84it/s, Loss=0.28, Accuracy=0.907]\n", + "Training - epoch 6: 100% 100/100 [00:09<00:00, 10.56it/s, Loss=0.291, Accuracy=0.905]\n", + "Training - epoch 7: 100% 100/100 [00:06<00:00, 16.41it/s, Loss=0.28, Accuracy=0.907]\n", + "Training - epoch 8: 100% 100/100 [00:07<00:00, 13.23it/s, Loss=0.234, Accuracy=0.921]\n", + "Training - epoch 9: 100% 100/100 [00:06<00:00, 16.41it/s, Loss=0.227, Accuracy=0.924]\n", + "Training - epoch 10: 100% 100/100 [00:07<00:00, 13.88it/s, Loss=0.21, Accuracy=0.929]\n", + "Training - epoch 11: 100% 100/100 [00:06<00:00, 14.49it/s, Loss=0.205, Accuracy=0.931]\n", + "Training - epoch 12: 100% 100/100 [00:07<00:00, 13.37it/s, Loss=0.201, Accuracy=0.931]\n", + "Training - epoch 13: 100% 100/100 [00:07<00:00, 12.84it/s, Loss=0.217, Accuracy=0.926]\n", + "Training - epoch 14: 80% 80/100 [00:08<00:02, 9.56it/s, Loss=0.198, Accuracy=0.932]\n", + "Traceback (most recent call last):\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 255, in \n", + " main()\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 60, in main\n", + " cross_validation_metrics = cross_validation(\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 143, in cross_validation\n", + " model.train(train_data)\n", + " File \"/content/Deep4Life/src/models/custom_stellar.py\", line 223, in train\n", + " self._train_graph_batch(train_data_loader, self.cfg.epochs)\n", + " File \"/content/Deep4Life/src/models/custom_stellar.py\", line 294, in _train_graph_batch\n", + " loss.backward()\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/_tensor.py\", line 522, in backward\n", + " torch.autograd.backward(\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/autograd/__init__.py\", line 266, in backward\n", + " Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass\n", + "KeyboardInterrupt\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!python3 src/train_and_validate.py --method stellar --config custom_random_nodes" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "qVkWThjSRJtd", + "outputId": "68e16fee-9c0c-4347-8f45-a574c5d53d17" + }, + "execution_count": 29, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Training - epoch 0: 100% 961/961 [00:15<00:00, 63.30it/s, Loss=0.26, Accuracy=0.914]\n", + "Training - epoch 1: 100% 961/961 [00:15<00:00, 61.85it/s, Loss=0.167, Accuracy=0.94]\n", + "Training - epoch 2: 100% 961/961 [00:17<00:00, 53.40it/s, Loss=0.144, Accuracy=0.947]\n", + "Training - epoch 3: 100% 961/961 [00:19<00:00, 49.82it/s, Loss=0.131, Accuracy=0.951]\n", + "Training - epoch 4: 8% 80/961 [00:02<00:27, 32.59it/s, Loss=0.121, Accuracy=0.956]\n", + "Traceback (most recent call last):\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 255, in \n", + " main()\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 60, in main\n", + " cross_validation_metrics = cross_validation(\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 143, in cross_validation\n", + " model.train(train_data)\n", + " File \"/content/Deep4Life/src/models/custom_stellar.py\", line 232, in train\n", + " self._train_graph_batch(train_data_loader, self.cfg.epochs)\n", + " File \"/content/Deep4Life/src/models/custom_stellar.py\", line 295, in _train_graph_batch\n", + " self.optimizer.step()\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/optim/optimizer.py\", line 385, in wrapper\n", + " out = func(*args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/optim/optimizer.py\", line 76, in _use_grad\n", + " ret = func(self, *args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/optim/adam.py\", line 166, in step\n", + " adam(\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/optim/adam.py\", line 316, in adam\n", + " func(params,\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/optim/adam.py\", line 380, in _single_tensor_adam\n", + " grad = grad.add(param, alpha=weight_decay)\n", + "KeyboardInterrupt\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!pip install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.2.1+cu121.html" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "o96-R3c8TKID", + "outputId": "41d9df05-289f-4bc3-fe31-10439460f478" + }, + "execution_count": 34, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Looking in links: https://data.pyg.org/whl/torch-2.2.1+cu121.html\n", + "Collecting pyg_lib\n", + " Downloading https://data.pyg.org/whl/torch-2.2.0%2Bcu121/pyg_lib-0.4.0%2Bpt22cu121-cp310-cp310-linux_x86_64.whl (2.5 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.5/2.5 MB\u001b[0m \u001b[31m32.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting torch_scatter\n", + " Downloading https://data.pyg.org/whl/torch-2.2.0%2Bcu121/torch_scatter-2.1.2%2Bpt22cu121-cp310-cp310-linux_x86_64.whl (10.9 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m10.9/10.9 MB\u001b[0m \u001b[31m64.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting torch_sparse\n", + " Downloading https://data.pyg.org/whl/torch-2.2.0%2Bcu121/torch_sparse-0.6.18%2Bpt22cu121-cp310-cp310-linux_x86_64.whl (5.0 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.0/5.0 MB\u001b[0m \u001b[31m70.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting torch_cluster\n", + " Downloading https://data.pyg.org/whl/torch-2.2.0%2Bcu121/torch_cluster-1.6.3%2Bpt22cu121-cp310-cp310-linux_x86_64.whl (3.4 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.4/3.4 MB\u001b[0m \u001b[31m30.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting torch_spline_conv\n", + " Downloading https://data.pyg.org/whl/torch-2.2.0%2Bcu121/torch_spline_conv-1.2.2%2Bpt22cu121-cp310-cp310-linux_x86_64.whl (943 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m943.4/943.4 kB\u001b[0m \u001b[31m54.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: scipy in /usr/local/lib/python3.10/dist-packages (from torch_sparse) (1.11.4)\n", + "Requirement already satisfied: numpy<1.28.0,>=1.21.6 in /usr/local/lib/python3.10/dist-packages (from scipy->torch_sparse) (1.25.2)\n", + "Installing collected packages: torch_spline_conv, torch_scatter, pyg_lib, torch_sparse, torch_cluster\n", + "Successfully installed pyg_lib-0.4.0+pt22cu121 torch_cluster-1.6.3+pt22cu121 torch_scatter-2.1.2+pt22cu121 torch_sparse-0.6.18+pt22cu121 torch_spline_conv-1.2.2+pt22cu121\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!python3 src/train_and_validate.py --method stellar --config custom_neighbors" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "InYvmw5cRMUw", + "outputId": "52bdfdb0-de20-4f08-c813-099641cb084f" + }, + "execution_count": 35, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Training - epoch 0: 100% 961/961 [00:33<00:00, 28.83it/s, Loss=0.26, Accuracy=0.917]\n", + "Training - epoch 1: 100% 961/961 [01:54<00:00, 8.38it/s, Loss=0.13, Accuracy=0.952]\n", + "Training - epoch 2: 80% 766/961 [04:47<01:13, 2.67it/s, Loss=0.111, Accuracy=0.958]\n", + "Traceback (most recent call last):\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 255, in \n", + " main()\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 60, in main\n", + " cross_validation_metrics = cross_validation(\n", + " File \"/content/Deep4Life/src/train_and_validate.py\", line 143, in cross_validation\n", + " model.train(train_data)\n", + " File \"/content/Deep4Life/src/models/custom_stellar.py\", line 226, in train\n", + " self._train_graph_batch(train_data_loader, self.cfg.epochs)\n", + " File \"/content/Deep4Life/src/models/custom_stellar.py\", line 290, in _train_graph_batch\n", + " output, _ = self.model(batch)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1511, in _wrapped_call_impl\n", + " return self._call_impl(*args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1520, in _call_impl\n", + " return forward_call(*args, **kwargs)\n", + " File \"/content/Deep4Life/src/models/custom_stellar.py\", line 179, in forward\n", + " _, out_feat = self.encoder(data)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1511, in _wrapped_call_impl\n", + " return self._call_impl(*args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1520, in _call_impl\n", + " return forward_call(*args, **kwargs)\n", + " File \"/content/Deep4Life/src/models/custom_stellar.py\", line 78, in forward\n", + " out_feat = layer(out_feat, edge_index)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1511, in _wrapped_call_impl\n", + " return self._call_impl(*args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1520, in _call_impl\n", + " return forward_call(*args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch_geometric/nn/conv/film_conv.py\", line 135, in forward\n", + " beta, gamma = self.films[0](x[1]).split(self.out_channels, dim=-1)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1511, in _wrapped_call_impl\n", + " return self._call_impl(*args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py\", line 1520, in _call_impl\n", + " return forward_call(*args, **kwargs)\n", + " File \"/usr/local/lib/python3.10/dist-packages/torch_geometric/nn/dense/linear.py\", line 147, in forward\n", + " return F.linear(x, self.weight, self.bias)\n", + "KeyboardInterrupt\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Test" + ], + "metadata": { + "id": "Zz_iQ2x-Zkf8" + } + }, + { + "cell_type": "code", + "source": [ + "!git fetch origin" + ], + "metadata": { + "id": "ITv-OwERZtmx" + }, + "execution_count": 277, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "!git pull origin" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "6ZifCK44iP2G", + "outputId": "317f8f02-b470-41ae-fd37-796b36ab71a6" + }, + "execution_count": 278, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Updating ad5b3b6..9c109bc\n", + "Fast-forward\n", + " src/models/sklearn_svm.py | 2 \u001b[32m+\u001b[m\u001b[31m-\u001b[m\n", + " src/train_and_validate.py | 90 \u001b[32m+++++++++++++++++++++++++++++++++\u001b[m\u001b[31m----------------------------------\u001b[m\n", + " 2 files changed, 46 insertions(+), 46 deletions(-)\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!git checkout lukass/introduce_test_mode" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "JfC4eoCigScf", + "outputId": "b9791f64-0fc5-4e52-b158-54852d0dca6e" + }, + "execution_count": 54, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Switched to branch 'lukass/introduce_test_mode'\n", + "Your branch is behind 'origin/lukass/introduce_test_mode' by 2 commits, and can be fast-forwarded.\n", + " (use \"git pull\" to update your local branch)\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "## Creating a dummy test set" + ], + "metadata": { + "id": "CBYwuvB1-HpL" + } + }, + { + "cell_type": "code", + "source": [ + "from src.datasets.data_utils import load_full_anndata\n", + "test_anndata = load_full_anndata(False)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "h8FruEyWmVas", + "outputId": "b8ae13c9-cce4-4204-adb0-6e86af539ec7" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "False\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import scanpy\n", + "\n", + "sampled_anndata = scanpy.pp.subsample(test_anndata, n_obs=1000, copy=True, random_state=42)\n", + "sampled_anndata.write_h5ad(\"/content/Deep4Life/data/test/cell_data.h5ad\")\n", + "len(sampled_anndata.obs[\"cell_labels\"].cat.categories)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "GfTDkC8B4fOx", + "outputId": "92bfb6b9-ff71-4fbf-a718-6985a02e2fa8" + }, + "execution_count": 265, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "14" + ] + }, + "metadata": {}, + "execution_count": 265 + } + ] + }, + { + "cell_type": "code", + "source": [ + "filenames_list = sampled_anndata.obs[\"image\"].unique()\n", + "len(filenames_list)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "1PORqQd05JJR", + "outputId": "036cdf2d-0de9-490f-cde6-31eeb924ddca" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "124" + ] + }, + "metadata": {}, + "execution_count": 251 + } + ] + }, + { + "cell_type": "code", + "source": [ + "filenames = \"\\n\".join(filenames_list)\n", + "with open(\"filenames\", \"w\") as f:\n", + " f.write(filenames)" + ], + "metadata": { + "id": "UKsYd4PB5UYa" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "! ls data/train/images_masks/img | wc -l" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "vMJqmfWsk8oP", + "outputId": "1f85a74e-9728-497e-9042-3c9e8ede9f9d" + }, + "execution_count": 254, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "125\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "! mkdir -p data/test/images_masks/img" + ], + "metadata": { + "id": "6i7yaHdglY8K" + }, + "execution_count": 256, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "! mkdir -p data/test/images_masks/masks" + ], + "metadata": { + "id": "8NzLKJQeleOI" + }, + "execution_count": 257, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "!cat filenames|wc -l" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "b4CWU0wG2Oe9", + "outputId": "a9f79583-249d-44f6-98b0-4276b10e2940" + }, + "execution_count": 259, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "123\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "!cat filenames | xargs -I {} cp data/train/images_masks/img/{} data/test/images_masks/img" + ], + "metadata": { + "id": "3fsh0nFwycoq" + }, + "execution_count": 260, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "!cat filenames | xargs -I {} cp data/train/images_masks/masks/{} data/test/images_masks/masks" + ], + "metadata": { + "id": "O7PvxAr8y79W" + }, + "execution_count": 261, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "! ls data/test/images_masks/img | wc -l" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "6TX4HRComBEd", + "outputId": "a5da119f-ef87-4f0f-f34d-191d9329e794" + }, + "execution_count": 262, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "124\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "! ls data/test/images_masks/masks | wc -l" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "HN1-bMiZmDMo", + "outputId": "01837965-23f3-4024-ab75-a626fa719fc0" + }, + "execution_count": 263, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "124\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "## Running inference on a trained svm" + ], + "metadata": { + "id": "j8TRsezr-Lr6" + } + }, + { + "cell_type": "code", + "source": [ + "!python3 src/train_and_validate.py --method sklearn_svm/svc --config linear test linear_2024-05-08_20-33-44_seed_42_folds_5" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "T3OJt8QWgX_I", + "outputId": "75a38a50-fc28-4037-8283-28d267e0598e" + }, + "execution_count": 272, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "1000\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "## Running on best results from the drive (I created a shurtcut to my drive to the shared folder)" + ], + "metadata": { + "id": "8GIgbimH-U_5" + } + }, + { + "cell_type": "code", + "source": [ + "!cp -r /content/drive/MyDrive/best_results/* ./results/" + ], + "metadata": { + "id": "qrbvfKFL8Msp" + }, + "execution_count": 270, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "!python3 src/train_and_validate.py --method stellar --config custom test custom_2024-05-08_22-23-22_seed_42_folds_5" + ], + "metadata": { + "id": "Ic4on4YP7kmu" + }, + "execution_count": 279, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "!python3 src/train_and_validate.py --method xgboost --config standard test standard_2024-05-08_21-15-37_seed_42_folds_5" + ], + "metadata": { + "id": "wV1CxYamBkS4" + }, + "execution_count": 281, + "outputs": [] + } + ], + "metadata": { + "colab": { + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/src/eval/metrics.py b/src/eval/metrics.py new file mode 100644 index 0000000..9234d22 --- /dev/null +++ b/src/eval/metrics.py @@ -0,0 +1,70 @@ +import sklearn + + +# def macro_average_precision(ground_truth, prediction_probability): +# """ +# Calculates macro-averaged precision for multi-class classification. + +# Args: +# ground_truth (array-like): Array of true labels. +# prediction_probability (array-like): Array of predicted class probabilities. + +# Returns: +# float: Macro-averaged precision score. +# """ +# num_classes = len(ground_truth.unique()) + +# precision_per_class = [] + +# # Calculate precision score for each class +# for class_label in range(num_classes): +# class_mask = ground_truth == class_label +# ground_truth_filtered = ground_truth[class_mask] +# prediction_probability_filtered = prediction_probability[class_mask] +# # Calculate precision for this class +# precision = sklearn.metrics.precision_score(ground_truth_filtered, prediction_probability_filtered[:, class_label], average='binary', zero_division=0) +# precision_per_class.append(precision) + +# # Macro-average the precision scores +# macro_average_precision = np.mean(precision_per_class) +# return macro_average_precision + + +def calculate_metrics( + ground_truth, prediction, prediction_probability, classes, cross_validation_metrics +): + f1_score_per_cell_type = sklearn.metrics.f1_score( + ground_truth, prediction, labels=classes, average=None + ) + f1_score = sklearn.metrics.f1_score( + ground_truth, prediction, labels=classes, average="macro" + ) + accuracy = sklearn.metrics.accuracy_score(ground_truth, prediction) + if prediction_probability is not None: + average_precision_per_cell_type = sklearn.metrics.average_precision_score( + ground_truth, prediction_probability, average=None + ) + roc_auc_per_cell_type = sklearn.metrics.roc_auc_score( + ground_truth, + prediction_probability, + multi_class="ovr", + average=None, + labels=classes, + ) + else: + average_precision_per_cell_type = None + roc_auc_per_cell_type = None + confusion_matrix = sklearn.metrics.confusion_matrix( + ground_truth, prediction, labels=classes + ) + + metrics = { + "f1_score_per_cell_type": f1_score_per_cell_type, + "f1_score": f1_score, + "accuracy": accuracy, + "average_precision_per_cell_type": average_precision_per_cell_type, + "roc_auc_per_cell_type": roc_auc_per_cell_type, + "confusion_matrix": confusion_matrix, + } + + cross_validation_metrics.loc[len(cross_validation_metrics.index)] = metrics diff --git a/src/eval/utils.py b/src/eval/utils.py new file mode 100644 index 0000000..aa955c8 --- /dev/null +++ b/src/eval/utils.py @@ -0,0 +1,63 @@ +import pandas as pd +import anndata +import torch +from sklearn.model_selection import KFold +from eval.metrics import calculate_metrics +from models.ModelBase import ModelBase + + +def cross_validation( + data: anndata.AnnData, model: ModelBase, random_state: int = 42, n_folds: int = 5 +) -> pd.DataFrame: + + metrics_names = [ + "f1_score_per_cell_type", + "f1_score", + "accuracy", + "average_precision_per_cell_type", + "roc_auc_per_cell_type", + "confusion_matrix", + ] + + cross_validation_metrics = pd.DataFrame(columns=metrics_names) + + for i, (train_data, test_data) in enumerate(k_folds(data, n_folds, random_state)): + model.train(train_data) + prediction = model.predict(test_data) + prediction_probability = model.predict_proba(test_data) + ground_truth = test_data.obs["cell_labels"] + + calculate_metrics( + ground_truth, + prediction, + prediction_probability, + test_data.obs["cell_labels"].cat.categories, + cross_validation_metrics, + ) + + print( + f"Validation accuracy of {i} fold:", + cross_validation_metrics.loc[i]["accuracy"], + ) + + average_metrics = { + metric_name: cross_validation_metrics[metric_name].mean() + for metric_name in metrics_names + } + cross_validation_metrics.loc[len(cross_validation_metrics.index)] = average_metrics + + return cross_validation_metrics + + +def k_folds(data: anndata.AnnData, n_folds: int, random_state: int): + sample_ids = data.obs["sample_id"].cat.remove_unused_categories() + sample_ids_unique = sample_ids.cat.categories + + kfold = KFold(n_splits=n_folds, shuffle=True, random_state=random_state) + split = kfold.split(sample_ids_unique.tolist()) + + for train, test in split: + train_mask = data.obs["sample_id"].isin(sample_ids_unique[train]) + test_mask = data.obs["sample_id"].isin(sample_ids_unique[test]) + + yield data[train_mask], data[test_mask] diff --git a/src/models/custom_stellar.py b/src/models/custom_stellar.py index a83055b..5b631fb 100644 --- a/src/models/custom_stellar.py +++ b/src/models/custom_stellar.py @@ -12,29 +12,75 @@ from torch import Tensor from torch_geometric.data import Batch, Data from torch_geometric.loader import DataLoader, RandomNodeLoader, NeighborLoader -from torch_geometric.nn import (APPNP, AGNNConv, AntiSymmetricConv, ARMAConv, - CGConv, ChebConv, ClusterGCNConv, - CuGraphGATConv, CuGraphRGCNConv, - CuGraphSAGEConv, DirGNNConv, DNAConv, - DynamicEdgeConv, EdgeConv, EGConv, FAConv, - FastRGCNConv, FeaStConv, FiLMConv, - FusedGATConv, GATConv, GatedGraphConv, - GATv2Conv, GCN2Conv, GCNConv, GENConv, - GeneralConv, GINConv, GINEConv, GMMConv, - GPSConv, GraphConv, GravNetConv, HANConv, - HEATConv, HeteroConv, HGTConv, HypergraphConv, - LEConv, LGConv, MFConv, MixHopConv, NNConv, - PANConv, PDNConv, PNAConv, PointGNNConv, - PointNetConv, PointTransformerConv, PPFConv, - ResGatedGraphConv, RGATConv, RGCNConv, - SAGEConv, SGConv, SignedConv, SplineConv, - SSGConv, SuperGATConv, TAGConv, - TransformerConv, WLConv, WLConvContinuous, - XConv) +from torch_geometric.nn import ( + APPNP, + AGNNConv, + AntiSymmetricConv, + ARMAConv, + CGConv, + ChebConv, + ClusterGCNConv, + CuGraphGATConv, + CuGraphRGCNConv, + CuGraphSAGEConv, + DirGNNConv, + DNAConv, + DynamicEdgeConv, + EdgeConv, + EGConv, + FAConv, + FastRGCNConv, + FeaStConv, + FiLMConv, + FusedGATConv, + GATConv, + GatedGraphConv, + GATv2Conv, + GCN2Conv, + GCNConv, + GENConv, + GeneralConv, + GINConv, + GINEConv, + GMMConv, + GPSConv, + GraphConv, + GravNetConv, + HANConv, + HEATConv, + HeteroConv, + HGTConv, + HypergraphConv, + LEConv, + LGConv, + MFConv, + MixHopConv, + NNConv, + PANConv, + PDNConv, + PNAConv, + PointGNNConv, + PointNetConv, + PointTransformerConv, + PPFConv, + ResGatedGraphConv, + RGATConv, + RGCNConv, + SAGEConv, + SGConv, + SignedConv, + SplineConv, + SSGConv, + SuperGATConv, + TAGConv, + TransformerConv, + WLConv, + WLConvContinuous, + XConv, +) from tqdm import tqdm -from datasets.stellar_data import (StellarDataloader, - make_graph_list_from_anndata) +from datasets.stellar_data import StellarDataloader, make_graph_list_from_anndata from models.ModelBase import ModelBase from models.vanilla_stellar import VanillaStellarClassifficationHead from utils import calculate_batch_accuracy @@ -60,7 +106,12 @@ def __init__( self.input_dim = input_dim self.hid_dim = hid_dim self.input_linear = nn.Linear(input_dim, hid_dim) - self.hidden_linear = nn.Sequential(*[nn.Sequential(nn.Linear(hid_dim, hid_dim), nn.ReLU() ) for _ in range(n_hidden_layers)]) + self.hidden_linear = nn.Sequential( + *[ + nn.Sequential(nn.Linear(hid_dim, hid_dim), nn.ReLU()) + for _ in range(n_hidden_layers) + ] + ) self.graph_convs = nn.ModuleList() self.batch_norm = batch_norm self.batch_norms = nn.ModuleList() @@ -128,6 +179,7 @@ def forward(self, x: Tensor) -> Tensor: out = self.linear(x) return out * self.temperature + class CustomSimpleStellarClassifficationHead(nn.Module): r""" A classification head that uses a linear layer to make predictions. @@ -143,10 +195,11 @@ def forward(self, x: Tensor) -> Tensor: out = self.linear(x) return out + CLASSIFICATION_HEAD_IMPLEMENTATIONS = [ VanillaStellarClassifficationHead, CustomStellarClassifficationHead, - CustomSimpleStellarClassifficationHead + CustomSimpleStellarClassifficationHead, ] @@ -171,7 +224,12 @@ def __init__( ): super(CustomStellarModel, self).__init__() self.encoder = CustomStellarEncoder( - input_dim, hid_dim, graph_conv_constructor, n_hidden_layers, n_graph_layers, batch_norm + input_dim, + hid_dim, + graph_conv_constructor, + n_hidden_layers, + n_graph_layers, + batch_norm, ) self.fc_net = fc_net_constructor(hid_dim, num_classes, temperature=temperature) @@ -219,16 +277,29 @@ def train(self, data: anndata.AnnData) -> None: batched_graphs = Batch.from_data_list(graphs) if self.cfg.batch_type == "graph": - train_data_loader = StellarDataloader(graphs, batch_size=self.cfg.batch_size) + train_data_loader = StellarDataloader( + graphs, batch_size=self.cfg.batch_size + ) self._train_graph_batch(train_data_loader, self.cfg.epochs) elif self.cfg.batch_type == "neighbors": - train_data_loader = NeighborLoader(batched_graphs, num_neighbors=[5], batch_size=self.cfg.node_batch_size, shuffle=True) + train_data_loader = NeighborLoader( + batched_graphs, + num_neighbors=[5], + batch_size=self.cfg.node_batch_size, + shuffle=True, + ) self._train_graph_batch(train_data_loader, self.cfg.epochs) elif self.cfg.batch_type == "nodes_in_graph": - train_data_loader = StellarDataloader(graphs, batch_size=self.cfg.batch_size) + train_data_loader = StellarDataloader( + graphs, batch_size=self.cfg.batch_size + ) self._train_node_batch(train_data_loader, self.cfg.epochs) elif self.cfg.batch_type == "random_nodes": - train_data_loader = RandomNodeLoader(batched_graphs, num_parts=batched_graphs.x.shape[0] // self.cfg.node_batch_size + 1, shuffle=True) + train_data_loader = RandomNodeLoader( + batched_graphs, + num_parts=batched_graphs.x.shape[0] // self.cfg.node_batch_size + 1, + shuffle=True, + ) self._train_graph_batch(train_data_loader, self.cfg.epochs) def predict(self, data: anndata.AnnData) -> np.ndarray: diff --git a/src/models/sklearn_mlp.py b/src/models/sklearn_mlp.py index b745a1b..f16cd24 100644 --- a/src/models/sklearn_mlp.py +++ b/src/models/sklearn_mlp.py @@ -16,7 +16,7 @@ def __init__(self, config): random_state=1, early_stopping=True, verbose=True, - max_iter=self.config.max_inter + max_iter=self.config.max_inter, ) def train(self, data: anndata.AnnData) -> None: @@ -44,4 +44,4 @@ def save(self, file_path: str) -> str: return file_path + ".joblib" def load(self, file_path: str) -> None: - self.mlp_classifier = load(file_path) + self.mlp_classifier = load(file_path + ".joblib") diff --git a/src/models/sklearn_svm.py b/src/models/sklearn_svm.py index c0d9a27..30bd34e 100644 --- a/src/models/sklearn_svm.py +++ b/src/models/sklearn_svm.py @@ -28,6 +28,7 @@ def train(self, data: anndata.AnnData) -> None: def predict(self, data: anndata.AnnData) -> np.ndarray: X = data.layers["exprs"] + self.scaler.fit(X) X_scaled = self.scaler.transform(X) prediction = self.svm.predict(X_scaled) @@ -49,7 +50,7 @@ def save(self, file_path: str) -> str: return path_with_ext def load(self, file_path: str) -> None: - self.svm = load(file_path) + self.svm = load(file_path + ".joblib") class SVMSklearnSVC(SVMSklearnModel): diff --git a/src/models/torch_mlp.py b/src/models/torch_mlp.py index 4a133fd..71b6de9 100644 --- a/src/models/torch_mlp.py +++ b/src/models/torch_mlp.py @@ -65,7 +65,7 @@ def save(self, file_path: str) -> str: return file_path + ".pt" def load(self, file_path: str) -> None: - self.mlp.load_state_dict(torch.load(file_path)) + self.mlp.load_state_dict(torch.load(file_path + ".pt")) def _train(self, X_train, y_train, log=False, early_stopping=False): # train config. Probably it should be moved to config directory diff --git a/src/models/xgboost.py b/src/models/xgboost.py index b2c4114..dced803 100644 --- a/src/models/xgboost.py +++ b/src/models/xgboost.py @@ -28,6 +28,7 @@ def train(self, data: anndata.AnnData) -> None: def predict(self, data: anndata.AnnData) -> np.ndarray: X = data.layers["exprs"] + self.scaler.fit(X) X_scaled = self.scaler.transform(X) prediction = self.xgboost.predict(X_scaled) @@ -48,4 +49,4 @@ def save(self, file_path: str) -> str: return path_with_ext def load(self, file_path: str) -> None: - self.xgboost.load_model(file_path) + self.xgboost.load_model(file_path + ".json") diff --git a/src/train_and_validate.py b/src/train_and_validate.py index 2393977..e4673c9 100644 --- a/src/train_and_validate.py +++ b/src/train_and_validate.py @@ -21,14 +21,17 @@ from models.sklearn_svm import SVMSklearnSVC from models.vanilla_stellar import VanillaStellarReduced from models.xgboost import XGBoostModel +from eval.utils import cross_validation CONFIG_PATH: Path = Path(__file__).parent / "config" RESULTS_PATH: Path = Path(__file__).parent.parent / "results" def main(): - parser = argparse.ArgumentParser(description="Validate model") - parser.add_argument("--dataset-path", default="data/train", help="dataset path") + np.random.seed(42) + torch.manual_seed(42) + + parser = argparse.ArgumentParser(description="Script to train or test a model.") parser.add_argument( "--method", default="stellar", @@ -39,65 +42,94 @@ def main(): default="standard", help="Name of a configuration in src/config/{method} directory.", ) - parser.add_argument( + + subparsers = parser.add_subparsers(help="Train or test a model.", dest="mode") + train_parser = subparsers.add_parser("train", help="Train a model.") + train_parser.add_argument( "--cv-seed", default=42, help="Seed used to make k folds for cross validation." ) - parser.add_argument( + train_parser.add_argument( "--n-folds", default=5, help="Number of folds in cross validation." ) - parser.add_argument("--test", action="store_true", help="Test mode.") - parser.add_argument( - "--retrain", default=True, help="Retrain a model using the whole dataset." + train_parser.add_argument("--do-cv", default=True, help="Perform cross validation.") + train_parser.add_argument( + "--retrain", + default=True, + help="Only if do-cv is set, retrain a model using the whole dataset.", ) - args = parser.parse_args() + test_parser = subparsers.add_parser("test", help="Test a model.") + test_parser.add_argument( + "model_name", + help="Name of the model to test (subdirectory of src/results containing the model and its config).", + ) + args = parser.parse_args() config = load_config(args) model = create_model(args, config) + test_mode = args.mode == "test" + data = load_full_anndata(test=test_mode) + + # Create directories if they don't exist + if not os.path.exists(RESULTS_PATH): + os.mkdir(RESULTS_PATH) - data = load_full_anndata(test=args.test) + if not test_mode: + train_model(args, model, data, config) + else: + test_model(args, model, data) - cross_validation_metrics = cross_validation( - data, model, random_state=args.cv_seed, n_folds=args.n_folds - ) +def train_model(args, model, data, config): # Save results current_time = datetime.datetime.now() formatted_time = current_time.strftime("%Y-%m-%d_%H-%M-%S") - # Create directories if they don't exist - if not os.path.exists(RESULTS_PATH): - os.mkdir(RESULTS_PATH) - - results_path = RESULTS_PATH / args.method - if not os.path.exists(results_path): - os.makedirs(results_path) - results_path = ( RESULTS_PATH / args.method / f"{args.config}_{formatted_time}_seed_{args.cv_seed}_folds_{args.n_folds}" ) - if not os.path.exists(results_path): - os.mkdir(results_path) + os.makedirs(results_path) + + # Save results + current_time = datetime.datetime.now() + formatted_time = current_time.strftime("%Y-%m-%d_%H-%M-%S") # Save config with open(results_path / "config.yaml", "w") as file: yaml.dump(config.__dict__, file) print(f"Config saved to: {results_path / 'config.yaml'}") - # Save metrics - cross_validation_metrics.to_json(results_path / "metrics.json", indent=4) - print(f"Metrics saved to: {results_path / 'metrics.json'}") + if args.do_cv: + cross_validation_metrics = cross_validation( + data, model, random_state=args.cv_seed, n_folds=args.n_folds + ) + + # Save metrics + cross_validation_metrics.to_json(results_path / "metrics.json", indent=4) + print(f"Metrics saved to: {results_path / 'metrics.json'}") # Retrain and save model - if args.retrain: + if not args.do_cv or args.retrain: print("Retraining model...") model.train(data) saved_model_path = model.save(str(results_path / "saved_model")) print(f"Model saved to: {saved_model_path}") +def test_model(args, model, data): + results_path = RESULTS_PATH / args.method / args.model_name + model_path = results_path / "saved_model" + model.load(str(model_path)) + prediction = model.predict(data) + prediction_probability = model.predict_proba(data) + + # Save prediction and prediction probability + np.save(results_path / "prediction.npy", prediction) + np.save(results_path / "prediction_probability.npy", prediction_probability) + + def load_config(args) -> argparse.Namespace: with open(CONFIG_PATH / args.method / f"{args.config}.yaml") as file: config = yaml.safe_load(file) @@ -123,133 +155,5 @@ def create_model(args, config) -> ModelBase: raise NotImplementedError(f"{args.method} method not implemented.") -def cross_validation( - data: anndata.AnnData, model: ModelBase, random_state: int = 42, n_folds: int = 5 -) -> pd.DataFrame: - torch.manual_seed(42) - - metrics_names = [ - "f1_score_per_cell_type", - "f1_score", - "accuracy", - "average_precision_per_cell_type", - "roc_auc_per_cell_type", - "confusion_matrix", - ] - - cross_validation_metrics = pd.DataFrame(columns=metrics_names) - - for i, (train_data, test_data) in enumerate(k_folds(data, n_folds, random_state)): - model.train(train_data) - prediction = model.predict(test_data) - prediction_probability = model.predict_proba(test_data) - ground_truth = test_data.obs["cell_labels"] - - calculate_metrics( - ground_truth, - prediction, - prediction_probability, - test_data.obs["cell_labels"].cat.categories, - cross_validation_metrics, - ) - - print( - f"Validation accuracy of {i} fold:", - cross_validation_metrics.loc[i]["accuracy"], - ) - - average_metrics = { - metric_name: cross_validation_metrics[metric_name].mean() - for metric_name in metrics_names - } - cross_validation_metrics.loc[len(cross_validation_metrics.index)] = average_metrics - - return cross_validation_metrics - - -def k_folds(data: anndata.AnnData, n_folds: int, random_state: int): - sample_ids = data.obs["sample_id"].cat.remove_unused_categories() - sample_ids_unique = sample_ids.cat.categories - - kfold = KFold(n_splits=n_folds, shuffle=True, random_state=random_state) - split = kfold.split(sample_ids_unique.tolist()) - - for train, test in split: - train_mask = data.obs["sample_id"].isin(sample_ids_unique[train]) - test_mask = data.obs["sample_id"].isin(sample_ids_unique[test]) - - yield data[train_mask], data[test_mask] - - -# def macro_average_precision(ground_truth, prediction_probability): -# """ -# Calculates macro-averaged precision for multi-class classification. - -# Args: -# ground_truth (array-like): Array of true labels. -# prediction_probability (array-like): Array of predicted class probabilities. - -# Returns: -# float: Macro-averaged precision score. -# """ -# num_classes = len(ground_truth.unique()) - -# precision_per_class = [] - -# # Calculate precision score for each class -# for class_label in range(num_classes): -# class_mask = ground_truth == class_label -# ground_truth_filtered = ground_truth[class_mask] -# prediction_probability_filtered = prediction_probability[class_mask] -# # Calculate precision for this class -# precision = sklearn.metrics.precision_score(ground_truth_filtered, prediction_probability_filtered[:, class_label], average='binary', zero_division=0) -# precision_per_class.append(precision) - -# # Macro-average the precision scores -# macro_average_precision = np.mean(precision_per_class) -# return macro_average_precision - - - -def calculate_metrics( - ground_truth, prediction, prediction_probability, classes, cross_validation_metrics -): - f1_score_per_cell_type = sklearn.metrics.f1_score( - ground_truth, prediction, labels=classes, average=None - ) - f1_score = sklearn.metrics.f1_score( - ground_truth, prediction, labels=classes, average="macro" - ) - accuracy = sklearn.metrics.accuracy_score(ground_truth, prediction) - if prediction_probability is not None: - average_precision_per_cell_type = sklearn.metrics.average_precision_score( - ground_truth, prediction_probability, average=None - ) - roc_auc_per_cell_type = sklearn.metrics.roc_auc_score( - ground_truth, - prediction_probability, - multi_class="ovr", - average=None, - labels=classes, - ) - else: - average_precision_per_cell_type = None - roc_auc_per_cell_type = None - confusion_matrix = sklearn.metrics.confusion_matrix( - ground_truth, prediction, labels=classes - ) - - metrics = { - "f1_score_per_cell_type": f1_score_per_cell_type, - "f1_score": f1_score, - "accuracy": accuracy, - "average_precision_per_cell_type": average_precision_per_cell_type, - "roc_auc_per_cell_type": roc_auc_per_cell_type, - "confusion_matrix": confusion_matrix, - } - - cross_validation_metrics.loc[len(cross_validation_metrics.index)] = metrics - - if __name__ == "__main__": main() diff --git a/stripped/notebooks/script_demo_stripped.py b/stripped/notebooks/script_demo_stripped.py new file mode 100644 index 0000000..6e1607e --- /dev/null +++ b/stripped/notebooks/script_demo_stripped.py @@ -0,0 +1,350 @@ +#!/usr/bin/env python +# coding: utf-8 + +# ## Setup + +# ## Run this if running on colab + +# In[ ]: + + +from IPython.display import clear_output; token = input(); clear_output() + + +# In[ ]: + + +get_ipython().system(' git clone https://$token@github.com/SzymonLukasik/Deep4Life.git') + + +# In[ ]: + + +get_ipython().run_line_magic('cd', '/content/Deep4Life') + + +# In[ ]: + + +get_ipython().system('pip install anndata') + + +# In[ ]: + + +get_ipython().system(' pip install pyometiff') + + +# ## Imports + +# In[ ]: + + +import pandas as pd +from pandas import DataFrame +import numpy as np +import matplotlib.pyplot as plt +import scipy.stats as stats +import plotly.express as px +import plotly.graph_objects as go +import plotly.subplots as sp +import pyometiff +import os +import gdown +import json +from pathlib import Path +from sklearn.preprocessing import LabelEncoder +from sklearn.preprocessing import MinMaxScaler +from sklearn.svm import SVC, LinearSVC, NuSVC +from sklearn.model_selection import GridSearchCV + +from typing import List +from src.datasets import load_d4ls +from sklearn.model_selection import train_test_split + +pd.set_option('display.max_columns', None) + + +# In[ ]: + + +get_ipython().run_line_magic('load_ext', 'autoreload') +get_ipython().run_line_magic('autoreload', '2') + + +# In[ ]: + + +get_ipython().system('mkdir data') + + +# In[ ]: + + +get_ipython().system('gdown 1-0YOHE1VoTRWqfBJLHQorGcHmkhCYvqW') + + +# In[ ]: + + +load_d4ls.DATA_PATH + + +# In[ ]: + + +get_ipython().system('unzip train.zip -d $load_d4ls.DATA_PATH') + + +# ## Load anndata + +# In[ ]: + + +train_anndata = load_d4ls.load_full_anndata() + + +# # Training from the command line + +# In[ ]: + + +get_ipython().system(' git checkout lukass/svm_baseline') + + +# In[7]: + + +get_ipython().system(' git pull origin') + + +# In[19]: + + +get_ipython().system(' git status') + + +# In[15]: + + +get_ipython().system(' git checkout -- src/models/sklearn_svm.py') + + +# In[20]: + + +get_ipython().system(' git branch') + + +# In[ ]: + + +get_ipython().system(' pip install scanpy') + + +# In[ ]: + + +get_ipython().system(' pip install scikit_learn==1.4.2') + + +# ## SVM Baseline + +# In[18]: + + +get_ipython().system('python3 src/train_and_validate.py --method sklearn_svm/svc --config linear') + + +# In[ ]: + + +get_ipython().system('python3 src/train_and_validate.py --method sklearn_svm/svc --config linear') + + +# ## Other methods + +# In[274]: + + +get_ipython().system(' git fetch origin master') + + +# In[24]: + + +get_ipython().system('python3 src/train_and_validate.py --method xgboost --config standard') + + +# In[25]: + + +get_ipython().system('python3 src/train_and_validate.py --method sklearn_mlp --config standard') + + +# In[26]: + + +get_ipython().system('python3 src/train_and_validate.py --method torch_mlp --config standard') + + +# In[27]: + + +get_ipython().system('python3 src/train_and_validate.py --method stellar --config standard') + + +# In[28]: + + +get_ipython().system('python3 src/train_and_validate.py --method stellar --config custom') + + +# In[29]: + + +get_ipython().system('python3 src/train_and_validate.py --method stellar --config custom_random_nodes') + + +# In[34]: + + +get_ipython().system('pip install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.2.1+cu121.html') + + +# In[35]: + + +get_ipython().system('python3 src/train_and_validate.py --method stellar --config custom_neighbors') + + +# # Test + +# In[277]: + + +get_ipython().system('git fetch origin') + + +# In[278]: + + +get_ipython().system('git pull origin') + + +# In[54]: + + +get_ipython().system('git checkout lukass/introduce_test_mode') + + +# ## Creating a dummy test set + +# In[ ]: + + +from src.datasets.data_utils import load_full_anndata +test_anndata = load_full_anndata(False) + + +# In[265]: + + +import scanpy + +sampled_anndata = scanpy.pp.subsample(test_anndata, n_obs=1000, copy=True, random_state=42) +sampled_anndata.write_h5ad("/content/Deep4Life/data/test/cell_data.h5ad") +len(sampled_anndata.obs["cell_labels"].cat.categories) + + +# In[ ]: + + +filenames_list = sampled_anndata.obs["image"].unique() +len(filenames_list) + + +# In[ ]: + + +filenames = " +".join(filenames_list) +with open("filenames", "w") as f: + f.write(filenames) + + +# In[254]: + + +get_ipython().system(' ls data/train/images_masks/img | wc -l') + + +# In[256]: + + +get_ipython().system(' mkdir -p data/test/images_masks/img') + + +# In[257]: + + +get_ipython().system(' mkdir -p data/test/images_masks/masks') + + +# In[259]: + + +get_ipython().system('cat filenames|wc -l') + + +# In[260]: + + +get_ipython().system('cat filenames | xargs -I {} cp data/train/images_masks/img/{} data/test/images_masks/img') + + +# In[261]: + + +get_ipython().system('cat filenames | xargs -I {} cp data/train/images_masks/masks/{} data/test/images_masks/masks') + + +# In[262]: + + +get_ipython().system(' ls data/test/images_masks/img | wc -l') + + +# In[263]: + + +get_ipython().system(' ls data/test/images_masks/masks | wc -l') + + +# ## Running inference on a trained svm + +# In[272]: + + +get_ipython().system('python3 src/train_and_validate.py --method sklearn_svm/svc --config linear test linear_2024-05-08_20-33-44_seed_42_folds_5') + + +# ## Running on best results from the drive (I created a shurtcut to my drive to the shared folder) + +# In[270]: + + +get_ipython().system('cp -r /content/drive/MyDrive/best_results/* ./results/') + + +# In[279]: + + +get_ipython().system('python3 src/train_and_validate.py --method stellar --config custom test custom_2024-05-08_22-23-22_seed_42_folds_5') + + +# In[281]: + + +get_ipython().system('python3 src/train_and_validate.py --method xgboost --config standard test standard_2024-05-08_21-15-37_seed_42_folds_5') +