From bed3d4c3843b43c7e766354036b28346dfbb7bff Mon Sep 17 00:00:00 2001 From: Mehrin Kiani Date: Thu, 25 Jan 2024 17:26:39 -0500 Subject: [PATCH 1/5] Update notebooks --- notebooks/keras_fashion_mnist.ipynb | 109 +++++++++---- notebooks/pytorch_sentiment_analysis.ipynb | 100 ++++++++---- notebooks/tensorflow_fashion_mnist.ipynb | 150 ++++++++---------- .../xgboost_diabetes_classification.ipynb | 77 +++++++-- 4 files changed, 278 insertions(+), 158 deletions(-) diff --git a/notebooks/keras_fashion_mnist.ipynb b/notebooks/keras_fashion_mnist.ipynb index af136a7..9cdfd45 100644 --- a/notebooks/keras_fashion_mnist.ipynb +++ b/notebooks/keras_fashion_mnist.ipynb @@ -11,9 +11,18 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "modelscan, version 0.5.0\n" + ] + } + ], "source": [ - "!pip install -q modelscan" + "!pip install -q modelscan\n", + "!modelscan -v" ] }, { @@ -58,35 +67,35 @@ "output_type": "stream", "text": [ "Epoch 1/10\n", - "1875/1875 [==============================] - 2s 773us/step - loss: 0.5034 - accuracy: 0.8228\n", + "1875/1875 [==============================] - 1s 726us/step - loss: 0.4988 - accuracy: 0.8246\n", "Epoch 2/10\n", - "1875/1875 [==============================] - 1s 738us/step - loss: 0.3762 - accuracy: 0.8640\n", + "1875/1875 [==============================] - 1s 754us/step - loss: 0.3765 - accuracy: 0.8641\n", "Epoch 3/10\n", - "1875/1875 [==============================] - 1s 760us/step - loss: 0.3358 - accuracy: 0.8769\n", + "1875/1875 [==============================] - 1s 729us/step - loss: 0.3408 - accuracy: 0.8752\n", "Epoch 4/10\n", - "1875/1875 [==============================] - 1s 733us/step - loss: 0.3114 - accuracy: 0.8854\n", + "1875/1875 [==============================] - 1s 772us/step - loss: 0.3138 - accuracy: 0.8853\n", "Epoch 5/10\n", - "1875/1875 [==============================] - 1s 743us/step - loss: 0.2949 - accuracy: 0.8909\n", + "1875/1875 [==============================] - 1s 716us/step - loss: 0.2953 - accuracy: 0.8916\n", "Epoch 6/10\n", - "1875/1875 [==============================] - 1s 731us/step - loss: 0.2816 - accuracy: 0.8962\n", + "1875/1875 [==============================] - 1s 744us/step - loss: 0.2817 - accuracy: 0.8964\n", "Epoch 7/10\n", - "1875/1875 [==============================] - 1s 743us/step - loss: 0.2687 - accuracy: 0.9000\n", + "1875/1875 [==============================] - 1s 770us/step - loss: 0.2699 - accuracy: 0.8995\n", "Epoch 8/10\n", - "1875/1875 [==============================] - 1s 762us/step - loss: 0.2567 - accuracy: 0.9044\n", + "1875/1875 [==============================] - 1s 736us/step - loss: 0.2590 - accuracy: 0.9025\n", "Epoch 9/10\n", - "1875/1875 [==============================] - 1s 766us/step - loss: 0.2464 - accuracy: 0.9075\n", + "1875/1875 [==============================] - 1s 720us/step - loss: 0.2475 - accuracy: 0.9072\n", "Epoch 10/10\n", - "1875/1875 [==============================] - 1s 737us/step - loss: 0.2372 - accuracy: 0.9113\n", - "313/313 [==============================] - 0s 490us/step - loss: 0.3440 - accuracy: 0.8827\n", + "1875/1875 [==============================] - 1s 747us/step - loss: 0.2403 - accuracy: 0.9109\n", + "313/313 [==============================] - 0s 480us/step - loss: 0.3441 - accuracy: 0.8793\n", "\n", - "Model trained with test accuracy: 0.8827000260353088\n" + "Model trained with test accuracy: 0.8792999982833862\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "/Users/mehrinkiani/mambaforge/envs/notebooks-xgb-2/lib/python3.9/site-packages/keras/src/engine/training.py:3000: UserWarning: You are saving your model as an HDF5 file via `model.save()`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')`.\n", + "/Users/mehrinkiani/mambaforge/envs/py310/lib/python3.10/site-packages/keras/src/engine/training.py:3000: UserWarning: You are saving your model as an HDF5 file via `model.save()`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')`.\n", " saving_api.save_model(\n" ] } @@ -117,9 +126,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "1/1 [==============================] - 0s 35ms/step\n", + "1/1 [==============================] - 0s 34ms/step\n", "\n", - "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 98.059 99.993996 100. ]\n", + "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 99.396 99.94 100. ]\n", "\n", "The true labels are ['Ankle boot', 'Pullover', 'Trouser']\n" ] @@ -159,7 +168,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/KerasModels/safe_model.h5 using hdf5 model scan\n", + "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", + "\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/KerasModels/safe_model.h5 using modelscan.scanners.H5LambdaDetectScan model scan\n", "\n", "\u001b[34m--- Summary ---\u001b[0m\n", "\n", @@ -244,9 +255,9 @@ "aws_secret_access_key=\n", "aws_access_key_id=\n", "aws_secret_access_key=\n", - "1/1 [==============================] - 0s 29ms/step\n", + "1/1 [==============================] - 0s 28ms/step\n", "\n", - "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 98.059 99.993996 100. ]\n", + "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 99.396 99.94 100. ]\n", "\n", "The true labels are ['Ankle boot', 'Pullover', 'Trouser']\n" ] @@ -289,7 +300,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/KerasModels/unsafe_model.h5 using hdf5 model scan\n", + "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", + "\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/KerasModels/unsafe_model.h5 using modelscan.scanners.H5LambdaDetectScan model scan\n", "\n", "\u001b[34m--- Summary ---\u001b[0m\n", "\n", @@ -317,17 +330,59 @@ "!modelscan -p KerasModels/unsafe_model.h5" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Reporting Format\n", + "ModelScan can report scan results in console (default), JSON, or custom report (to be defined by user in settings-file). For mode details, please see: ` modelscan -h` " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## JSON Report\n", + "\n", + "For JSON reporting: `modelscan -p ./path-to/file -r json -o output-file-name.json` \n" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", + "\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt:unsafe_model/data.pkl using modelscan.scanners.PickleUnsafeOpScan model scan\n", + "\u001b[1m{\u001b[0m\u001b[32m\"modelscan_version\"\u001b[0m: \u001b[32m\"0.5.0\"\u001b[0m, \u001b[32m\"timestamp\"\u001b[0m: \u001b[32m\"2024-01-25T17:11:52.483755\"\u001b[0m, \n", + "\u001b[32m\"input_path\"\u001b[0m: \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt\"\u001b[0m\n", + ", \u001b[32m\"total_issues\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"summary\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"LOW\"\u001b[0m: \u001b[1;36m0\u001b[0m, \n", + "\u001b[32m\"MEDIUM\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"HIGH\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"CRITICAL\"\u001b[0m: \u001b[1;36m1\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"CRITICAL\"\u001b[0m: \n", + "\u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m\"description\"\u001b[0m: \u001b[32m\"Use of unsafe operator 'system' from module 'posix'\"\u001b[0m, \n", + "\u001b[32m\"operator\"\u001b[0m: \u001b[32m\"system\"\u001b[0m, \u001b[32m\"module\"\u001b[0m: \u001b[32m\"posix\"\u001b[0m, \u001b[32m\"source\"\u001b[0m: \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt:\u001b[0m\n", + "\u001b[32munsafe_model/data.pkl\"\u001b[0m, \u001b[32m\"scanner\"\u001b[0m: \u001b[32m\"modelscan.scanners.PickleUnsafeOpScan\"\u001b[0m\u001b[1m}\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m, \n", + "\u001b[32m\"errors\"\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m]\u001b[0m, \u001b[32m\"scanned\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_scanned\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"scanned_files\"\u001b[0m: \n", + "\u001b[1m[\u001b[0m\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt\u001b[0m\n", + "\u001b[32m:unsafe_model/data.pkl\"\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m\n" + ] + } + ], + "source": [ + "# This will save the scan results in file: keras-model-scan-results.json\n", + "!modelscan --path ./PyTorchModels/unsafe_model.pt -r json -o keras-model-scan-results.json" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3.9.16 ('notebooks-xgb-2')", + "display_name": "Python 3.10.13 ('py310')", "language": "python", "name": "python3" }, @@ -341,12 +396,12 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.10.13" }, "orig_nbformat": 4, "vscode": { "interpreter": { - "hash": "8792b9cba3843e3778a70fb92fd4a6e11f0e29f4d97b60d08b903ca0b490cce6" + "hash": "bd638e2064d9001d4ca93bc8e56e039dad230900dd235e8a6196f1614960903a" } } }, diff --git a/notebooks/pytorch_sentiment_analysis.ipynb b/notebooks/pytorch_sentiment_analysis.ipynb index b9401a2..282439b 100644 --- a/notebooks/pytorch_sentiment_analysis.ipynb +++ b/notebooks/pytorch_sentiment_analysis.ipynb @@ -11,7 +11,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Installing modelscan" + "## Installing ModelScan" ] }, { @@ -23,34 +23,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "Collecting modelscan\n", - " Obtaining dependency information for modelscan from https://files.pythonhosted.org/packages/bf/6e/dda8f775b53c307bd59042a7d20143b3f0d068e9b9c6776cf07a28ce208d/modelscan-0.1.1-py3-none-any.whl.metadata\n", - " Using cached modelscan-0.1.1-py3-none-any.whl.metadata (5.1 kB)\n", - "Collecting click<9.0.0,>=8.1.3 (from modelscan)\n", - " Obtaining dependency information for click<9.0.0,>=8.1.3 from https://files.pythonhosted.org/packages/1a/70/e63223f8116931d365993d4a6b7ef653a4d920b41d03de7c59499962821f/click-8.1.6-py3-none-any.whl.metadata\n", - " Using cached click-8.1.6-py3-none-any.whl.metadata (3.0 kB)\n", - "Collecting numpy==1.24.0 (from modelscan)\n", - " Using cached numpy-1.24.0-cp39-cp39-macosx_11_0_arm64.whl (13.9 MB)\n", - "Collecting rich<14.0.0,>=13.4.2 (from modelscan)\n", - " Obtaining dependency information for rich<14.0.0,>=13.4.2 from https://files.pythonhosted.org/packages/8d/5f/21a93b2ec205f4b79853ff6e838e3c99064d5dbe85ec6b05967506f14af0/rich-13.5.2-py3-none-any.whl.metadata\n", - " Using cached rich-13.5.2-py3-none-any.whl.metadata (18 kB)\n", - "Collecting markdown-it-py>=2.2.0 (from rich<14.0.0,>=13.4.2->modelscan)\n", - " Obtaining dependency information for markdown-it-py>=2.2.0 from https://files.pythonhosted.org/packages/42/d7/1ec15b46af6af88f19b8e5ffea08fa375d433c998b8a7639e76935c14f1f/markdown_it_py-3.0.0-py3-none-any.whl.metadata\n", - " Using cached markdown_it_py-3.0.0-py3-none-any.whl.metadata (6.9 kB)\n", - "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /Users/mehrinkiani/mambaforge/envs/notebooks-pt/lib/python3.9/site-packages (from rich<14.0.0,>=13.4.2->modelscan) (2.15.1)\n", - "Collecting mdurl~=0.1 (from markdown-it-py>=2.2.0->rich<14.0.0,>=13.4.2->modelscan)\n", - " Using cached mdurl-0.1.2-py3-none-any.whl (10.0 kB)\n", - "Using cached modelscan-0.1.1-py3-none-any.whl (22 kB)\n", - "Using cached click-8.1.6-py3-none-any.whl (97 kB)\n", - "Using cached rich-13.5.2-py3-none-any.whl (239 kB)\n", - "Using cached markdown_it_py-3.0.0-py3-none-any.whl (87 kB)\n", - "Installing collected packages: numpy, mdurl, click, markdown-it-py, rich, modelscan\n", - "Successfully installed click-8.1.6 markdown-it-py-3.0.0 mdurl-0.1.2 modelscan-0.1.1 numpy-1.24.0 rich-13.5.2\n" + "modelscan, version 0.5.0\n" ] } ], "source": [ - "!pip install modelscan" + "!pip install -q modelscan\n", + "!modelscan -v" ] }, { @@ -73,7 +52,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/Users/mehrinkiani/mambaforge/envs/notebooks-pt/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + "/Users/mehrinkiani/mambaforge/envs/py310/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, @@ -147,7 +126,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Scan the Safe Model\n", + "# Scan Safe Model\n", "\n", "The scan results include information on the files scanned, and any issues if found. For the safe model scanned, modelscan finds no model serialization attacks, as expected." ] @@ -161,7 +140,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/safe_model.pt:safe_model/data.pkl using pickle model scan\n", + "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", + "\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/safe_model.pt:safe_model/data.pkl using modelscan.scanners.PickleUnsafeOpScan model scan\n", "\n", "\u001b[34m--- Summary ---\u001b[0m\n", "\n", @@ -237,7 +218,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Scanning Unsafe Model\n", + "# Scan Unsafe Model\n", "\n", "The scan results include information on the files scanned, and any issues if found. In this case, a critical severity level issue is found in the unsafe model scanned. \n", "\n", @@ -253,7 +234,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt:unsafe_model/data.pkl using pickle model scan\n", + "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", + "\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt:unsafe_model/data.pkl using modelscan.scanners.PickleUnsafeOpScan model scan\n", "\n", "\u001b[34m--- Summary ---\u001b[0m\n", "\n", @@ -278,7 +261,56 @@ } ], "source": [ - "!modelscan --path ./PyTorchModels/unsafe_model.pt" + "!modelscan --path ./PyTorchModels/unsafe_model.pt " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Reporting Format\n", + "ModelScan can report scan results in console (default), json, or custom report (to be defined by user in settings-file). For mode details, please see: ` modelscan -h` " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## JSON Report\n", + "\n", + "For JSON reporting: `modelscan -p ./path-to/file -r json -o output-file-name.json` " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", + "\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt:unsafe_model/data.pkl using modelscan.scanners.PickleUnsafeOpScan model scan\n", + "\u001b[1m{\u001b[0m\u001b[32m\"modelscan_version\"\u001b[0m: \u001b[32m\"0.5.0\"\u001b[0m, \u001b[32m\"timestamp\"\u001b[0m: \u001b[32m\"2024-01-25T17:10:54.306065\"\u001b[0m, \n", + "\u001b[32m\"input_path\"\u001b[0m: \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt\"\u001b[0m\n", + ", \u001b[32m\"total_issues\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"summary\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"LOW\"\u001b[0m: \u001b[1;36m0\u001b[0m, \n", + "\u001b[32m\"MEDIUM\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"HIGH\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"CRITICAL\"\u001b[0m: \u001b[1;36m1\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"CRITICAL\"\u001b[0m: \n", + "\u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m\"description\"\u001b[0m: \u001b[32m\"Use of unsafe operator 'system' from module 'posix'\"\u001b[0m, \n", + "\u001b[32m\"operator\"\u001b[0m: \u001b[32m\"system\"\u001b[0m, \u001b[32m\"module\"\u001b[0m: \u001b[32m\"posix\"\u001b[0m, \u001b[32m\"source\"\u001b[0m: \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt:\u001b[0m\n", + "\u001b[32munsafe_model/data.pkl\"\u001b[0m, \u001b[32m\"scanner\"\u001b[0m: \u001b[32m\"modelscan.scanners.PickleUnsafeOpScan\"\u001b[0m\u001b[1m}\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m, \n", + "\u001b[32m\"errors\"\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m]\u001b[0m, \u001b[32m\"scanned\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_scanned\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"scanned_files\"\u001b[0m: \n", + "\u001b[1m[\u001b[0m\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt\u001b[0m\n", + "\u001b[32m:unsafe_model/data.pkl\"\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m\n" + ] + } + ], + "source": [ + "# This will save the scan results in file: pytorch-model-scan-results.json\n", + "!modelscan --path ./PyTorchModels/unsafe_model.pt -r json -o pytorch-model-scan-results.json" ] }, { @@ -291,7 +323,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.9.16 ('notebooks-pt')", + "display_name": "Python 3.10.13 ('py310')", "language": "python", "name": "python3" }, @@ -305,11 +337,11 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.10.13" }, "vscode": { "interpreter": { - "hash": "95ff33cfa0d19b4e14b9fe5f5453ae67cda9106db59c9cf5735c1bf946b2200c" + "hash": "bd638e2064d9001d4ca93bc8e56e039dad230900dd235e8a6196f1614960903a" } } }, diff --git a/notebooks/tensorflow_fashion_mnist.ipynb b/notebooks/tensorflow_fashion_mnist.ipynb index d420324..12203df 100644 --- a/notebooks/tensorflow_fashion_mnist.ipynb +++ b/notebooks/tensorflow_fashion_mnist.ipynb @@ -16,18 +16,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "Requirement already satisfied: modelscan in /Users/mehrinkiani/mambaforge/envs/notebooks-xgb-2/lib/python3.9/site-packages (0.1.1)\n", - "Requirement already satisfied: click<9.0.0,>=8.1.3 in /Users/mehrinkiani/mambaforge/envs/notebooks-xgb-2/lib/python3.9/site-packages (from modelscan) (8.1.6)\n", - "Requirement already satisfied: numpy==1.24.0 in /Users/mehrinkiani/mambaforge/envs/notebooks-xgb-2/lib/python3.9/site-packages (from modelscan) (1.24.0)\n", - "Requirement already satisfied: rich<14.0.0,>=13.4.2 in /Users/mehrinkiani/mambaforge/envs/notebooks-xgb-2/lib/python3.9/site-packages (from modelscan) (13.5.2)\n", - "Requirement already satisfied: markdown-it-py>=2.2.0 in /Users/mehrinkiani/mambaforge/envs/notebooks-xgb-2/lib/python3.9/site-packages (from rich<14.0.0,>=13.4.2->modelscan) (3.0.0)\n", - "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /Users/mehrinkiani/mambaforge/envs/notebooks-xgb-2/lib/python3.9/site-packages (from rich<14.0.0,>=13.4.2->modelscan) (2.15.1)\n", - "Requirement already satisfied: mdurl~=0.1 in /Users/mehrinkiani/mambaforge/envs/notebooks-xgb-2/lib/python3.9/site-packages (from markdown-it-py>=2.2.0->rich<14.0.0,>=13.4.2->modelscan) (0.1.2)\n" + "modelscan, version 0.5.0\n" ] } ], "source": [ - "!pip install modelscan" + "!pip install -q modelscan\n", + "!modelscan -v" ] }, { @@ -73,28 +68,28 @@ "output_type": "stream", "text": [ "Epoch 1/10\n", - "1875/1875 [==============================] - 2s 752us/step - loss: 0.5000 - accuracy: 0.8244\n", + "1875/1875 [==============================] - 2s 741us/step - loss: 0.4967 - accuracy: 0.8252\n", "Epoch 2/10\n", - "1875/1875 [==============================] - 1s 726us/step - loss: 0.3774 - accuracy: 0.8637\n", + "1875/1875 [==============================] - 1s 699us/step - loss: 0.3739 - accuracy: 0.8662\n", "Epoch 3/10\n", - "1875/1875 [==============================] - 1s 734us/step - loss: 0.3386 - accuracy: 0.8767\n", + "1875/1875 [==============================] - 1s 690us/step - loss: 0.3390 - accuracy: 0.8767\n", "Epoch 4/10\n", - "1875/1875 [==============================] - 1s 730us/step - loss: 0.3131 - accuracy: 0.8858\n", + "1875/1875 [==============================] - 1s 719us/step - loss: 0.3143 - accuracy: 0.8855\n", "Epoch 5/10\n", - "1875/1875 [==============================] - 1s 750us/step - loss: 0.2943 - accuracy: 0.8921\n", + "1875/1875 [==============================] - 1s 703us/step - loss: 0.2945 - accuracy: 0.8920\n", "Epoch 6/10\n", - "1875/1875 [==============================] - 1s 735us/step - loss: 0.2821 - accuracy: 0.8953\n", + "1875/1875 [==============================] - 1s 745us/step - loss: 0.2810 - accuracy: 0.8951\n", "Epoch 7/10\n", - "1875/1875 [==============================] - 1s 731us/step - loss: 0.2686 - accuracy: 0.9007\n", + "1875/1875 [==============================] - 1s 789us/step - loss: 0.2689 - accuracy: 0.8995\n", "Epoch 8/10\n", - "1875/1875 [==============================] - 1s 733us/step - loss: 0.2586 - accuracy: 0.9029\n", + "1875/1875 [==============================] - 1s 732us/step - loss: 0.2602 - accuracy: 0.9026\n", "Epoch 9/10\n", - "1875/1875 [==============================] - 1s 753us/step - loss: 0.2493 - accuracy: 0.9068\n", + "1875/1875 [==============================] - 1s 724us/step - loss: 0.2493 - accuracy: 0.9062\n", "Epoch 10/10\n", - "1875/1875 [==============================] - 1s 731us/step - loss: 0.2390 - accuracy: 0.9104\n", - "313/313 [==============================] - 0s 482us/step - loss: 0.3422 - accuracy: 0.8820\n", + "1875/1875 [==============================] - 1s 736us/step - loss: 0.2411 - accuracy: 0.9090\n", + "313/313 [==============================] - 0s 487us/step - loss: 0.3440 - accuracy: 0.8816\n", "\n", - "Model trained with test accuracy: 0.8820000290870667\n" + "Model trained with test accuracy: 0.881600022315979\n" ] } ], @@ -127,7 +122,7 @@ "text": [ "1/1 [==============================] - 0s 35ms/step\n", "\n", - "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 95.854996 99.886 100. ]\n", + "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 91.275 99.15501 100. ]\n", "\n", "The true labels are ['Ankle boot', 'Pullover', 'Trouser']\n" ] @@ -166,13 +161,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/safe_model/fingerprint.pb using saved_model model scan\n", - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/safe_model/keras_metadata.pb using saved_model model scan\n", - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/safe_model/saved_model.pb using saved_model model scan\n", + "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", + "\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/safe_model/fingerprint.pb using modelscan.scanners.SavedModelTensorflowOpScan model scan\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/safe_model/keras_metadata.pb using modelscan.scanners.SavedModelLambdaDetectScan model scan\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/safe_model/saved_model.pb using modelscan.scanners.SavedModelTensorflowOpScan model scan\n", "\n", "\u001b[34m--- Summary ---\u001b[0m\n", "\n", - "\u001b[32m No issues found! 🎉\u001b[0m\n" + "\u001b[32m No issues found! 🎉\u001b[0m\n", + "\n", + "\u001b[34m--- Skipped --- \u001b[0m\n", + "\n", + "Total skipped: \u001b[1;36m2\u001b[0m - run with --show-skipped to see the full list.\n" ] } ], @@ -220,28 +221,18 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "File found: /tmp/aws_secret.txt\n", - "aws_access_key_id=\n", - "aws_secret_access_key=\n", - "1/1 [==============================] - 0s 48ms/step\n", - "\n", - "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 95.854996 99.886 100. ]\n", - "\n", - "The true labels are ['Ankle boot', 'Pullover', 'Trouser']\n" + "ename": "InvalidArgumentError", + "evalue": "Graph execution error:\n\nDetected at node 'list_files/assert_not_empty/Assert' defined at (most recent call last):\nNode: 'list_files/assert_not_empty/Assert'\nassertion failed: [No files matched pattern: /tmp/*.txt]\n\t [[{{node list_files/assert_not_empty/Assert}}]] [Op:__inference_predict_function_79667]", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mInvalidArgumentError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[8], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m unsafe_model_loaded \u001b[38;5;241m=\u001b[39m tf\u001b[38;5;241m.\u001b[39mkeras\u001b[38;5;241m.\u001b[39mmodels\u001b[38;5;241m.\u001b[39mload_model(unsafe_model_path)\n\u001b[1;32m 3\u001b[0m number_of_predictions \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m3\u001b[39m\n\u001b[0;32m----> 4\u001b[0m \u001b[43mget_predictions\u001b[49m\u001b[43m(\u001b[49m\u001b[43munsafe_model_loaded\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnumber_of_predictions\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Documents/modelscan/notebooks/utils/tensorflow_fashion_mnist_model.py:74\u001b[0m, in \u001b[0;36mget_predictions\u001b[0;34m(model, number_of_predictions)\u001b[0m\n\u001b[1;32m 71\u001b[0m get_test_data_only \u001b[39m=\u001b[39m \u001b[39mTrue\u001b[39;00m\n\u001b[1;32m 72\u001b[0m test_images, test_labels \u001b[39m=\u001b[39m get_data(get_test_data_only)\n\u001b[0;32m---> 74\u001b[0m model_output \u001b[39m=\u001b[39m model\u001b[39m.\u001b[39;49mpredict(test_images[\u001b[39m0\u001b[39;49m:number_of_predictions])\n\u001b[1;32m 75\u001b[0m prediction_probabilities \u001b[39m=\u001b[39m [np\u001b[39m.\u001b[39mmax(prob) \u001b[39mfor\u001b[39;00m prob \u001b[39min\u001b[39;00m model_output]\n\u001b[1;32m 76\u001b[0m prediction_labels \u001b[39m=\u001b[39m [class_names[np\u001b[39m.\u001b[39margmax(pred)] \u001b[39mfor\u001b[39;00m pred \u001b[39min\u001b[39;00m model_output]\n", + "File \u001b[0;32m~/mambaforge/envs/py310/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py:70\u001b[0m, in \u001b[0;36mfilter_traceback..error_handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 67\u001b[0m filtered_tb \u001b[39m=\u001b[39m _process_traceback_frames(e\u001b[39m.\u001b[39m__traceback__)\n\u001b[1;32m 68\u001b[0m \u001b[39m# To get the full stack trace, call:\u001b[39;00m\n\u001b[1;32m 69\u001b[0m \u001b[39m# `tf.debugging.disable_traceback_filtering()`\u001b[39;00m\n\u001b[0;32m---> 70\u001b[0m \u001b[39mraise\u001b[39;00m e\u001b[39m.\u001b[39mwith_traceback(filtered_tb) \u001b[39mfrom\u001b[39;00m \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 71\u001b[0m \u001b[39mfinally\u001b[39;00m:\n\u001b[1;32m 72\u001b[0m \u001b[39mdel\u001b[39;00m filtered_tb\n", + "File \u001b[0;32m~/mambaforge/envs/py310/lib/python3.10/site-packages/tensorflow/python/eager/execute.py:53\u001b[0m, in \u001b[0;36mquick_execute\u001b[0;34m(op_name, num_outputs, inputs, attrs, ctx, name)\u001b[0m\n\u001b[1;32m 51\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m 52\u001b[0m ctx\u001b[39m.\u001b[39mensure_initialized()\n\u001b[0;32m---> 53\u001b[0m tensors \u001b[39m=\u001b[39m pywrap_tfe\u001b[39m.\u001b[39mTFE_Py_Execute(ctx\u001b[39m.\u001b[39m_handle, device_name, op_name,\n\u001b[1;32m 54\u001b[0m inputs, attrs, num_outputs)\n\u001b[1;32m 55\u001b[0m \u001b[39mexcept\u001b[39;00m core\u001b[39m.\u001b[39m_NotOkStatusException \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 56\u001b[0m \u001b[39mif\u001b[39;00m name \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n", + "\u001b[0;31mInvalidArgumentError\u001b[0m: Graph execution error:\n\nDetected at node 'list_files/assert_not_empty/Assert' defined at (most recent call last):\nNode: 'list_files/assert_not_empty/Assert'\nassertion failed: [No files matched pattern: /tmp/*.txt]\n\t [[{{node list_files/assert_not_empty/Assert}}]] [Op:__inference_predict_function_79667]" ] - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgMAAAC5CAYAAAC1FTxtAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAckklEQVR4nO3de3BV1fXA8cUjIQQSCBAegRgGQcAqCCoWqMjDDkKtCjqllqKMFhVbpbW2WFsBf33oMHbUGVutM/hqBa2KglKK4qDlrVUTQN4CAUwAeScQnjm/P/akN8leG3YeJNy7v58ZR+7KOWef5O5zs3LOOus0iKIoEgAAEKyG9b0DAACgfpEMAAAQOJIBAAACRzIAAEDgSAYAAAgcyQAAAIEjGQAAIHAkAwAABK6xz0KlpaVSUFAgaWlp0qBBg3O9T0hQURRJUVGRZGVlScOGdZOHMndRG5i7iFe+c9crGSgoKJDs7Oxa2zmEbceOHdKpU6c6GYu5i9rE3EW8Otvc9UoG0tLS/rex9PT02tkzBOfw4cOSnZ39v/lUFxJx7hYVFVmxzz77TF128ODBtTp2bm6uGm/evLkV69q1a62OXZ+Yu2emdbXXzmZ89NFHVuy5555Tt9mrVy8rtnv3bivWpUsXK3bkyBErdvDg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WHz6qUl+RZizLnGbDMyYYa4Hlb8UUObmm81dA6tWVX27zZub00pRZP4CKp99lhk+3CQj779vTqN++9siTz5pbv06k2HDRLp1Exk0yFz3veGGitd+H3/c7Pu4cSZ73bxZZMECU+0tItKxo0kiPvnEXOu95x5zgJRPQh580DRguvhik0Fv3171nwHiwx13mF/kt90mcs015hbXIUP8109NNfNr/34zj2+5xczRZ56puFzXruaa7apVsbsIyvTqZW5n3bjR3KrVp49Jlun1geo62+dgq1Yi//iH+Sy89FJzFrj852ijRiL79pnj4qKLRH7wA/PHXdmdW8xZHY8wBgAgcHF7ZgAAANQOkgEAAAJHMgAAQOBIBgAACBzJAAAAgSMZAAAgcCQDAAAEjmQAAIDAkQwAABA4kgEAAAJHMgAAQOBIBgAACNz/A9cY/qpUgLgzAAAAAElFTkSuQmCC", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" } ], "source": [ @@ -264,59 +255,44 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/fingerprint.pb using saved_model model scan\n", - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/keras_metadata.pb using saved_model model scan\n", - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/saved_model.pb using saved_model model scan\n", - "\n", - "\u001b[34m--- Summary ---\u001b[0m\n", - "\n", - "Total Issues: \u001b[1;36m2\u001b[0m\n", - "\n", - "Total Issues By Severity:\n", - "\n", - " - LOW: \u001b[1;32m0\u001b[0m\n", - " - MEDIUM: \u001b[1;32m0\u001b[0m\n", - " - HIGH: \u001b[1;36m2\u001b[0m\n", - " - CRITICAL: \u001b[1;32m0\u001b[0m\n", - "\n", - "\u001b[34m--- Issues by Severity ---\u001b[0m\n", - "\n", - "\u001b[34m--- HIGH ---\u001b[0m\n", - "\n", - "Unsafe operator found:\n", - " - Severity: HIGH\n", - " - Description: Use of unsafe operator 'ReadFile' from module 'Tensorflow'\n", - " - Source: /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/saved_model.pb\n", - "\n", - "Unsafe operator found:\n", - " - Severity: HIGH\n", - " - Description: Use of unsafe operator 'WriteFile' from module 'Tensorflow'\n", - " - Source: /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/saved_model.pb\n" - ] - } - ], + "outputs": [], "source": [ "!modelscan -p TensorFlowModels/unsafe_model" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Reporting Format\n", + "ModelScan can report scan results in console (default), JSON, or custom report (to be defined by user in settings-file). For mode details, please see: ` modelscan -h` " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## JSON Report\n", + "\n", + "For JSON reporting: `modelscan -p ./path-to/file -r json -o output-file-name.json` " + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# This will save the scan results in file: tensorflow-model-scan-results.json\n", + "!modelscan --path ./PyTorchModels/unsafe_model.pt -r json -o tensorflow-model-scan-results.json" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3.9.16 ('notebooks-xgb-2')", + "display_name": "Python 3.10.13 ('py310')", "language": "python", "name": "python3" }, @@ -330,12 +306,12 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.10.13" }, "orig_nbformat": 4, "vscode": { "interpreter": { - "hash": "8792b9cba3843e3778a70fb92fd4a6e11f0e29f4d97b60d08b903ca0b490cce6" + "hash": "bd638e2064d9001d4ca93bc8e56e039dad230900dd235e8a6196f1614960903a" } } }, diff --git a/notebooks/xgboost_diabetes_classification.ipynb b/notebooks/xgboost_diabetes_classification.ipynb index 1ead323..b036bab 100644 --- a/notebooks/xgboost_diabetes_classification.ipynb +++ b/notebooks/xgboost_diabetes_classification.ipynb @@ -13,9 +13,18 @@ "execution_count": 1, "id": "00052a84", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "modelscan, version 0.5.0\n" + ] + } + ], "source": [ - "!pip install -q modelscan" + "!pip install -q modelscan\n", + "!modelscan -v" ] }, { @@ -119,7 +128,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/XGBoostModels/safe_model.pkl using pickle model scan\n", + "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", + "\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/XGBoostModels/safe_model.pkl using modelscan.scanners.PickleUnsafeOpScan model scan\n", "\n", "\u001b[34m--- Summary ---\u001b[0m\n", "\n", @@ -226,7 +237,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/XGBoostModels/unsafe_model.pkl using pickle model scan\n", + "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", + "\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/XGBoostModels/unsafe_model.pkl using modelscan.scanners.PickleUnsafeOpScan model scan\n", "\n", "\u001b[34m--- Summary ---\u001b[0m\n", "\n", @@ -254,18 +267,62 @@ "!modelscan -p XGBoostModels/unsafe_model.pkl" ] }, + { + "cell_type": "markdown", + "id": "9a908243", + "metadata": {}, + "source": [ + "# Reporting Format\n", + "ModelScan can report scan results in console (default), JSON, or custom report (to be defined by user in settings-file). For mode details, please see: ` modelscan -h` " + ] + }, + { + "cell_type": "markdown", + "id": "7ff858af", + "metadata": {}, + "source": [ + "## JSON Report\n", + "\n", + "For JSON reporting: `modelscan -p ./path-to/file -r json -o output-file-name.json` " + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "6df55b3e", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", + "\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt:unsafe_model/data.pkl using modelscan.scanners.PickleUnsafeOpScan model scan\n", + "\u001b[1m{\u001b[0m\u001b[32m\"modelscan_version\"\u001b[0m: \u001b[32m\"0.5.0\"\u001b[0m, \u001b[32m\"timestamp\"\u001b[0m: \u001b[32m\"2024-01-25T17:03:14.320664\"\u001b[0m, \n", + "\u001b[32m\"input_path\"\u001b[0m: \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt\"\u001b[0m\n", + ", \u001b[32m\"total_issues\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"summary\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"LOW\"\u001b[0m: \u001b[1;36m0\u001b[0m, \n", + "\u001b[32m\"MEDIUM\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"HIGH\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"CRITICAL\"\u001b[0m: \u001b[1;36m1\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"CRITICAL\"\u001b[0m: \n", + "\u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m\"description\"\u001b[0m: \u001b[32m\"Use of unsafe operator 'system' from module 'posix'\"\u001b[0m, \n", + "\u001b[32m\"operator\"\u001b[0m: \u001b[32m\"system\"\u001b[0m, \u001b[32m\"module\"\u001b[0m: \u001b[32m\"posix\"\u001b[0m, \u001b[32m\"source\"\u001b[0m: \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt:\u001b[0m\n", + "\u001b[32munsafe_model/data.pkl\"\u001b[0m, \u001b[32m\"scanner\"\u001b[0m: \u001b[32m\"modelscan.scanners.PickleUnsafeOpScan\"\u001b[0m\u001b[1m}\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m, \n", + "\u001b[32m\"errors\"\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m]\u001b[0m, \u001b[32m\"scanned\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_scanned\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"scanned_files\"\u001b[0m: \n", + "\u001b[1m[\u001b[0m\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt\u001b[0m\n", + "\u001b[32m:unsafe_model/data.pkl\"\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m\n" + ] + } + ], + "source": [ + "# This will save the scan results in file: xgboost-model-scan-results.json\n", + "!modelscan --path ./PyTorchModels/unsafe_model.pt -r json -o xgboost-model-scan-results.json" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3.9.16 ('notebooks-xgb-2')", + "display_name": "Python 3.10.13 ('py310')", "language": "python", "name": "python3" }, @@ -279,11 +336,11 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.10.13" }, "vscode": { "interpreter": { - "hash": "8792b9cba3843e3778a70fb92fd4a6e11f0e29f4d97b60d08b903ca0b490cce6" + "hash": "bd638e2064d9001d4ca93bc8e56e039dad230900dd235e8a6196f1614960903a" } } }, From 31d2d3a0575f5656d130bd95894ebf51e591eec4 Mon Sep 17 00:00:00 2001 From: Mehrin Kiani Date: Thu, 25 Jan 2024 17:57:52 -0500 Subject: [PATCH 2/5] update scan command --- notebooks/keras_fashion_mnist.ipynb | 65 ++++---- notebooks/tensorflow_fashion_mnist.ipynb | 150 ++++++++++++++---- .../xgboost_diabetes_classification.ipynb | 20 +-- 3 files changed, 166 insertions(+), 69 deletions(-) diff --git a/notebooks/keras_fashion_mnist.ipynb b/notebooks/keras_fashion_mnist.ipynb index 9cdfd45..a1e2b36 100644 --- a/notebooks/keras_fashion_mnist.ipynb +++ b/notebooks/keras_fashion_mnist.ipynb @@ -67,28 +67,28 @@ "output_type": "stream", "text": [ "Epoch 1/10\n", - "1875/1875 [==============================] - 1s 726us/step - loss: 0.4988 - accuracy: 0.8246\n", + "1875/1875 [==============================] - 2s 1ms/step - loss: 0.4986 - accuracy: 0.8258\n", "Epoch 2/10\n", - "1875/1875 [==============================] - 1s 754us/step - loss: 0.3765 - accuracy: 0.8641\n", + "1875/1875 [==============================] - 2s 800us/step - loss: 0.3741 - accuracy: 0.8649\n", "Epoch 3/10\n", - "1875/1875 [==============================] - 1s 729us/step - loss: 0.3408 - accuracy: 0.8752\n", + "1875/1875 [==============================] - 1s 772us/step - loss: 0.3391 - accuracy: 0.8766\n", "Epoch 4/10\n", - "1875/1875 [==============================] - 1s 772us/step - loss: 0.3138 - accuracy: 0.8853\n", + "1875/1875 [==============================] - 1s 755us/step - loss: 0.3125 - accuracy: 0.8852\n", "Epoch 5/10\n", - "1875/1875 [==============================] - 1s 716us/step - loss: 0.2953 - accuracy: 0.8916\n", + "1875/1875 [==============================] - 2s 965us/step - loss: 0.2955 - accuracy: 0.8908\n", "Epoch 6/10\n", - "1875/1875 [==============================] - 1s 744us/step - loss: 0.2817 - accuracy: 0.8964\n", + "1875/1875 [==============================] - 2s 905us/step - loss: 0.2808 - accuracy: 0.8963\n", "Epoch 7/10\n", - "1875/1875 [==============================] - 1s 770us/step - loss: 0.2699 - accuracy: 0.8995\n", + "1875/1875 [==============================] - 2s 1ms/step - loss: 0.2696 - accuracy: 0.9004\n", "Epoch 8/10\n", - "1875/1875 [==============================] - 1s 736us/step - loss: 0.2590 - accuracy: 0.9025\n", + "1875/1875 [==============================] - 2s 895us/step - loss: 0.2587 - accuracy: 0.9039\n", "Epoch 9/10\n", - "1875/1875 [==============================] - 1s 720us/step - loss: 0.2475 - accuracy: 0.9072\n", + "1875/1875 [==============================] - 2s 925us/step - loss: 0.2479 - accuracy: 0.9068\n", "Epoch 10/10\n", - "1875/1875 [==============================] - 1s 747us/step - loss: 0.2403 - accuracy: 0.9109\n", - "313/313 [==============================] - 0s 480us/step - loss: 0.3441 - accuracy: 0.8793\n", + "1875/1875 [==============================] - 2s 893us/step - loss: 0.2406 - accuracy: 0.9112\n", + "313/313 [==============================] - 0s 555us/step - loss: 0.3496 - accuracy: 0.8790\n", "\n", - "Model trained with test accuracy: 0.8792999982833862\n" + "Model trained with test accuracy: 0.8790000081062317\n" ] }, { @@ -126,9 +126,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "1/1 [==============================] - 0s 34ms/step\n", + "1/1 [==============================] - 0s 42ms/step\n", "\n", - "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 99.396 99.94 100. ]\n", + "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 98.948 99.926 100. ]\n", "\n", "The true labels are ['Ankle boot', 'Pullover', 'Trouser']\n" ] @@ -255,9 +255,9 @@ "aws_secret_access_key=\n", "aws_access_key_id=\n", "aws_secret_access_key=\n", - "1/1 [==============================] - 0s 28ms/step\n", + "1/1 [==============================] - 0s 35ms/step\n", "\n", - "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 99.396 99.94 100. ]\n", + "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 98.948 99.926 100. ]\n", "\n", "The true labels are ['Ankle boot', 'Pullover', 'Trouser']\n" ] @@ -358,26 +358,33 @@ "text": [ "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", "\n", - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt:unsafe_model/data.pkl using modelscan.scanners.PickleUnsafeOpScan model scan\n", - "\u001b[1m{\u001b[0m\u001b[32m\"modelscan_version\"\u001b[0m: \u001b[32m\"0.5.0\"\u001b[0m, \u001b[32m\"timestamp\"\u001b[0m: \u001b[32m\"2024-01-25T17:11:52.483755\"\u001b[0m, \n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/KerasModels/unsafe_model.h5 using modelscan.scanners.H5LambdaDetectScan model scan\n", + "\u001b[1m{\u001b[0m\u001b[32m\"modelscan_version\"\u001b[0m: \u001b[32m\"0.5.0\"\u001b[0m, \u001b[32m\"timestamp\"\u001b[0m: \u001b[32m\"2024-01-25T17:56:36.776966\"\u001b[0m, \n", "\u001b[32m\"input_path\"\u001b[0m: \n", - "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt\"\u001b[0m\n", - ", \u001b[32m\"total_issues\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"summary\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"LOW\"\u001b[0m: \u001b[1;36m0\u001b[0m, \n", - "\u001b[32m\"MEDIUM\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"HIGH\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"CRITICAL\"\u001b[0m: \u001b[1;36m1\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"CRITICAL\"\u001b[0m: \n", - "\u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m\"description\"\u001b[0m: \u001b[32m\"Use of unsafe operator 'system' from module 'posix'\"\u001b[0m, \n", - "\u001b[32m\"operator\"\u001b[0m: \u001b[32m\"system\"\u001b[0m, \u001b[32m\"module\"\u001b[0m: \u001b[32m\"posix\"\u001b[0m, \u001b[32m\"source\"\u001b[0m: \n", - "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt:\u001b[0m\n", - "\u001b[32munsafe_model/data.pkl\"\u001b[0m, \u001b[32m\"scanner\"\u001b[0m: \u001b[32m\"modelscan.scanners.PickleUnsafeOpScan\"\u001b[0m\u001b[1m}\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m, \n", - "\u001b[32m\"errors\"\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m]\u001b[0m, \u001b[32m\"scanned\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_scanned\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"scanned_files\"\u001b[0m: \n", - "\u001b[1m[\u001b[0m\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt\u001b[0m\n", - "\u001b[32m:unsafe_model/data.pkl\"\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m\n" + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/KerasModels/unsafe_model.h5\"\u001b[0m, \n", + "\u001b[32m\"total_issues\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"summary\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"LOW\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"MEDIUM\"\u001b[0m: \n", + "\u001b[1;36m1\u001b[0m, \u001b[32m\"HIGH\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"CRITICAL\"\u001b[0m: \u001b[1;36m0\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"MEDIUM\"\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m\"description\"\u001b[0m:\n", + "\u001b[32m\"Use of unsafe operator 'Lambda' from module 'Keras'\"\u001b[0m, \u001b[32m\"operator\"\u001b[0m: \u001b[32m\"Lambda\"\u001b[0m, \n", + "\u001b[32m\"module\"\u001b[0m: \u001b[32m\"Keras\"\u001b[0m, \u001b[32m\"source\"\u001b[0m: \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/KerasModels/unsafe_model.h5\"\u001b[0m, \n", + "\u001b[32m\"scanner\"\u001b[0m: \u001b[32m\"modelscan.scanners.H5LambdaDetectScan\"\u001b[0m\u001b[1m}\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"errors\"\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m]\u001b[0m, \u001b[32m\"scanned\"\u001b[0m: \n", + "\u001b[1m{\u001b[0m\u001b[32m\"total_scanned\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"scanned_files\"\u001b[0m: \n", + "\u001b[1m[\u001b[0m\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/KerasModels/unsafe_model.h5\"\u001b[0m\u001b[1m]\u001b[0m\n", + "\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m\n" ] } ], "source": [ "# This will save the scan results in file: keras-model-scan-results.json\n", - "!modelscan --path ./PyTorchModels/unsafe_model.pt -r json -o keras-model-scan-results.json" + "!modelscan --path KerasModels/unsafe_model.h5 -r json -o keras-model-scan-results.json" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/notebooks/tensorflow_fashion_mnist.ipynb b/notebooks/tensorflow_fashion_mnist.ipynb index 12203df..bdd48e6 100644 --- a/notebooks/tensorflow_fashion_mnist.ipynb +++ b/notebooks/tensorflow_fashion_mnist.ipynb @@ -68,28 +68,28 @@ "output_type": "stream", "text": [ "Epoch 1/10\n", - "1875/1875 [==============================] - 2s 741us/step - loss: 0.4967 - accuracy: 0.8252\n", + "1875/1875 [==============================] - 2s 1ms/step - loss: 0.4993 - accuracy: 0.8256\n", "Epoch 2/10\n", - "1875/1875 [==============================] - 1s 699us/step - loss: 0.3739 - accuracy: 0.8662\n", + "1875/1875 [==============================] - 2s 915us/step - loss: 0.3759 - accuracy: 0.8643\n", "Epoch 3/10\n", - "1875/1875 [==============================] - 1s 690us/step - loss: 0.3390 - accuracy: 0.8767\n", + "1875/1875 [==============================] - 2s 925us/step - loss: 0.3380 - accuracy: 0.8761\n", "Epoch 4/10\n", - "1875/1875 [==============================] - 1s 719us/step - loss: 0.3143 - accuracy: 0.8855\n", + "1875/1875 [==============================] - 2s 919us/step - loss: 0.3125 - accuracy: 0.8852\n", "Epoch 5/10\n", - "1875/1875 [==============================] - 1s 703us/step - loss: 0.2945 - accuracy: 0.8920\n", + "1875/1875 [==============================] - 2s 947us/step - loss: 0.2955 - accuracy: 0.8910\n", "Epoch 6/10\n", - "1875/1875 [==============================] - 1s 745us/step - loss: 0.2810 - accuracy: 0.8951\n", + "1875/1875 [==============================] - 2s 839us/step - loss: 0.2819 - accuracy: 0.8951\n", "Epoch 7/10\n", - "1875/1875 [==============================] - 1s 789us/step - loss: 0.2689 - accuracy: 0.8995\n", + "1875/1875 [==============================] - 2s 1ms/step - loss: 0.2708 - accuracy: 0.9000\n", "Epoch 8/10\n", - "1875/1875 [==============================] - 1s 732us/step - loss: 0.2602 - accuracy: 0.9026\n", + "1875/1875 [==============================] - 2s 983us/step - loss: 0.2577 - accuracy: 0.9047\n", "Epoch 9/10\n", - "1875/1875 [==============================] - 1s 724us/step - loss: 0.2493 - accuracy: 0.9062\n", + "1875/1875 [==============================] - 2s 983us/step - loss: 0.2496 - accuracy: 0.9065\n", "Epoch 10/10\n", - "1875/1875 [==============================] - 1s 736us/step - loss: 0.2411 - accuracy: 0.9090\n", - "313/313 [==============================] - 0s 487us/step - loss: 0.3440 - accuracy: 0.8816\n", + "1875/1875 [==============================] - 2s 818us/step - loss: 0.2387 - accuracy: 0.9109\n", + "313/313 [==============================] - 0s 564us/step - loss: 0.4170 - accuracy: 0.8603\n", "\n", - "Model trained with test accuracy: 0.881600022315979\n" + "Model trained with test accuracy: 0.8603000044822693\n" ] } ], @@ -120,9 +120,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "1/1 [==============================] - 0s 35ms/step\n", + "1/1 [==============================] - 0s 36ms/step\n", "\n", - "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 91.275 99.15501 100. ]\n", + "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 94.768 65.806 100. ]\n", "\n", "The true labels are ['Ankle boot', 'Pullover', 'Trouser']\n" ] @@ -221,18 +221,28 @@ "metadata": {}, "outputs": [ { - "ename": "InvalidArgumentError", - "evalue": "Graph execution error:\n\nDetected at node 'list_files/assert_not_empty/Assert' defined at (most recent call last):\nNode: 'list_files/assert_not_empty/Assert'\nassertion failed: [No files matched pattern: /tmp/*.txt]\n\t [[{{node list_files/assert_not_empty/Assert}}]] [Op:__inference_predict_function_79667]", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mInvalidArgumentError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[8], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m unsafe_model_loaded \u001b[38;5;241m=\u001b[39m tf\u001b[38;5;241m.\u001b[39mkeras\u001b[38;5;241m.\u001b[39mmodels\u001b[38;5;241m.\u001b[39mload_model(unsafe_model_path)\n\u001b[1;32m 3\u001b[0m number_of_predictions \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m3\u001b[39m\n\u001b[0;32m----> 4\u001b[0m \u001b[43mget_predictions\u001b[49m\u001b[43m(\u001b[49m\u001b[43munsafe_model_loaded\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnumber_of_predictions\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Documents/modelscan/notebooks/utils/tensorflow_fashion_mnist_model.py:74\u001b[0m, in \u001b[0;36mget_predictions\u001b[0;34m(model, number_of_predictions)\u001b[0m\n\u001b[1;32m 71\u001b[0m get_test_data_only \u001b[39m=\u001b[39m \u001b[39mTrue\u001b[39;00m\n\u001b[1;32m 72\u001b[0m test_images, test_labels \u001b[39m=\u001b[39m get_data(get_test_data_only)\n\u001b[0;32m---> 74\u001b[0m model_output \u001b[39m=\u001b[39m model\u001b[39m.\u001b[39;49mpredict(test_images[\u001b[39m0\u001b[39;49m:number_of_predictions])\n\u001b[1;32m 75\u001b[0m prediction_probabilities \u001b[39m=\u001b[39m [np\u001b[39m.\u001b[39mmax(prob) \u001b[39mfor\u001b[39;00m prob \u001b[39min\u001b[39;00m model_output]\n\u001b[1;32m 76\u001b[0m prediction_labels \u001b[39m=\u001b[39m [class_names[np\u001b[39m.\u001b[39margmax(pred)] \u001b[39mfor\u001b[39;00m pred \u001b[39min\u001b[39;00m model_output]\n", - "File \u001b[0;32m~/mambaforge/envs/py310/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py:70\u001b[0m, in \u001b[0;36mfilter_traceback..error_handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 67\u001b[0m filtered_tb \u001b[39m=\u001b[39m _process_traceback_frames(e\u001b[39m.\u001b[39m__traceback__)\n\u001b[1;32m 68\u001b[0m \u001b[39m# To get the full stack trace, call:\u001b[39;00m\n\u001b[1;32m 69\u001b[0m \u001b[39m# `tf.debugging.disable_traceback_filtering()`\u001b[39;00m\n\u001b[0;32m---> 70\u001b[0m \u001b[39mraise\u001b[39;00m e\u001b[39m.\u001b[39mwith_traceback(filtered_tb) \u001b[39mfrom\u001b[39;00m \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 71\u001b[0m \u001b[39mfinally\u001b[39;00m:\n\u001b[1;32m 72\u001b[0m \u001b[39mdel\u001b[39;00m filtered_tb\n", - "File \u001b[0;32m~/mambaforge/envs/py310/lib/python3.10/site-packages/tensorflow/python/eager/execute.py:53\u001b[0m, in \u001b[0;36mquick_execute\u001b[0;34m(op_name, num_outputs, inputs, attrs, ctx, name)\u001b[0m\n\u001b[1;32m 51\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m 52\u001b[0m ctx\u001b[39m.\u001b[39mensure_initialized()\n\u001b[0;32m---> 53\u001b[0m tensors \u001b[39m=\u001b[39m pywrap_tfe\u001b[39m.\u001b[39mTFE_Py_Execute(ctx\u001b[39m.\u001b[39m_handle, device_name, op_name,\n\u001b[1;32m 54\u001b[0m inputs, attrs, num_outputs)\n\u001b[1;32m 55\u001b[0m \u001b[39mexcept\u001b[39;00m core\u001b[39m.\u001b[39m_NotOkStatusException \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 56\u001b[0m \u001b[39mif\u001b[39;00m name \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n", - "\u001b[0;31mInvalidArgumentError\u001b[0m: Graph execution error:\n\nDetected at node 'list_files/assert_not_empty/Assert' defined at (most recent call last):\nNode: 'list_files/assert_not_empty/Assert'\nassertion failed: [No files matched pattern: /tmp/*.txt]\n\t [[{{node list_files/assert_not_empty/Assert}}]] [Op:__inference_predict_function_79667]" + "name": "stdout", + "output_type": "stream", + "text": [ + "File found: /tmp/aws_secret.txt\n", + "aws_access_key_id=\n", + "aws_secret_access_key=\n", + "1/1 [==============================] - 0s 48ms/step\n", + "\n", + "The model predicts: ['Ankle boot', 'Pullover', 'Trouser'] with probabilities: [ 94.768 65.806 100. ]\n", + "\n", + "The true labels are ['Ankle boot', 'Pullover', 'Trouser']\n" ] + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgMAAAC5CAYAAAC1FTxtAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9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rzc42H7jJySJLl8a+fvKkueZ18cXmdc+e5jbK8gfC0qWmSKbsYVTJyea6LhJHs2Zmbl1wQcVK68zMitXap0+LrFnjv92ePc2cLF84tXSpmcPdu8diY8eaMwLvvmu+Vv4W3r59Td2MdiwkevU1ap/P52Bmpvl8Lj9vc3PtbV10kcgvfmEKYUePNnfkiDBnXeI2GXjvPZEDB0TuvFPkkksq/nfzzfqlgrNp1sxkko0bm9OxyiPrRcRcSnjlFXN24Msvzemr114T+d3vzrz9EyfM/q5da24RmzrVFK00bGjGnjhR5Fe/Evn3v80yEyaYyw533mnWv/dec0nhvvtMJe6cOWYbDzwQS0I6dxZZudLcRbB3b8WzH0gsQ4ea+TpvnpkPEyfalf9nMnasSX5vv90kEYsWmbk1bpxIu3YVl/v8c1Mge8st5sxbmcmTRZYtM/M4N1dk0yYzLysXYwE+fD4Hr7rKXG59+GFz+n/mzIpnq0pKzPz76COR/HyTWHz6qUl+RZizLnGbDMyYYa4Hlb8UUObmm81dA6tWVX27zZub00pRZP4CKp99lhk+3CQj779vTqN++9siTz5pbv06k2HDRLp1Exk0yFz3veGGitd+H3/c7Pu4cSZ73bxZZMECU+0tItKxo0kiPvnEXOu95x5zgJRPQh580DRguvhik0Fv3171nwHiwx13mF/kt90mcs015hbXIUP8109NNfNr/34zj2+5xczRZ56puFzXruaa7apVsbsIyvTqZW5n3bjR3KrVp49Jlun1geo62+dgq1Yi//iH+Sy89FJzFrj852ijRiL79pnj4qKLRH7wA/PHXdmdW8xZHY8wBgAgcHF7ZgAAANQOkgEAAAJHMgAAQOBIBgAACBzJAAAAgSMZAAAgcCQDAAAEjmQAAIDAkQwAABA4kgEAAAJHMgAAQOBIBgAACNz/A9cY/qpUgLgzAAAAAElFTkSuQmCC", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -255,9 +265,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", + "\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/fingerprint.pb using modelscan.scanners.SavedModelTensorflowOpScan model scan\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/keras_metadata.pb using modelscan.scanners.SavedModelLambdaDetectScan model scan\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/saved_model.pb using modelscan.scanners.SavedModelTensorflowOpScan model scan\n", + "\n", + "\u001b[34m--- Summary ---\u001b[0m\n", + "\n", + "Total Issues: \u001b[1;36m2\u001b[0m\n", + "\n", + "Total Issues By Severity:\n", + "\n", + " - LOW: \u001b[1;32m0\u001b[0m\n", + " - MEDIUM: \u001b[1;32m0\u001b[0m\n", + " - HIGH: \u001b[1;36m2\u001b[0m\n", + " - CRITICAL: \u001b[1;32m0\u001b[0m\n", + "\n", + "\u001b[34m--- Issues by Severity ---\u001b[0m\n", + "\n", + "\u001b[34m--- HIGH ---\u001b[0m\n", + "\n", + "Unsafe operator found:\n", + " - Severity: HIGH\n", + " - Description: Use of unsafe operator 'ReadFile' from module 'Tensorflow'\n", + " - Source: /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/saved_model.pb\n", + "\n", + "Unsafe operator found:\n", + " - Severity: HIGH\n", + " - Description: Use of unsafe operator 'WriteFile' from module 'Tensorflow'\n", + " - Source: /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/saved_model.pb\n", + "\n", + "\u001b[34m--- Skipped --- \u001b[0m\n", + "\n", + "Total skipped: \u001b[1;36m2\u001b[0m - run with --show-skipped to see the full list.\n" + ] + } + ], "source": [ "!modelscan -p TensorFlowModels/unsafe_model" ] @@ -281,13 +332,52 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", + "\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/fingerprint.pb using modelscan.scanners.SavedModelTensorflowOpScan model scan\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/keras_metadata.pb using modelscan.scanners.SavedModelLambdaDetectScan model scan\n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/saved_model.pb using modelscan.scanners.SavedModelTensorflowOpScan model scan\n", + "\u001b[1m{\u001b[0m\u001b[32m\"modelscan_version\"\u001b[0m: \u001b[32m\"0.5.0\"\u001b[0m, \u001b[32m\"timestamp\"\u001b[0m: \u001b[32m\"2024-01-25T17:56:46.559473\"\u001b[0m, \n", + "\u001b[32m\"input_path\"\u001b[0m: \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model\"\u001b[0m\n", + ", \u001b[32m\"total_issues\"\u001b[0m: \u001b[1;36m2\u001b[0m, \u001b[32m\"summary\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"LOW\"\u001b[0m: \u001b[1;36m0\u001b[0m, \n", + "\u001b[32m\"MEDIUM\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"HIGH\"\u001b[0m: \u001b[1;36m2\u001b[0m, \u001b[32m\"CRITICAL\"\u001b[0m: \u001b[1;36m0\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"HIGH\"\u001b[0m: \n", + "\u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m\"description\"\u001b[0m: \u001b[32m\"Use of unsafe operator 'ReadFile' from module 'Tensorflow'\"\u001b[0m, \n", + "\u001b[32m\"operator\"\u001b[0m: \u001b[32m\"ReadFile\"\u001b[0m, \u001b[32m\"module\"\u001b[0m: \u001b[32m\"Tensorflow\"\u001b[0m, \u001b[32m\"source\"\u001b[0m: \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/\u001b[0m\n", + "\u001b[32msaved_model.pb\"\u001b[0m, \u001b[32m\"scanner\"\u001b[0m: \u001b[32m\"modelscan.scanners.SavedModelTensorflowOpScan\"\u001b[0m\u001b[1m}\u001b[0m, \n", + "\u001b[1m{\u001b[0m\u001b[32m\"description\"\u001b[0m: \u001b[32m\"Use of unsafe operator 'WriteFile' from module 'Tensorflow'\"\u001b[0m, \n", + "\u001b[32m\"operator\"\u001b[0m: \u001b[32m\"WriteFile\"\u001b[0m, \u001b[32m\"module\"\u001b[0m: \u001b[32m\"Tensorflow\"\u001b[0m, \u001b[32m\"source\"\u001b[0m: \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/\u001b[0m\n", + "\u001b[32msaved_model.pb\"\u001b[0m, \u001b[32m\"scanner\"\u001b[0m: \u001b[32m\"modelscan.scanners.SavedModelTensorflowOpScan\"\u001b[0m\u001b[1m}\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m, \n", + "\u001b[32m\"errors\"\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m]\u001b[0m, \u001b[32m\"scanned\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_scanned\"\u001b[0m: \u001b[1;36m3\u001b[0m, \u001b[32m\"scanned_files\"\u001b[0m: \n", + "\u001b[1m[\u001b[0m\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model\u001b[0m\n", + "\u001b[32m/fingerprint.pb\"\u001b[0m, \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/\u001b[0m\n", + "\u001b[32mkeras_metadata.pb\"\u001b[0m, \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/TensorFlowModels/unsafe_model/\u001b[0m\n", + "\u001b[32msaved_model.pb\"\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m\n" + ] + } + ], "source": [ "# This will save the scan results in file: tensorflow-model-scan-results.json\n", - "!modelscan --path ./PyTorchModels/unsafe_model.pt -r json -o tensorflow-model-scan-results.json" + "!modelscan --path TensorFlowModels/unsafe_model -r json -o tensorflow-model-scan-results.json" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/notebooks/xgboost_diabetes_classification.ipynb b/notebooks/xgboost_diabetes_classification.ipynb index b036bab..4638d19 100644 --- a/notebooks/xgboost_diabetes_classification.ipynb +++ b/notebooks/xgboost_diabetes_classification.ipynb @@ -298,25 +298,25 @@ "text": [ "No settings file detected at /Users/mehrinkiani/Documents/modelscan/notebooks/modelscan-settings.toml. Using defaults. \n", "\n", - "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt:unsafe_model/data.pkl using modelscan.scanners.PickleUnsafeOpScan model scan\n", - "\u001b[1m{\u001b[0m\u001b[32m\"modelscan_version\"\u001b[0m: \u001b[32m\"0.5.0\"\u001b[0m, \u001b[32m\"timestamp\"\u001b[0m: \u001b[32m\"2024-01-25T17:03:14.320664\"\u001b[0m, \n", + "Scanning /Users/mehrinkiani/Documents/modelscan/notebooks/XGBoostModels/unsafe_model.pkl using modelscan.scanners.PickleUnsafeOpScan model scan\n", + "\u001b[1m{\u001b[0m\u001b[32m\"modelscan_version\"\u001b[0m: \u001b[32m\"0.5.0\"\u001b[0m, \u001b[32m\"timestamp\"\u001b[0m: \u001b[32m\"2024-01-25T17:56:00.855056\"\u001b[0m, \n", "\u001b[32m\"input_path\"\u001b[0m: \n", - "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt\"\u001b[0m\n", - ", \u001b[32m\"total_issues\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"summary\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"LOW\"\u001b[0m: \u001b[1;36m0\u001b[0m, \n", + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/XGBoostModels/unsafe_model.pkl\u001b[0m\n", + "\u001b[32m\"\u001b[0m, \u001b[32m\"total_issues\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"summary\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"LOW\"\u001b[0m: \u001b[1;36m0\u001b[0m, \n", "\u001b[32m\"MEDIUM\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"HIGH\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"CRITICAL\"\u001b[0m: \u001b[1;36m1\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"CRITICAL\"\u001b[0m: \n", "\u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m\"description\"\u001b[0m: \u001b[32m\"Use of unsafe operator 'system' from module 'posix'\"\u001b[0m, \n", "\u001b[32m\"operator\"\u001b[0m: \u001b[32m\"system\"\u001b[0m, \u001b[32m\"module\"\u001b[0m: \u001b[32m\"posix\"\u001b[0m, \u001b[32m\"source\"\u001b[0m: \n", - "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt:\u001b[0m\n", - "\u001b[32munsafe_model/data.pkl\"\u001b[0m, \u001b[32m\"scanner\"\u001b[0m: \u001b[32m\"modelscan.scanners.PickleUnsafeOpScan\"\u001b[0m\u001b[1m}\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m, \n", - "\u001b[32m\"errors\"\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m]\u001b[0m, \u001b[32m\"scanned\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_scanned\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"scanned_files\"\u001b[0m: \n", - "\u001b[1m[\u001b[0m\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/PyTorchModels/unsafe_model.pt\u001b[0m\n", - "\u001b[32m:unsafe_model/data.pkl\"\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m\n" + "\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/XGBoostModels/unsafe_model.pkl\u001b[0m\n", + "\u001b[32m\"\u001b[0m, \u001b[32m\"scanner\"\u001b[0m: \u001b[32m\"modelscan.scanners.PickleUnsafeOpScan\"\u001b[0m\u001b[1m}\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"errors\"\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m]\u001b[0m, \n", + "\u001b[32m\"scanned\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_scanned\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"scanned_files\"\u001b[0m: \n", + "\u001b[1m[\u001b[0m\u001b[32m\"/Users/mehrinkiani/Documents/modelscan/notebooks/XGBoostModels/unsafe_model.pk\u001b[0m\n", + "\u001b[32ml\"\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m\n" ] } ], "source": [ "# This will save the scan results in file: xgboost-model-scan-results.json\n", - "!modelscan --path ./PyTorchModels/unsafe_model.pt -r json -o xgboost-model-scan-results.json" + "!modelscan --path XGBoostModels/unsafe_model.pkl -r json -o xgboost-model-scan-results.json" ] } ], From 4c6425d3fedf21b3ded3fcc2b55751ad97c4781d Mon Sep 17 00:00:00 2001 From: Mehrin Kiani Date: Fri, 26 Jan 2024 14:14:47 -0500 Subject: [PATCH 3/5] update readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 824955b..53844e7 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,10 @@ ModelScan supports the following arguments via the CLI: | ```modelscan -p /path/to/model_file``` | -p or --path | Scan a locally stored model | | ```modelscan -p /path/to/model_file --settings-file ./modelscan-settings.toml``` | --settings-file | Scan a locally stored model using custom configurations | | ```modelscan create-settings-file``` | -l or --location | Create a configurable settings file | +| ```modelscan -r``` | -r or --reporting-format | Format of the output. Options are console, json, or custom (to be defined in settings-file). Default is console. | +| ```modelscan -r reporting-format -o file-name.format``` | -o or --output-file | Optional file name for output report | +| ```modelscan -l``` | -l, --log | level of log messages to display (default:INFO). Other options are CRITICAL, ERROR, WARNING, and DEBUG | +| ```modelscan --show-skipped``` | --show-skipped | Print a list of files that were skipped during the scan | Remember models are just like any other form of digital media, you should scan content from any untrusted source before use. From 901ee77e1b9c8add8490d4ec428ccd6991042a35 Mon Sep 17 00:00:00 2001 From: Mehrin Kiani Date: Fri, 26 Jan 2024 14:18:21 -0500 Subject: [PATCH 4/5] Fixed typos --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 53844e7..c961507 100644 --- a/README.md +++ b/README.md @@ -116,9 +116,9 @@ ModelScan supports the following arguments via the CLI: | ```modelscan -p /path/to/model_file``` | -p or --path | Scan a locally stored model | | ```modelscan -p /path/to/model_file --settings-file ./modelscan-settings.toml``` | --settings-file | Scan a locally stored model using custom configurations | | ```modelscan create-settings-file``` | -l or --location | Create a configurable settings file | -| ```modelscan -r``` | -r or --reporting-format | Format of the output. Options are console, json, or custom (to be defined in settings-file). Default is console. | -| ```modelscan -r reporting-format -o file-name.format``` | -o or --output-file | Optional file name for output report | -| ```modelscan -l``` | -l, --log | level of log messages to display (default:INFO). Other options are CRITICAL, ERROR, WARNING, and DEBUG | +| ```modelscan -r``` | -r or --reporting-format | Format of the output. Options are console, json, or custom (to be defined in settings-file). Default is console | +| ```modelscan -r reporting-format -o file-name``` | -o or --output-file | Optional file name for output report | +| ```modelscan -l``` | -l, --log | Level of log messages to display (default:INFO). Other options are CRITICAL, ERROR, WARNING, and DEBUG | | ```modelscan --show-skipped``` | --show-skipped | Print a list of files that were skipped during the scan | From 16f5e625a05b5e17d9dc7587fd3b7c6d4a34ba31 Mon Sep 17 00:00:00 2001 From: Mehrin Kiani Date: Fri, 26 Jan 2024 14:42:33 -0500 Subject: [PATCH 5/5] update readme --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index c961507..57c856c 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,6 @@ ModelScan supports the following arguments via the CLI: | ```modelscan create-settings-file``` | -l or --location | Create a configurable settings file | | ```modelscan -r``` | -r or --reporting-format | Format of the output. Options are console, json, or custom (to be defined in settings-file). Default is console | | ```modelscan -r reporting-format -o file-name``` | -o or --output-file | Optional file name for output report | -| ```modelscan -l``` | -l, --log | Level of log messages to display (default:INFO). Other options are CRITICAL, ERROR, WARNING, and DEBUG | | ```modelscan --show-skipped``` | --show-skipped | Print a list of files that were skipped during the scan |