Skip to content

Commit

Permalink
feat: Add the descriptionExcludes parameter to AnalyzeImage (#1590)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhamilton723 authored Aug 2, 2022
1 parent b9ac22a commit 51beaa0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,7 @@ class AnalyzeImage(override val uid: String)

val details = new ServiceParam[Seq[String]](
this, "details", "what visual feature types to return",
{
case Left(seq) => seq.forall(Set("Celebrities", "Landmarks"))
case _ => true
},
{ _ => true},
isURLParam = true,
toValueString = { seq => seq.mkString(",") }
)
Expand All @@ -501,6 +498,21 @@ class AnalyzeImage(override val uid: String)

def setDetailsCol(v: String): this.type = setVectorParam(details, v)

val descriptionExclude = new ServiceParam[Seq[String]](
this, "descriptionExclude", "Whether to exclude certain parts of the model in the description",
{ _ => true},
isURLParam = true,
toValueString = { seq => seq.mkString(",") }
)

def getDescriptionExclude: Seq[String] = getScalarParam(descriptionExclude)

def getDescriptionExcludeCol: String = getVectorParam(descriptionExclude)

def setDescriptionExclude(v: Seq[String]): this.type = setScalarParam(descriptionExclude, v)

def setDescriptionExcludeCol(v: String): this.type = setVectorParam(descriptionExclude, v)

val language = new ServiceParam[String](
this, "language", "the language of the response (en if none given)", isURLParam = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,22 @@ class AnalyzeImageSuite extends TransformerFuzzing[AnalyzeImage] with CognitiveK
.setSubscriptionKey(cognitiveKey)
.setLocation("eastus")
.setOutputCol("features")

lazy val ai: AnalyzeImage = baseAI
.setImageUrlCol("url")
.setLanguageCol("language")
.setVisualFeatures(
Seq("Categories", "Tags", "Description", "Faces", "ImageType", "Color", "Adult", "Objects", "Brands"))
Seq("Categories", "Tags", "Description", "Faces", "ImageType", "Color", "Adult", "Objects", "Brands")
)
.setDetails(Seq("Celebrities", "Landmarks"))

def ai: AnalyzeImage = baseAI
.setImageUrlCol("url")

lazy val bytesDF: DataFrame = BingImageSearch
.downloadFromUrls("url", "imageBytes", 4, 10000)
.transform(df)
.drop("url")

lazy val bytesAI: AnalyzeImage = baseAI
def bytesAI: AnalyzeImage = baseAI
.setImageBytesCol("imageBytes")
.setLanguageCol("language")
.setVisualFeatures(
Seq("Categories", "Tags", "Description", "Faces", "ImageType", "Color", "Adult", "Objects", "Brands")
)
.setDetails(Seq("Celebrities", "Landmarks"))

test("full parametrization") {
val row = (Seq("Categories"), "en", Seq("Celebrities"),
Expand Down Expand Up @@ -258,6 +254,7 @@ class ReadImageSuite extends TransformerFuzzing[ReadImage]
def prep(df: DataFrame) = {
df.select("url", "ocr.analyzeResult.readResults")
}

super.assertDFEq(prep(df1), prep(df2))(eq)
}

Expand Down

0 comments on commit 51beaa0

Please sign in to comment.