-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init * add distripredict * javardd * java spark context * test * fix * remove tes * remove * add type check * meet comments * fix import * fix * fix style * combine testcase * fix style * replaceable variable
- Loading branch information
0 parents
commit e0e11aa
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
scala/orca/src/main/scala/com/intel/analytics/bigdl/orca/python/PythonOrca.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2018 Analytics Zoo Authors. | ||
* | ||
* Licensed 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 com.intel.analytics.zoo.orca.python | ||
|
||
import com.intel.analytics.zoo.pipeline.inference.InferenceModel | ||
import org.apache.spark.api.java.{JavaRDD, JavaSparkContext} | ||
import java.util.{List => JList} | ||
|
||
import com.intel.analytics.bigdl.tensor.TensorNumericMath.TensorNumeric | ||
import com.intel.analytics.zoo.common.PythonZoo | ||
|
||
import scala.reflect.ClassTag | ||
|
||
object PythonOrca { | ||
|
||
def ofFloat(): PythonOrca[Float] = new PythonOrca[Float]() | ||
|
||
def ofDouble(): PythonOrca[Double] = new PythonOrca[Double]() | ||
} | ||
|
||
class PythonOrca[T: ClassTag](implicit ev: TensorNumeric[T]) extends PythonZoo[T] { | ||
def inferenceModelDistriPredict(model: InferenceModel, sc: JavaSparkContext, | ||
inputs: JavaRDD[JList[com.intel.analytics.bigdl.python.api | ||
.JTensor]], | ||
inputIsTable: Boolean): JavaRDD[JList[Object]] = { | ||
val broadcastModel = sc.broadcast(model) | ||
inputs.rdd.mapPartitions(partition => { | ||
val localModel = broadcastModel.value | ||
partition.map(inputs => { | ||
val inputActivity = jTensorsToActivity(inputs, inputIsTable) | ||
val outputActivity = localModel.doPredict(inputActivity) | ||
activityToList(outputActivity) | ||
}) | ||
}) | ||
} | ||
} |