[go: nahoru, domu]

Skip to content

Commit

Permalink
Expose R for TIFF and LMDB
Browse files Browse the repository at this point in the history
This PR exposes TIFF and LMDB in R bindings.

Note: The plan is to relase 0.3.0 with TIFF and LMDB
with TensorFlow 1.12.0 support. Then release 0.4.0
with TensorFlow 1.13.0 support.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
  • Loading branch information
yongtang committed Feb 15, 2019
1 parent 2c8fa21 commit faa37c0
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 0 deletions.
26 changes: 26 additions & 0 deletions R-package/R/image_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,29 @@ webp_dataset <- function(filenames) {
dataset <- tfio_lib$image$WebPDataset(filenames = filenames)
as_tf_dataset(dataset)
}
#' Create a `TIFFDataset`.
#'
#' A TIFF Image File Dataset that reads the TIFF file.
#'
#' @param filenames A `tf.string` tensor containing one or more filenames.
#'
#' @examples \dontrun{
#' dataset <- tiff_dataset(
#' filenames = list("testdata/small.tiff")) %>%
#' dataset_repeat(1)
#'
#' sess <- tf$Session()
#' iterator <- make_iterator_one_shot(dataset)
#' next_batch <- iterator_get_next(iterator)
#'
#' until_out_of_range({
#' batch <- sess$run(next_batch)
#' print(batch)
#' })
#' }
#'
#' @export
tiff_dataset <- function(filenames) {
dataset <- tfio_lib$image$TIFFDataset(filenames = filenames)
as_tf_dataset(dataset)
}
26 changes: 26 additions & 0 deletions R-package/R/lmdb_dataset.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' Create a `LMDBDataset`.
#'
#' This function allows a user to read data from a LMDB
#' file. A lmdb file consists of (key value) pairs sequentially.
#'
#' @param filenames A `tf.string` tensor containing one or more filenames.
#'
#' @examples \dontrun{
#' dataset <- sequence_file_dataset("testdata/data.mdb") %>%
#' dataset_repeat(1)
#'
#' sess <- tf$Session()
#' iterator <- make_iterator_one_shot(dataset)
#' next_batch <- iterator_get_next(iterator)
#'
#' until_out_of_range({
#' batch <- sess$run(next_batch)
#' print(batch)
#' })
#' }
#'
#' @export
lmdb_dataset <- function(filenames) {
dataset <- tfio_lib$lmdb$LMDBDataset(filenames = filenames)
as_tf_dataset(dataset)
}
16 changes: 16 additions & 0 deletions R-package/tests/testthat/test-datasets-ops.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,19 @@ test_succeeds("video_dataset() works successfully", {
dataset_repeat(2)
iterate_all_batches(dataset)
})

test_succeeds("lmdb_dataset() works successfully", {
skip_on_travis()
dataset <- lmdb_dataset(
filenames = list("testdata/data.mdb")) %>%
dataset_repeat(2)
iterate_all_batches(dataset)
})

test_succeeds("tiff_dataset() works successfully", {
skip_on_travis()
dataset <- tiff_dataset(
filenames = list("testdata/small.tiff")) %>%
dataset_repeat(2)
iterate_all_batches(dataset)
})
Binary file added R-package/tests/testthat/testdata/data.mdb
Binary file not shown.
Binary file added R-package/tests/testthat/testdata/small.tiff
Binary file not shown.
3 changes: 3 additions & 0 deletions tensorflow_io/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@
"""Image Dataset.
@@WebPDataset
@@TIFFDataset
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorflow_io.image.python.ops.image_dataset_ops import WebPDataset
from tensorflow_io.image.python.ops.image_dataset_ops import TIFFDataset

from tensorflow.python.util.all_util import remove_undocumented

_allowed_symbols = [
"WebPDataset",
"TIFFDataset",
]

remove_undocumented(__name__)

0 comments on commit faa37c0

Please sign in to comment.