andrewfayres commented on a change in pull request #12848: Fix Batch input
issue with Scala Benchmark
URL: https://github.com/apache/incubator-mxnet/pull/12848#discussion_r226131087
##########
File path:
scala-package/infer/src/main/scala/org/apache/mxnet/infer/ImageClassifier.scala
##########
@@ -97,14 +97,12 @@ class ImageClassifier(modelPathPrefix: String,
def classifyImageBatch(inputBatch: Traversable[BufferedImage], topK:
Option[Int] = None):
IndexedSeq[IndexedSeq[(String, Float)]] = {
- val imageBatch = ListBuffer[NDArray]()
- for (image <- inputBatch) {
- val scaledImage = ImageClassifier.reshapeImage(image, width, height)
- val pixelsNDArray = ImageClassifier.bufferedImageToPixels(scaledImage,
inputShape)
- imageBatch += pixelsNDArray
- }
+ val inputBatchSeq = inputBatch.toIndexedSeq
+ val imageBatch = inputBatchSeq.indices.par.map(idx => {
+ val scaledImage = ImageClassifier.reshapeImage(inputBatchSeq(idx),
width, height)
+ ImageClassifier.bufferedImageToPixels(scaledImage, inputShape.drop(1))
Review comment:
Same comment as above. Save inputShape.drop(1) to a meaningful name. It
makes it more clear why we're dropping it. Given that this is being done in a
loop it's in theory more important because we're remaking the Shape each time
(sure is almost certainly being optimized away by the compiler).
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services