diff --git a/program/cohort.ipynb b/program/cohort.ipynb index 51f5ebc..0a326d6 100644 --- a/program/cohort.ipynb +++ b/program/cohort.ipynb @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 72, "id": "4b2265b0", "metadata": {}, "outputs": [ @@ -102,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 73, "id": "32c4d764", "metadata": {}, "outputs": [], @@ -120,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 74, "id": "3164a3af", "metadata": {}, "outputs": [], @@ -144,7 +144,7 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 75, "id": "7bc40d28", "metadata": {}, "outputs": [], @@ -166,7 +166,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 76, "id": "3b3f17e5", "metadata": {}, "outputs": [], @@ -209,7 +209,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 77, "id": "942a01b5", "metadata": {}, "outputs": [], @@ -244,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 104, + "execution_count": 78, "id": "f1cd2f0e-446d-48a9-a008-b4f1cc593bfc", "metadata": { "tags": [] @@ -351,7 +351,7 @@ "4 3450.0 FEMALE " ] }, - "execution_count": 104, + "execution_count": 78, "metadata": {}, "output_type": "execute_result" } @@ -394,7 +394,7 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": 79, "id": "f2107c25-e730-4e22-a1b8-5bda53e61124", "metadata": { "tags": [] @@ -573,7 +573,7 @@ "max 6300.000000 NaN " ] }, - "execution_count": 105, + "execution_count": 79, "metadata": {}, "output_type": "execute_result" } @@ -592,7 +592,7 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": 80, "id": "1242122a-726e-4c37-a718-dd8e873d1612", "metadata": { "tags": [] @@ -648,7 +648,7 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 81, "id": "cf1cf582-8831-4f83-bb17-2175afb193e8", "metadata": { "tags": [] @@ -663,7 +663,7 @@ "Name: count, dtype: int64" ] }, - "execution_count": 108, + "execution_count": 81, "metadata": {}, "output_type": "execute_result" } @@ -686,7 +686,7 @@ }, { "cell_type": "code", - "execution_count": 109, + "execution_count": 82, "id": "cc42cb08-275c-4b05-9d2b-77052da2f336", "metadata": { "tags": [] @@ -705,7 +705,7 @@ "dtype: int64" ] }, - "execution_count": 109, + "execution_count": 82, "metadata": {}, "output_type": "execute_result" } @@ -724,7 +724,7 @@ }, { "cell_type": "code", - "execution_count": 110, + "execution_count": 83, "id": "3c57d55d-afd6-467a-a7a8-ff04132770ed", "metadata": { "tags": [] @@ -743,7 +743,7 @@ "dtype: int64" ] }, - "execution_count": 110, + "execution_count": 83, "metadata": {}, "output_type": "execute_result" } @@ -768,7 +768,7 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 84, "id": "2852c740", "metadata": {}, "outputs": [ @@ -814,7 +814,7 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 85, "id": "707cc972", "metadata": {}, "outputs": [ @@ -862,7 +862,7 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 86, "id": "3daf3ba1-d218-4ad4-b862-af679b91273f", "metadata": { "tags": [] @@ -942,7 +942,7 @@ "body_mass_g 640316.716388 " ] }, - "execution_count": 84, + "execution_count": 86, "metadata": {}, "output_type": "execute_result" } @@ -973,7 +973,7 @@ }, { "cell_type": "code", - "execution_count": 111, + "execution_count": 87, "id": "1d793e09-2cb9-47ff-a0e6-199a0f4fc1b3", "metadata": { "tags": [] @@ -1053,7 +1053,7 @@ "body_mass_g 1.000000 " ] }, - "execution_count": 111, + "execution_count": 87, "metadata": {}, "output_type": "execute_result" } @@ -1084,7 +1084,7 @@ }, { "cell_type": "code", - "execution_count": 112, + "execution_count": 88, "id": "1258c99d", "metadata": {}, "outputs": [ @@ -1124,7 +1124,7 @@ }, { "cell_type": "code", - "execution_count": 113, + "execution_count": 89, "id": "45b0a87f-028d-477f-9b65-199728c0b7ee", "metadata": { "tags": [] @@ -1179,19 +1179,28 @@ "source": [ "### Step 1 - Creating the Preprocessing Script\n", "\n", - "The first step we need in the pipeline is a [Processing Step](https://docs.aws.amazon.com/sagemaker/latest/dg/build-and-manage-steps.html#step-type-processing) to run a script that will split and transform the data. This Processing Step will create a SageMaker Processing Job in the background, run the script, and upload the output to S3. You can use Processing Jobs to perform data preprocessing, post-processing, feature engineering, data validation, and model evaluation. Check the [ProcessingStep](https://sagemaker.readthedocs.io/en/stable/workflows/pipelines/sagemaker.workflow.pipelines.html#sagemaker.workflow.steps.ProcessingStep) SageMaker's SDK documentation for more information.\n", + "The first step we need in the pipeline is a [Processing Step](https://docs.aws.amazon.com/sagemaker/latest/dg/build-and-manage-steps.html#step-type-processing) to run a script that will split and transform the data.\n", "\n", - "We will store the script in a folder called `processing`:\n" + "This Processing Step will create a SageMaker Processing Job in the background, run the script, and upload the output to S3. You can use Processing Jobs to perform data preprocessing, post-processing, feature engineering, data validation, and model evaluation. Check the [ProcessingStep](https://sagemaker.readthedocs.io/en/stable/workflows/pipelines/sagemaker.workflow.pipelines.html#sagemaker.workflow.steps.ProcessingStep) SageMaker's SDK documentation for more information.\n" + ] + }, + { + "cell_type": "markdown", + "id": "6ab6f546", + "metadata": {}, + "source": [ + "We will store the script in a folder called `processing` and add it to the system path so we can later import it as a module.\n" ] }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 90, "id": "78fe069e", "metadata": {}, "outputs": [], "source": [ - "(CODE_FOLDER / \"processing\").mkdir(parents=True, exist_ok=True)" + "(CODE_FOLDER / \"processing\").mkdir(parents=True, exist_ok=True)\n", + "sys.path.extend([f\"./{CODE_FOLDER}/processing\"])" ] }, { @@ -1204,7 +1213,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 91, "id": "fb6ba7c0-1bd6-4fe5-8b7f-f6cbdfd3846c", "metadata": { "tags": [] @@ -1429,7 +1438,7 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 92, "id": "d1f122a4-acff-4687-91b9-bfef13567d88", "metadata": { "tags": [] @@ -1440,23 +1449,23 @@ "output_type": "stream", "text": [ "\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\n", - "\u001b[32m\u001b[32m\u001b[1m8 passed\u001b[0m\u001b[32m in 0.13s\u001b[0m\u001b[0m\n" + "\u001b[32m\u001b[32m\u001b[1m8 passed\u001b[0m\u001b[32m in 0.16s\u001b[0m\u001b[0m\n" ] } ], "source": [ "%%ipytest -s\n", - "#| code-fold: true\n", - "#| output: false\n", + "# | code-fold: true\n", + "# | output: false\n", "\n", "import os\n", "import shutil\n", "import tarfile\n", "import pytest\n", "import tempfile\n", - "import joblib\n", + "\n", "from processing.script import preprocess\n", - " \n", + "\n", "\n", "@pytest.fixture(scope=\"function\", autouse=False)\n", "def directory():\n", @@ -1464,18 +1473,18 @@ " input_directory = Path(directory) / \"input\"\n", " input_directory.mkdir(parents=True, exist_ok=True)\n", " shutil.copy2(DATA_FILEPATH, input_directory / \"data.csv\")\n", - " \n", + "\n", " directory = Path(directory)\n", " preprocess(base_directory=directory)\n", - " \n", + "\n", " yield directory\n", - " \n", + "\n", " shutil.rmtree(directory)\n", "\n", "\n", "def test_preprocess_generates_data_splits(directory):\n", " output_directories = os.listdir(directory)\n", - " \n", + "\n", " assert \"train\" in output_directories\n", " assert \"validation\" in output_directories\n", " assert \"test\" in output_directories\n", @@ -1517,7 +1526,9 @@ "\n", "\n", "def test_train_baseline_is_not_transformed(directory):\n", - " baseline = pd.read_csv(directory / \"train-baseline\" / \"train-baseline.csv\", header=None)\n", + " baseline = pd.read_csv(\n", + " directory / \"train-baseline\" / \"train-baseline.csv\", header=None\n", + " )\n", "\n", " island = baseline.iloc[:, 0].unique()\n", "\n", @@ -1527,7 +1538,9 @@ "\n", "\n", "def test_test_baseline_is_not_transformed(directory):\n", - " baseline = pd.read_csv(directory / \"test-baseline\" / \"test-baseline.csv\", header=None)\n", + " baseline = pd.read_csv(\n", + " directory / \"test-baseline\" / \"test-baseline.csv\", header=None\n", + " )\n", "\n", " island = baseline.iloc[:, 1].unique()\n", "\n", @@ -1553,12 +1566,14 @@ "source": [ "### Step 2 - Caching Configuration\n", "\n", - "Several SageMaker Pipeline steps support caching. When a step runs, and dependending on the configured caching policy, SageMaker will try to reuse the result of a previous successful run of the same step. You can find more information about this topic in [Caching Pipeline Steps](https://docs.aws.amazon.com/sagemaker/latest/dg/pipelines-caching.html). Let's define a caching policy that we'll reuse on every step:\n" + "Several SageMaker Pipeline steps support caching. When a step runs, and dependending on the configured caching policy, SageMaker will try to reuse the result of a previous successful run of the same step. You can find more information about this topic in [Caching Pipeline Steps](https://docs.aws.amazon.com/sagemaker/latest/dg/pipelines-caching.html).\n", + "\n", + "Let's define a caching policy that we'll reuse on every step:\n" ] }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 93, "id": "d88e9ccf", "metadata": {}, "outputs": [], @@ -1575,12 +1590,12 @@ "source": [ "### Step 3 - Pipeline Configuration\n", "\n", - "We can parameterize a SageMaker Pipeline to make it more flexible. In this case, we'll use a parameter to pass the location of the dataset we want to process. We can execute the pipeline with different datasets by changing the value of this parameter. To read more about these parameters, check [Pipeline Parameters](https://docs.aws.amazon.com/sagemaker/latest/dg/build-and-manage-parameters.html).\n" + "We can parameterize a SageMaker Pipeline to make it more flexible. In this case, we'll use a parameter to pass the location of the dataset we want to process. We can execute the pipeline with different datasets by changing the value of this parameter. Check [Pipeline Parameters](https://docs.aws.amazon.com/sagemaker/latest/dg/build-and-manage-parameters.html) for more information.\n" ] }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 94, "id": "331fe373", "metadata": {}, "outputs": [], @@ -1611,12 +1626,12 @@ "\n", " \"High-level\n", "\n", - "The [Data Processing with Framework Processors](https://docs.aws.amazon.com/sagemaker/latest/dg/processing-job-frameworks.html) page discusses other built-in processors you can use. The [Docker Registry Paths and Example Code](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-algo-docker-registry-paths.html) page contains information about the available framework versions for each region.\n" + "The [Data Processing with Framework Processors](https://docs.aws.amazon.com/sagemaker/latest/dg/processing-job-frameworks.html) page discusses other built-in processors you can use. The [Available Deep Learning Container Images](https://github.com/aws/deep-learning-containers/blob/master/available_images.md) page contains the list of available containers for each region.\n" ] }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 95, "id": "3aa4471a", "metadata": {}, "outputs": [ @@ -1654,12 +1669,14 @@ "id": "6cf2cc58", "metadata": {}, "source": [ - "Let's now define the Processing Step that we'll use in the pipeline. This step requires a list of inputs that we need on the preprocessing script. In this case, the input is the dataset we stored in S3. We also have a few outputs that we want SageMaker to capture when the Processing Job finishes.\n" + "Let's now define the Processing Step that we'll use in the pipeline.\n", + "\n", + "This step will specify the list of inputs that we'll access from the preprocessing script. In this case, the input is the dataset we stored in S3. We also have a few outputs that we want SageMaker to capture when the Processing Job finishes.\n" ] }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 96, "id": "cdbd9303", "metadata": { "tags": [] @@ -1740,7 +1757,7 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 97, "id": "e140642a", "metadata": { "tags": [] @@ -1750,16 +1767,16 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session3-pipeline',\n", - " 'ResponseMetadata': {'RequestId': '75a07c9b-0363-4b13-8fd4-2d4cdd1f718f',\n", + " 'ResponseMetadata': {'RequestId': '96b55cc7-57b9-47e3-8725-e983506037cc',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '75a07c9b-0363-4b13-8fd4-2d4cdd1f718f',\n", + " 'HTTPHeaders': {'x-amzn-requestid': '96b55cc7-57b9-47e3-8725-e983506037cc',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '85',\n", - " 'date': 'Mon, 25 Mar 2024 21:26:53 GMT'},\n", + " 'date': 'Mon, 25 Mar 2024 23:42:51 GMT'},\n", " 'RetryAttempts': 0}}" ] }, - "execution_count": 95, + "execution_count": 97, "metadata": {}, "output_type": "execute_result" } @@ -1804,19 +1821,26 @@ "source": [ "### Step 1 - Creating the Training Script\n", "\n", - "Let's create the training script. This script is responsible for training a neural network using the train data, validating the model, and saving it so we can later use it.\n", - "\n", - "We will store the script in a folder called `training`:\n" + "Let's create the training script. This script is responsible for training a neural network using the train data, validating the model, and saving it so we can later use it.\n" + ] + }, + { + "cell_type": "markdown", + "id": "e55e9294", + "metadata": {}, + "source": [ + "We will store the script in a folder called `training` and add it to the system path so we can later import it as a module.\n" ] }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 98, "id": "ac0b891c", "metadata": {}, "outputs": [], "source": [ - "(CODE_FOLDER / \"training\").mkdir(parents=True, exist_ok=True)" + "(CODE_FOLDER / \"training\").mkdir(parents=True, exist_ok=True)\n", + "sys.path.extend([f\"./{CODE_FOLDER}/training\"])" ] }, { @@ -1829,7 +1853,7 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 99, "id": "d92b121d-dcb9-43e8-9ee3-3ececb583e7e", "metadata": { "tags": [] @@ -1845,17 +1869,16 @@ ], "source": [ "%%writefile {CODE_FOLDER}/training/script.py\n", - "#| label: training-script\n", - "#| echo: true\n", - "#| output: false\n", - "#| filename: script.py\n", - "#| code-line-numbers: true\n", + "# | label: training-script\n", + "# | echo: true\n", + "# | output: false\n", + "# | filename: script.py\n", + "# | code-line-numbers: true\n", "\n", "import os\n", "import argparse\n", - "import json\n", "import tarfile\n", - "\n", + "import json\n", "import keras\n", "import numpy as np\n", "import pandas as pd\n", @@ -1872,7 +1895,13 @@ "\n", "\n", "def train(\n", - " model_directory, train_path, validation_path, pipeline_path, experiment, epochs=50, batch_size=32\n", + " model_directory,\n", + " train_path,\n", + " validation_path,\n", + " pipeline_path,\n", + " experiment,\n", + " epochs=50,\n", + " batch_size=32,\n", "):\n", " print(f\"Keras version: {keras.__version__}\")\n", "\n", @@ -1981,7 +2010,6 @@ " # SageMaker will create a model.tar.gz file with anything\n", " # inside this directory when the training script finishes.\n", " model_directory=os.environ[\"SM_MODEL_DIR\"],\n", - "\n", " # SageMaker creates one channel for each one of the inputs\n", " # to the Training Step.\n", " train_path=os.environ[\"SM_CHANNEL_TRAIN\"],\n", @@ -2003,7 +2031,7 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": 100, "id": "14ea27ce-c453-4cb0-b309-dbecd732957e", "metadata": { "tags": [] @@ -2014,14 +2042,8 @@ "output_type": "stream", "text": [ "\u001b[1;38;5;214mCOMET WARNING:\u001b[0m To get all data logged automatically, import comet_ml before the following modules: sklearn.\n", - "\u001b[1;38;5;214mCOMET WARNING:\u001b[0m As you are running in a Jupyter environment, you will need to call `experiment.end()` when finished to ensure all metrics and code are logged before exiting.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Experiment is live on comet.com https://www.comet.com/svpino/ml-school/a8cae87486e44dcfa5c1d92ec8f499fc\n", + "\u001b[1;38;5;214mCOMET WARNING:\u001b[0m As you are running in a Jupyter environment, you will need to call `experiment.end()` when finished to ensure all metrics and code are logged before exiting.\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Experiment is live on comet.com https://www.comet.com/svpino/ml-school/763e16ff21294be08ccfa246d6c00a28\n", "\n", "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.SGD` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.SGD`.\n" ] @@ -2031,22 +2053,22 @@ "output_type": "stream", "text": [ "Keras version: 2.14.0\n", - "8/8 - 0s - loss: 0.7614 - accuracy: 0.7908 - val_loss: 0.7425 - val_accuracy: 0.6863 - 168ms/epoch - 21ms/step\n", - "2/2 [==============================] - 0s 2ms/step\n" + "8/8 - 0s - loss: 1.2167 - accuracy: 0.2343 - val_loss: 1.1450 - val_accuracy: 0.2549 - 213ms/epoch - 27ms/step\n", + "2/2 [==============================] - 0s 2ms/step\n", + "Validation accuracy: 0.2549019607843137\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpvv2jh03g/model/001/assets\n" + "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmph_zlno04/model/001/assets\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Validation accuracy: 0.6862745098039216\n", "\u001b[32m.\u001b[0m" ] }, @@ -2059,17 +2081,17 @@ "\u001b[1;38;5;39mCOMET INFO:\u001b[0m ---------------------------------------------------------------------------------------\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Data:\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m display_summary_level : 1\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m url : https://www.comet.com/svpino/ml-school/a8cae87486e44dcfa5c1d92ec8f499fc\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m url : https://www.comet.com/svpino/ml-school/763e16ff21294be08ccfa246d6c00a28\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Metrics:\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m accuracy : 0.7907949686050415\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m batch_accuracy : 0.6875\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m batch_loss : 0.8463743925094604\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m epoch_duration : 0.16770008401363157\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m loss : 0.7614467740058899\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m val_accuracy : 0.686274528503418\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m val_loss : 0.7424638867378235\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m validate_batch_accuracy : 0.65625\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m validate_batch_loss : 0.7693116664886475\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m accuracy : 0.2343096286058426\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m batch_accuracy : 0.25\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m batch_loss : 1.2679023742675781\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m epoch_duration : 0.21291220805142075\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m loss : 1.2166963815689087\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m val_accuracy : 0.2549019753932953\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m val_loss : 1.1450446844100952\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m validate_batch_accuracy : 0.21875\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m validate_batch_loss : 1.1627323627471924\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Others:\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m trainable_params : 195\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Parameters:\n", @@ -2096,12 +2118,12 @@ "\u001b[1;38;5;39mCOMET INFO:\u001b[0m git metadata : 1\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m installed packages : 1\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m model graph : 1\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m model-element : 5 (92.05 KB)\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m model-element : 5 (92.54 KB)\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m \n", "\u001b[1;38;5;214mCOMET WARNING:\u001b[0m To get all data logged automatically, import comet_ml before the following modules: sklearn.\n", "\u001b[1;38;5;214mCOMET WARNING:\u001b[0m To get all data logged automatically, import comet_ml before the following modules: sklearn.\n", "\u001b[1;38;5;214mCOMET WARNING:\u001b[0m As you are running in a Jupyter environment, you will need to call `experiment.end()` when finished to ensure all metrics and code are logged before exiting.\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Experiment is live on comet.com https://www.comet.com/svpino/ml-school/8ecdde1cf77a4e6eb07d74159a662ab8\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Experiment is live on comet.com https://www.comet.com/svpino/ml-school/f883d4f905344223a831a0fd42c7d34b\n", "\n", "WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.SGD` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.SGD`.\n" ] @@ -2111,22 +2133,22 @@ "output_type": "stream", "text": [ "Keras version: 2.14.0\n", - "8/8 - 0s - loss: 1.1654 - accuracy: 0.0669 - val_loss: 1.0734 - val_accuracy: 0.2549 - 168ms/epoch - 21ms/step\n", - "2/2 [==============================] - 0s 1ms/step\n" + "8/8 - 0s - loss: 1.0479 - accuracy: 0.3975 - val_loss: 1.0027 - val_accuracy: 0.4118 - 212ms/epoch - 27ms/step\n", + "2/2 [==============================] - 0s 2ms/step\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpxnb1o9sz/model/001/assets\n" + "INFO:tensorflow:Assets written to: /var/folders/4c/v1q3hy1x4mb5w0wpc72zl3_w0000gp/T/tmpr1a25iea/model/001/assets\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Validation accuracy: 0.2549019607843137\n", + "Validation accuracy: 0.4117647058823529\n", "\u001b[32m.\u001b[0m" ] }, @@ -2139,17 +2161,17 @@ "\u001b[1;38;5;39mCOMET INFO:\u001b[0m ---------------------------------------------------------------------------------------\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Data:\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m display_summary_level : 1\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m url : https://www.comet.com/svpino/ml-school/8ecdde1cf77a4e6eb07d74159a662ab8\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m url : https://www.comet.com/svpino/ml-school/f883d4f905344223a831a0fd42c7d34b\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Metrics:\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m accuracy : 0.06694560497999191\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m batch_accuracy : 0.0625\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m batch_loss : 1.152015209197998\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m epoch_duration : 0.1679564579972066\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m loss : 1.1654127836227417\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m val_accuracy : 0.2549019753932953\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m val_loss : 1.0734405517578125\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m validate_batch_accuracy : 0.25\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m validate_batch_loss : 1.099074125289917\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m accuracy : 0.3974895477294922\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m batch_accuracy : 0.5\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m batch_loss : 1.02028489112854\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m epoch_duration : 0.21225383295677602\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m loss : 1.0479480028152466\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m val_accuracy : 0.4117647111415863\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m val_loss : 1.00267493724823\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m validate_batch_accuracy : 0.375\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m validate_batch_loss : 1.0365104675292969\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Others:\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m trainable_params : 195\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Parameters:\n", @@ -2176,10 +2198,9 @@ "\u001b[1;38;5;39mCOMET INFO:\u001b[0m git metadata : 1\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m installed packages : 1\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m model graph : 1\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m model-element : 5 (92.30 KB)\n", + "\u001b[1;38;5;39mCOMET INFO:\u001b[0m model-element : 5 (92.54 KB)\n", "\u001b[1;38;5;39mCOMET INFO:\u001b[0m \n", - "\u001b[1;38;5;214mCOMET WARNING:\u001b[0m To get all data logged automatically, import comet_ml before the following modules: sklearn.\n", - "\u001b[1;38;5;39mCOMET INFO:\u001b[0m Please wait for metadata to finish uploading (timeout is 3600 seconds)\n" + "\u001b[1;38;5;214mCOMET WARNING:\u001b[0m To get all data logged automatically, import comet_ml before the following modules: sklearn.\n" ] }, { @@ -2187,7 +2208,7 @@ "output_type": "stream", "text": [ "\n", - "\u001b[32m\u001b[32m\u001b[1m2 passed\u001b[0m\u001b[32m in 8.61s\u001b[0m\u001b[0m\n" + "\u001b[32m\u001b[32m\u001b[1m2 passed\u001b[0m\u001b[32m in 10.06s\u001b[0m\u001b[0m\n" ] } ], @@ -2198,10 +2219,8 @@ "\n", "import os\n", "import shutil\n", - "import tarfile\n", "import pytest\n", "import tempfile\n", - "import joblib\n", "\n", "from comet_ml import Experiment\n", "from processing.script import preprocess\n", @@ -2265,9 +2284,11 @@ "\n", "We can now create a [Training Step](https://docs.aws.amazon.com/sagemaker/latest/dg/build-and-manage-steps.html#step-type-training) that we can add to the pipeline. This Training Step will create a SageMaker Training Job in the background, run the training script, and upload the output to S3. Check the [TrainingStep](https://sagemaker.readthedocs.io/en/stable/workflows/pipelines/sagemaker.workflow.pipelines.html#sagemaker.workflow.steps.TrainingStep) SageMaker's SDK documentation for more information.\n", "\n", - "SageMaker manages the infrastructure of a Training Job. It provisions resources for the duration of the job, and cleans up when it completes. The Training Container image that SageMaker uses to run a Training Job can either be a SageMaker built-in image or a custom image. The [Docker Registry Paths and Example Code](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-algo-docker-registry-paths.html) page contains information about the available framework versions for each region. Here, you can also check the available SageMaker [Deep Learning Container images](https://github.com/aws/deep-learning-containers/blob/master/available_images.md).\n", + "SageMaker manages the infrastructure of a Training Job. It provisions resources for the duration of the job, and cleans up when it completes. The Training Container image that SageMaker uses to run a Training Job can either be a SageMaker built-in image or a custom image.\n", + "\n", + " \"High-level\n", "\n", - " \"High-level\n" + "The [Available Deep Learning Container Images](https://github.com/aws/deep-learning-containers/blob/master/available_images.md) page contains the list of available containers for each region.\n" ] }, { @@ -2280,7 +2301,7 @@ }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 101, "id": "d00eda86", "metadata": {}, "outputs": [ @@ -2322,7 +2343,7 @@ }, { "cell_type": "code", - "execution_count": 100, + "execution_count": 102, "id": "90fe82ae-6a2c-4461-bc83-bb52d8871e3b", "metadata": { "tags": [] @@ -2388,7 +2409,7 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 103, "id": "99e4850c-83d6-4f4e-a813-d5a3f4bb7486", "metadata": { "tags": [] @@ -2458,7 +2479,7 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 104, "id": "d92cac3d", "metadata": {}, "outputs": [ @@ -2466,13 +2487,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ + "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n", "INFO:sagemaker.image_uris:image_uri is not presented, retrieving image_uri based on instance_type, framework etc.\n" ] }, @@ -2480,16 +2495,16 @@ "data": { "text/plain": [ "{'PipelineArn': 'arn:aws:sagemaker:us-east-1:325223348818:pipeline/session4-pipeline',\n", - " 'ResponseMetadata': {'RequestId': 'b07207ea-36c9-4c59-9953-698da368feb2',\n", + " 'ResponseMetadata': {'RequestId': 'd4826609-9bc7-4f05-8e44-044cb2482a5c',\n", " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': 'b07207ea-36c9-4c59-9953-698da368feb2',\n", + " 'HTTPHeaders': {'x-amzn-requestid': 'd4826609-9bc7-4f05-8e44-044cb2482a5c',\n", " 'content-type': 'application/x-amz-json-1.1',\n", " 'content-length': '85',\n", - " 'date': 'Mon, 25 Mar 2024 21:27:03 GMT'},\n", + " 'date': 'Mon, 25 Mar 2024 23:43:03 GMT'},\n", " 'RetryAttempts': 0}}" ] }, - "execution_count": 102, + "execution_count": 104, "metadata": {}, "output_type": "execute_result" } @@ -9159,7 +9174,7 @@ "source": [ "## Running the Pipeline\n", "\n", - "We can run any of the pipelines we defined below by enabling the cell below and specifying the pipeline we want to run.\n" + "We can run any of the pipelines we defined before by enabling the cell below and specifying the pipeline we want to run.\n" ] }, { @@ -9176,28 +9191,28 @@ }, { "cell_type": "code", - "execution_count": 103, + "execution_count": 105, "id": "59d1e634", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "_PipelineExecution(arn='arn:aws:sagemaker:us-east-1:325223348818:pipeline/session4-pipeline/execution/7pduxtmpsv2c', sagemaker_session=)" + "_PipelineExecution(arn='arn:aws:sagemaker:us-east-1:325223348818:pipeline/session4-pipeline/execution/awtz4v8hgugf', sagemaker_session=)" ] }, - "execution_count": 103, + "execution_count": 105, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# %%script false --no-raise-error\n", + "%%script false --no-raise-error\n", "# | eval: false\n", "# | code: true\n", "# | output: false\n", "\n", - "session4_pipeline.start()" + "session3_pipeline.start()" ] }, {