Skip to content

Commit

Permalink
Add Estimator Python API and Inception Example (intel-analytics#1597)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyita authored and qiuxin2012 committed Sep 10, 2019
1 parent 8d9c3d1 commit 29ac631
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.feature.image

import com.intel.analytics.bigdl.transform.vision.image.opencv.OpenCVMat
import com.intel.analytics.bigdl.transform.vision.image.{FeatureTransformer, ImageFeature}
import org.opencv.core.Core

/**
* Flip the image horizontally and vertically
*/
class Mirror() extends FeatureTransformer {
override def transformMat(feature: ImageFeature): Unit = {
Mirror.transform(feature.opencvMat(), feature.opencvMat())
}
}

object Mirror {
def apply(): Mirror = new Mirror()

def transform(input: OpenCVMat, output: OpenCVMat): OpenCVMat = {
Core.flip(input, output, -1)
output
}
}

/**
* Flip the image horizontally and vertically
*/
class ImageMirror() extends ImageProcessing {
private val internalCrop = new Mirror

override def apply(prev: Iterator[ImageFeature]): Iterator[ImageFeature] = {
internalCrop.apply(prev)
}
}

object ImageMirror {
def apply(): ImageMirror = new ImageMirror()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
package com.intel.analytics.zoo.feature.python

import com.intel.analytics.bigdl.DataSet
import com.intel.analytics.bigdl.dataset.Transformer
import com.intel.analytics.bigdl.dataset.{Transformer, Sample => JSample}
import com.intel.analytics.bigdl.python.api.Sample
import com.intel.analytics.bigdl.tensor.TensorNumericMath.TensorNumeric
import com.intel.analytics.bigdl.transform.vision.image._
import com.intel.analytics.zoo.common.PythonZoo
Expand Down Expand Up @@ -48,6 +49,11 @@ class PythonFeatureSet[T: ClassTag](implicit ev: TensorNumeric[T]) extends Pytho
FeatureSet.rdd(data, MemoryType.fromString(memoryType))
}

def createSampleFeatureSetFromRDD(data: JavaRDD[Sample], memoryType: String)
: FeatureSet[JSample[T]] = {
FeatureSet.rdd(toJSample(data), MemoryType.fromString(memoryType))
}

def transformFeatureSet(featureSet: FeatureSet[Any],
transformer: Transformer[Any, Any]): FeatureSet[Any] = {
featureSet -> transformer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ class PythonImageFeature[T: ClassTag](implicit ev: TensorNumeric[T]) extends Pyt
ImageBytesToMat(byteKey, imageCodec)
}

def createImagePixelBytesToMat(
byteKey: String = ImageFeature.bytes): ImagePixelBytesToMat = {
ImagePixelBytesToMat(byteKey)
}

def createImageBrightness(deltaLow: Double, deltaHigh: Double): ImageBrightness = {
ImageBrightness(deltaLow, deltaHigh)
}
Expand All @@ -228,6 +233,10 @@ class PythonImageFeature[T: ClassTag](implicit ev: TensorNumeric[T]) extends Pyt
ImageFeatureToTensor()
}

def createImageFeatureToSample(): ImageFeatureToSample[T] = {
ImageFeatureToSample()
}

def createImageChannelNormalizer(
meanR: Double, meanG: Double, meanB: Double,
stdR: Double = 1, stdG: Double = 1, stdB: Double = 1
Expand Down Expand Up @@ -347,6 +356,10 @@ class PythonImageFeature[T: ClassTag](implicit ev: TensorNumeric[T]) extends Pyt
ImageHFlip()
}

def createImageMirror(): ImageMirror = {
ImageMirror()
}

def createImageSetToSample(inputKeys: JList[String],
targetKeys: JList[String],
sampleKey: String): ImageSetToSample[T] = {
Expand Down

0 comments on commit 29ac631

Please sign in to comment.