Skip to content

Commit c393679

Browse files
committed
adds test related to flow_from_dataset
1 parent 0105360 commit c393679

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

R/preprocessing.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ flow_images_from_directory <- function(
893893
#' @family image preprocessing
894894
#' @export
895895
flow_images_from_dataframe <- function(
896-
dataframe, directory=NULL, x_col="filename", y_col="class",
896+
dataframe, directory = NULL, x_col = "filename", y_col = "class",
897897
generator = image_data_generator(), target_size = c(256,256),
898898
color_mode = "rgb", classes = NULL, class_mode = "categorical",
899899
batch_size = 32, shuffle = TRUE, seed = NULL, save_to_dir = NULL,

tests/testthat/test-preprocessing.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,29 @@ test_succeeds("images arrays can be resized", {
7575
}
7676
})
7777

78+
test_succeeds("flow images from dataframe works", {
79+
if (have_pillow()) {
80+
81+
df <- data.frame(
82+
fname = rep("digit.jpeg", 10),
83+
class = letters[1:10],
84+
stringsAsFactors = FALSE
85+
)
86+
img_gen <- flow_images_from_dataframe(
87+
df,
88+
directory = ".",
89+
x_col = "fname",
90+
y_col = "class",
91+
drop_duplicates = FALSE
92+
)
93+
94+
batch <- reticulate::iter_next(img_gen)
95+
96+
expect_equal(dim(batch[[1]]), c(10, 256, 256, 3))
97+
expect_equal(dim(batch[[2]]), c(10, 10))
98+
}
99+
})
100+
101+
78102

79103

0 commit comments

Comments
 (0)