From c1cf09c8f38adcc12d31fdc18070ee07564be860 Mon Sep 17 00:00:00 2001 From: Song Jiaming Date: Mon, 15 Jun 2020 16:25:34 +0800 Subject: [PATCH] Infernce Model string support of TFNet (#2452) Noted InferenceModel predict batchSize is removed --- .../bigdl/dllib/inference/InferenceModel.scala | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/spark/dl/src/main/scala/com/intel/analytics/bigdl/dllib/inference/InferenceModel.scala b/spark/dl/src/main/scala/com/intel/analytics/bigdl/dllib/inference/InferenceModel.scala index d29dc7515e1..b3b4eb273c6 100644 --- a/spark/dl/src/main/scala/com/intel/analytics/bigdl/dllib/inference/InferenceModel.scala +++ b/spark/dl/src/main/scala/com/intel/analytics/bigdl/dllib/inference/InferenceModel.scala @@ -24,9 +24,11 @@ import java.util.{List => JList} import com.intel.analytics.bigdl.nn.abstractnn.Activity import com.intel.analytics.bigdl.tensor.Tensor +import com.intel.analytics.bigdl.tensor.TensorNumericMath.TensorNumeric import com.sun.xml.internal.bind.v2.TODO import scala.collection.JavaConverters._ +import scala.reflect.ClassTag class InferenceModel(private var autoScalingEnabled: Boolean = true, private var concurrentNum: Int = 20, @@ -37,7 +39,6 @@ class InferenceModel(private var autoScalingEnabled: Boolean = true, require(concurrentNum > 0, "concurrentNum should > 0") - private var batchCnt: Int = 0 @transient var inferenceSummary: InferenceSummary = null /** * default constructor, will create a InferenceModel with auto-scaling enabled. @@ -743,17 +744,17 @@ class InferenceModel(private var autoScalingEnabled: Boolean = true, val model: AbstractModel = retrieveModel() try { val begin = System.nanoTime() - val batchSize = if (inputActivity.isTensor) { - inputActivity.toTensor[Float].size(1) - } else { - val sampleKey = inputActivity.toTable.keySet.head - inputActivity.toTable(sampleKey).asInstanceOf[Tensor[Float]].size(1) - } +// val batchSize = if (inputActivity.isTensor) { +// inputActivity.toTensor[T].size(1) +// } else { +// val sampleKey = inputActivity.toTable.keySet.head +// inputActivity.toTable(sampleKey).asInstanceOf[Tensor[T]].size(1) +// } val result = model.predict(inputActivity) val end = System.nanoTime() val latency = end - begin - val name = s"model predict for batch ${batchSize}" + val name = s"model predict for batch" InferenceSupportive.logger.info(s"$name time elapsed [${latency/1e9} s, ${latency/1e6} ms].") result