You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/03/22 22:24:45 UTC

[GitHub] marcoabreu commented on a change in pull request #10054: [MXNET-53]Image classifier for scala-infer package

marcoabreu commented on a change in pull request #10054: [MXNET-53]Image classifier for scala-infer package
URL: https://github.com/apache/incubator-mxnet/pull/10054#discussion_r176589527
 
 

 ##########
 File path: scala-package/infer/src/test/scala/ml/dmlc/mxnet/infer/ImageClassifierSuite.scala
 ##########
 @@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ml.dmlc.mxnet.infer
+
+import ml.dmlc.mxnet._
+import ml.dmlc.mxnet.{DataDesc, Shape}
+
+import org.mockito.Matchers._
+import org.mockito.Mockito
+import org.scalatest.{BeforeAndAfterAll}
+
+// scalastyle:off
+import java.awt.image.BufferedImage
+// scalastyle:on
+
+/**
+  * Unit tests for ImageClassifier
+  */
+class ImageClassifierSuite extends ClassifierSuite with BeforeAndAfterAll {
+
+  class MyImageClassifier(modelPathPrefix: String,
+                           inputDescriptors: IndexedSeq[DataDesc])
+    extends ImageClassifier(modelPathPrefix, inputDescriptors) {
+
+    override def getPredictor(): MyClassyPredictor = {
+      Mockito.mock(classOf[MyClassyPredictor])
+    }
+
+    override def getClassifier(modelPathPrefix: String, inputDescriptors:
+    IndexedSeq[DataDesc]): Classifier = {
+      Mockito.mock(classOf[Classifier])
+    }
+
+    def getSynset(): IndexedSeq[String] = synset
+  }
+
+  test("ImageClassifierSuite-testRescaleImage") {
+    val image1 = new BufferedImage(100, 200, BufferedImage.TYPE_BYTE_GRAY)
+    val image2 = ImageClassifier.reshapeImage(image1, 1000, 2000)
+
+    assert(image2.getWidth === 1000)
+    assert(image2.getHeight === 2000)
+  }
+
+  test("ImageClassifierSuite-testConvertBufferedImageToNDArray") {
+    val dType = DType.Float32
+    val inputDescriptor = IndexedSeq[DataDesc](new DataDesc(modelPath, Shape(1, 3, 2, 2),
+      dType, "NCHW"))
+
+    val image1 = new BufferedImage(100, 200, BufferedImage.TYPE_BYTE_GRAY)
+    val image2 = ImageClassifier.reshapeImage(image1, 2, 2)
+
+    val result = ImageClassifier.bufferedImageToPixels(image2, Shape(1, 3, 2, 2))
+
+    assert(result.shape == inputDescriptor(0).shape)
 
 Review comment:
   Could you verify the content? (See above)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services