#' Create a dataframe from a directory with the imagenet
#' directory structure.
#'
#' The imagenet directory structure is laid out as follows
#' Top-level dirs: `train`, `test`, `valid` \cr
#' (you should provide path to those dirs as input) \cr
#' Mid-level dirs: `class1`, `class2`, `...` \cr
#' One directory for each class. The folders directly contain the images.
#' @param dirs [`character`]\cr
#' List of dirs to create dataframes from.
#' @return [`data.frame`]\cr
#' with columns "image" and "class" (the class).
#' @export
df_from_imagenet_dir = function(dirs) {
rbindlist(map(dirs, function(y) {
dt = rbindlist(map(list.dirs(y, recursive = FALSE), function(x) {
data.table(
class = basename(x),
image = list.files(x, full.names = TRUE)
)
}))
set(dt, j = "class", value = as.factor(dt$class))
return(dt)
}))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.