Skip to content

Commit

Permalink
Support creating Imageset from rdd of ndarray (intel-analytics#1507)
Browse files Browse the repository at this point in the history
* support create imageset from rdd from python

* add unit tests

* fix style
  • Loading branch information
yangw1234 committed Jul 11, 2019
1 parent b37cea6 commit 50e8122
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions python/dllib/src/bigdl/dllib/feature/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ def image_frame(cls, image_frame, memory_type="DRAM", bigdl_type="float"):
image_frame, memory_type)
return cls(jvalue=jvalue)

@classmethod
def image_set(cls, imageset, memory_type="DRAM", bigdl_type="float"):
"""
Create FeatureSet from ImageFrame.
:param image_frame: ImageFrame
:param memory_type: string, DRAM or PMEM
If it's DRAM, will cache dataset into dynamic random-access memory
If it's PMEM, will cache dataset into Intel Optane DC Persistent Memory
:param bigdl_type: numeric type
:return: A feature set
"""
jvalue = callBigDlFunc(bigdl_type, "createFeatureSetFromImageFrame",
imageset.to_image_frame(), memory_type)
return cls(jvalue=jvalue)

@classmethod
def rdd(cls, rdd, memory_type="DRAM", bigdl_type="float"):
"""
Expand Down
15 changes: 15 additions & 0 deletions python/dllib/src/bigdl/dllib/feature/image/imageset.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ class should be put into the same class folder. So each image in the path is lab
def from_image_frame(cls, image_frame, bigdl_type="float"):
return ImageSet(jvalue=callBigDlFunc(bigdl_type, "imageFrameToImageSet", image_frame))

@classmethod
def from_rdds(cls, image_rdd, label_rdd=None, bigdl_type="float"):
"""
Create a ImageSet from rdds of ndarray.
:param image_rdd: a rdd of ndarray, each ndarray should has dimension of 3 or 4 (3D images)
:param label_rdd: a rdd of ndarray
:return: a DistributedImageSet
"""
image_rdd = image_rdd.map(lambda x: JTensor.from_ndarray(x))
if label_rdd is not None:
label_rdd = label_rdd.map(lambda x: JTensor.from_ndarray(x))
return ImageSet(jvalue=callBigDlFunc(bigdl_type, "createDistributedImageSet",
image_rdd, label_rdd), bigdl_type=bigdl_type)

def transform(self, transformer):
"""
transformImageSet
Expand Down

0 comments on commit 50e8122

Please sign in to comment.