Skip to content

Commit

Permalink
chore: Move new ImageFeaturizer to onnx namespace (#1711)
Browse files Browse the repository at this point in the history
  • Loading branch information
svotaw authored Nov 15, 2022
1 parent 0ff6802 commit e38e3ad
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e38e3ad

Please sign in to comment.