diff --git a/deep-learning/src/main/python/synapse/ml/cntk/ImageFeaturizer.py b/deep-learning/src/main/python/synapse/ml/onnx/ImageFeaturizer.py similarity index 92% rename from deep-learning/src/main/python/synapse/ml/cntk/ImageFeaturizer.py rename to deep-learning/src/main/python/synapse/ml/onnx/ImageFeaturizer.py index 4107259ae8..e30abb52e1 100644 --- a/deep-learning/src/main/python/synapse/ml/cntk/ImageFeaturizer.py +++ b/deep-learning/src/main/python/synapse/ml/onnx/ImageFeaturizer.py @@ -6,7 +6,7 @@ if sys.version >= "3": basestring = str -from synapse.ml.cntk._ImageFeaturizer import _ImageFeaturizer +from synapse.ml.onnx._ImageFeaturizer import _ImageFeaturizer from pyspark.ml.common import inherit_doc diff --git a/deep-learning/src/main/scala/com/microsoft/azure/synapse/ml/cntk/ImageFeaturizer.txt b/deep-learning/src/main/scala/com/microsoft/azure/synapse/ml/cntk/ImageFeaturizer.txt deleted file mode 100644 index 864e9166c5..0000000000 --- a/deep-learning/src/main/scala/com/microsoft/azure/synapse/ml/cntk/ImageFeaturizer.txt +++ /dev/null @@ -1,18 +0,0 @@ -The ``ImageFeaturizer`` relies on a ``CNTKModel`` to do the -featurization of the image(s). One can set this model using the -modelLocation parameter. To map the nodes of the ``CNTKModel`` onto the -standard "layers" structure of a feed forward neural net, one needs to -supply a list of node names that range from the output node, back -towards the input node of the CNTK Function. This list does not need to -be exhaustive, and is provided to you if you use a model downloaded -from ``ModelDownloader``. One can find this layer list in the schema -of the downloaded model. - -The ``ImageFeaturizer`` takes an input column of images (the type -returned by the ``ImageReader``), automatically resizes them to fit the -``CNTKModel``'s inputs, and feeds them through a pre-trained CNTK model. -One can truncate the model using the ``cutOutputLayers`` parameter that -determines how many layers to truncate from the output of the network. -For example, layer=0 means that no layers are removed, layer=2 means -that the ``ImageFeaturizer`` returns the activations of the layer that -is two layers from the output layer, and so on. diff --git a/deep-learning/src/main/scala/com/microsoft/azure/synapse/ml/cntk/ImageFeaturizer.scala b/deep-learning/src/main/scala/com/microsoft/azure/synapse/ml/onnx/ImageFeaturizer.scala similarity index 98% rename from deep-learning/src/main/scala/com/microsoft/azure/synapse/ml/cntk/ImageFeaturizer.scala rename to deep-learning/src/main/scala/com/microsoft/azure/synapse/ml/onnx/ImageFeaturizer.scala index c34c755ea5..6fe2ead35c 100644 --- a/deep-learning/src/main/scala/com/microsoft/azure/synapse/ml/cntk/ImageFeaturizer.scala +++ b/deep-learning/src/main/scala/com/microsoft/azure/synapse/ml/onnx/ImageFeaturizer.scala @@ -1,14 +1,13 @@ // Copyright (C) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in project root for information. -package com.microsoft.azure.synapse.ml.cntk +package com.microsoft.azure.synapse.ml.onnx import com.microsoft.azure.synapse.ml.codegen.Wrappable import com.microsoft.azure.synapse.ml.core.contracts.{HasInputCol, HasOutputCol} import com.microsoft.azure.synapse.ml.core.schema.DatasetExtensions import com.microsoft.azure.synapse.ml.core.schema.DatasetExtensions.findUnusedColumnName import com.microsoft.azure.synapse.ml.logging.BasicLogging -import com.microsoft.azure.synapse.ml.onnx.{ONNXHub, ONNXModel, ONNXModelInfo} import com.microsoft.azure.synapse.ml.opencv.ImageTransformer import com.microsoft.azure.synapse.ml.param.TransformerParam import org.apache.spark.ml.linalg.DenseVector diff --git a/deep-learning/src/main/scala/com/microsoft/azure/synapse/ml/onnx/ImageFeaturizer.txt b/deep-learning/src/main/scala/com/microsoft/azure/synapse/ml/onnx/ImageFeaturizer.txt new file mode 100644 index 0000000000..c7bf325366 --- /dev/null +++ b/deep-learning/src/main/scala/com/microsoft/azure/synapse/ml/onnx/ImageFeaturizer.txt @@ -0,0 +1,16 @@ +The ``ImageFeaturizer`` relies on a ``ONNXModel`` to do the +featurization of the image(s). One can set this model directly using the +onnxModel parameter, or use setModel to set a known model name that will +be pulled from the ONNXHub. See docs for other options to set the underlying +model. + +The ``ImageFeaturizer`` takes an input column of images (the type +returned by the ``ImageReader``), automatically resizes them to fit the +``ONNXModel``'s inputs using an ``ImageTransformer``, and feeds them through +a pre-trained ONNX model. Some of the ``ImageTransformer`` parameters are +exposed on the featurizer so you can customize them. + +You may specify intermediate model nodes by either using the ``headless`` +parameter to automatically choose the full model output (headless = false), +or the intermediate feature nodes as indicated by the OnnxHub manifest for that +model (headless = true). diff --git a/deep-learning/src/test/scala/com/microsoft/azure/synapse/ml/explainers/ImageExplainersSuite.scala b/deep-learning/src/test/scala/com/microsoft/azure/synapse/ml/explainers/ImageExplainersSuite.scala index f004e03b51..bbda757076 100644 --- a/deep-learning/src/test/scala/com/microsoft/azure/synapse/ml/explainers/ImageExplainersSuite.scala +++ b/deep-learning/src/test/scala/com/microsoft/azure/synapse/ml/explainers/ImageExplainersSuite.scala @@ -3,10 +3,9 @@ package com.microsoft.azure.synapse.ml.explainers -import com.microsoft.azure.synapse.ml.cntk.{ImageFeaturizer, TrainedONNXModelUtils} import com.microsoft.azure.synapse.ml.core.test.base.TestBase import com.microsoft.azure.synapse.ml.io.IOImplicits._ -import com.microsoft.azure.synapse.ml.onnx.ONNXModel +import com.microsoft.azure.synapse.ml.onnx.{ImageFeaturizer, ONNXModel, TrainedONNXModelUtils} import com.microsoft.azure.synapse.ml.opencv.ImageTransformer import org.apache.commons.io.FileUtils import org.apache.spark.ml.{Pipeline, PipelineModel} diff --git a/deep-learning/src/test/scala/com/microsoft/azure/synapse/ml/cntk/ImageFeaturizerSuite.scala b/deep-learning/src/test/scala/com/microsoft/azure/synapse/ml/onnx/ImageFeaturizerSuite.scala similarity index 99% rename from deep-learning/src/test/scala/com/microsoft/azure/synapse/ml/cntk/ImageFeaturizerSuite.scala rename to deep-learning/src/test/scala/com/microsoft/azure/synapse/ml/onnx/ImageFeaturizerSuite.scala index 7248a0d763..a653a7fd20 100644 --- a/deep-learning/src/test/scala/com/microsoft/azure/synapse/ml/cntk/ImageFeaturizerSuite.scala +++ b/deep-learning/src/test/scala/com/microsoft/azure/synapse/ml/onnx/ImageFeaturizerSuite.scala @@ -1,7 +1,7 @@ // Copyright (C) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in project root for information. -package com.microsoft.azure.synapse.ml.cntk +package com.microsoft.azure.synapse.ml.onnx import breeze.linalg.argtopk import com.microsoft.azure.synapse.ml.Secrets diff --git a/notebooks/features/other/DeepLearning - Flower Image Classification.ipynb b/notebooks/features/other/DeepLearning - Flower Image Classification.ipynb index d0fdbf7ee2..6c3e28985b 100644 --- a/notebooks/features/other/DeepLearning - Flower Image Classification.ipynb +++ b/notebooks/features/other/DeepLearning - Flower Image Classification.ipynb @@ -15,7 +15,6 @@ "source": [ "from pyspark.ml import Transformer, Estimator, Pipeline\n", "from pyspark.ml.classification import LogisticRegression\n", - "from synapse.ml.downloader import ModelDownloader\n", "import sys, time\n", "from pyspark.sql import SparkSession\n", "\n", @@ -28,24 +27,6 @@ " from notebookutils.visualization import display" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "mml-deploy": "local" - }, - "outputs": [], - "source": [ - "if running_on_synapse():\n", - " modelDir = \"abfss://synapse@mmlsparkeuap.dfs.core.windows.net/models/\"\n", - "elif running_on_databricks():\n", - " modelDir = \"dbfs:/models/\"\n", - "else:\n", - " modelDir = \"/tmp/models/\"\n", - "\n", - "model = ModelDownloader(spark, modelDir).downloadByName(\"ResNet50\")" - ] - }, { "cell_type": "code", "execution_count": null, @@ -80,7 +61,7 @@ "source": [ "from synapse.ml.opencv import ImageTransformer\n", "from synapse.ml.image import UnrollImage\n", - "from synapse.ml.cntk import ImageFeaturizer\n", + "from synapse.ml.onnx import ImageFeaturizer\n", "from synapse.ml.stages import *\n", "\n", "# Make some featurizers\n", diff --git a/notebooks/features/responsible_ai/Interpretability - Snow Leopard Detection.ipynb b/notebooks/features/responsible_ai/Interpretability - Snow Leopard Detection.ipynb index 9771c4b36f..95721aae21 100644 --- a/notebooks/features/responsible_ai/Interpretability - Snow Leopard Detection.ipynb +++ b/notebooks/features/responsible_ai/Interpretability - Snow Leopard Detection.ipynb @@ -223,7 +223,7 @@ "from pyspark.ml.feature import StringIndexer\n", "from pyspark.ml.classification import LogisticRegression\n", "from pyspark.sql.functions import udf\n", - "from synapse.ml.cntk import ImageFeaturizer\n", + "from synapse.ml.onnx import ImageFeaturizer\n", "from synapse.ml.stages import UDFTransformer\n", "from pyspark.sql.types import *\n", "\n",