From 89e3875bf96f84338f6d147fd4c412a1cfce4d50 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sat, 12 Jul 2025 00:13:50 +0530 Subject: [PATCH 01/29] Adding pascal seg for splits train alone #139 --- R/dataset-pascal.R | 155 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 R/dataset-pascal.R diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R new file mode 100644 index 00000000..9a25c9fe --- /dev/null +++ b/R/dataset-pascal.R @@ -0,0 +1,155 @@ +#' @export +pascal_segmentation_dataset <- torch::dataset( + name = "pascal_segmentation_dataset", + + resources = list( + `2007` = list( + trainval = list( + url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar", + md5 = "c52e279531787c972589f7e41ab4ae64" + ), + test = list( + url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar", + md5 = "b6e924de25625d8de591ea690078ad9f" + ) + ), + `2008` = list( + trainval = list( + url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2008/VOCtrainval_14-Jul-2008.tar", + md5 = "2629fa636546599198acfcfbfcf1904a" + ) + ), + `2009` = list( + trainval = list( + url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2009/VOCtrainval_11-May-2009.tar", + md5 = "a3e00b113cfcfebf17e343f59da3caa1" + ) + ), + `2010` = list( + trainval = list( + url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2010/VOCtrainval_03-May-2010.tar", + md5 = "da459979d0c395079b5c75ee67908abb" + ) + ), + `2011` = list( + trainval = list( + url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2011/VOCtrainval_25-May-2011.tar", + md5 = "6c3384ef61512963050cb5d687e5bf1e" + ) + ), + `2012` = list( + trainval = list( + url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar", + md5 = "6cd6e144f989b92b3379bac3b3de84fd" + ) + ) + ), + + archive_size_table = list( + "2007" = list(trainval = "430 MB", test = "430 MB"), + "2008" = list(trainval = "1.0 GB"), + "2009" = list(trainval = "1.1 GB"), + "2010" = list(trainval = "1.1 GB"), + "2011" = list(trainval = "1.1 GB"), + "2012" = list(trainval = "2.0 GB") + ), + initialize = function( + root = tempdir(), + year = "2012", + split = "train", + transform = NULL, + target_transform = NULL, + download = FALSE + ) { + + self$root_path <- root + self$year <- match.arg(year, choices = names(self$resources)) + valid_splits <- names(self$resources[[self$year]]) + self$split <- match.arg(split, choices = valid_splits) + self$transform <- transform + self$target_transform <- target_transform + self$archive_size <- self$archive_size_table[[self$year]][[self$split]] + + if (download) { + cli_inform("Dataset {.cls {class(self)[[1]]}} (~{.emph {self$archive_size}}) will be downloaded and processed if not already available.") + self$download() + } + + if (!self$check_exists()) { + cli_abort("Pascal VOC dataset for year {self$year} not found. Use `download = TRUE` to fetch it.") + } + + data_file <- file.path(self$processed_folder, paste0(self$split, ".rds")) + data <- readRDS(data_file) + self$img_paths <- data$img_paths + self$mask_paths <- data$mask_paths + }, + + download = function() { + if (self$check_exists()) return() + + fs::dir_create(self$raw_folder) + fs::dir_create(self$processed_folder) + + resource <- self$resources[[self$year]][[self$split]] + archive <- download_and_cache(resource$url, prefix = class(self)[1]) + actual_md5 <- tools::md5sum(archive) + if (actual_md5 != resource$md5) { + cli_abort("Downloaded archive has incorrect MD5. Please delete and retry.") + } + + utils::untar(archive, exdir = self$raw_folder) + + voc_dir <- file.path(self$raw_folder, "VOCdevkit", paste0("VOC", self$year)) + split_file <- file.path(voc_dir, "ImageSets", "Segmentation", paste0(self$split, ".txt")) + + if (!fs::file_exists(split_file)) { + cli_abort("Split file not found: {split_file}") + } + + ids <- readLines(split_file) + img_paths <- file.path(voc_dir, "JPEGImages", paste0(ids, ".jpg")) + mask_paths <- file.path(voc_dir, "SegmentationClass", paste0(ids, ".png")) + + saveRDS(list( + img_paths = img_paths, + mask_paths = mask_paths + ), file.path(self$processed_folder, paste0(self$split, ".rds"))) + + cli_inform("Pascal VOC {self$year} dataset extracted and preprocessed.") + }, + + check_exists = function() { + fs::file_exists(file.path(self$processed_folder, paste0(self$split, ".rds"))) + }, + + .getitem = function(index) { + img_path <- self$img_paths[index] + mask_path <- self$mask_paths[index] + + x <- jpeg::readJPEG(img_path) + y <- png::readPNG(mask_path)[, , 1] + + if (!is.null(self$transform)) { + x <- self$transform(x) + } + if (!is.null(self$target_transform)) { + y <- self$target_transform(y) + } + + structure(list(x = x, y = y), class = "image_with_segmentation_mask") + }, + + .length = function() { + length(self$img_paths) + }, + + active = list( + raw_folder = function() { + file.path(self$root_path, paste0("pascal_voc_", self$year), "raw") + }, + processed_folder = function() { + file.path(self$root_path, paste0("pascal_voc_", self$year), "processed") + } + ) +) From 3719395d8f48f11387b87751ef003ba97e395254 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sat, 12 Jul 2025 00:57:08 +0530 Subject: [PATCH 02/29] Added support for train,test,trainval and val splits and 2007 to 2012 years for seg dataset #139 --- R/dataset-pascal.R | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 9a25c9fe..5e185bf3 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -46,13 +46,14 @@ pascal_segmentation_dataset <- torch::dataset( ), archive_size_table = list( - "2007" = list(trainval = "430 MB", test = "430 MB"), - "2008" = list(trainval = "1.0 GB"), - "2009" = list(trainval = "1.1 GB"), - "2010" = list(trainval = "1.1 GB"), - "2011" = list(trainval = "1.1 GB"), - "2012" = list(trainval = "2.0 GB") + "2007" = list(trainval = "430 MB", test = "440 MB"), + "2008" = list(trainval = "550 MB"), + "2009" = list(trainval = "890 MB"), + "2010" = list(trainval = "1.3 GB"), + "2011" = list(trainval = "1.7 GB"), + "2012" = list(trainval = "1.9 GB") ), + initialize = function( root = tempdir(), year = "2012", @@ -61,14 +62,14 @@ pascal_segmentation_dataset <- torch::dataset( target_transform = NULL, download = FALSE ) { - self$root_path <- root self$year <- match.arg(year, choices = names(self$resources)) - valid_splits <- names(self$resources[[self$year]]) - self$split <- match.arg(split, choices = valid_splits) + self$split <- match.arg(split, choices = c("train", "val", "trainval", "test")) self$transform <- transform self$target_transform <- target_transform - self$archive_size <- self$archive_size_table[[self$year]][[self$split]] + + archive_key <- if (self$split == "test") "test" else "trainval" + self$archive_size <- self$archive_size_table[[self$year]][[archive_key]] if (download) { cli_inform("Dataset {.cls {class(self)[[1]]}} (~{.emph {self$archive_size}}) will be downloaded and processed if not already available.") @@ -91,7 +92,8 @@ pascal_segmentation_dataset <- torch::dataset( fs::dir_create(self$raw_folder) fs::dir_create(self$processed_folder) - resource <- self$resources[[self$year]][[self$split]] + archive_key <- if (self$split == "test") "test" else "trainval" + resource <- self$resources[[self$year]][[archive_key]] archive <- download_and_cache(resource$url, prefix = class(self)[1]) actual_md5 <- tools::md5sum(archive) if (actual_md5 != resource$md5) { @@ -101,6 +103,12 @@ pascal_segmentation_dataset <- torch::dataset( utils::untar(archive, exdir = self$raw_folder) voc_dir <- file.path(self$raw_folder, "VOCdevkit", paste0("VOC", self$year)) + voc_root <- self$raw_folder + if (self$year == "2011") { + voc_root <- file.path(voc_root, "TrainVal") + } + voc_dir <- file.path(voc_root, "VOCdevkit", paste0("VOC", self$year)) + split_file <- file.path(voc_dir, "ImageSets", "Segmentation", paste0(self$split, ".txt")) if (!fs::file_exists(split_file)) { From 5f8b95c4a94c94654c459779771e9f44036195c0 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sat, 12 Jul 2025 01:28:32 +0530 Subject: [PATCH 03/29] Making seg dataset consistent according to #165 --- R/dataset-pascal.R | 77 +++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 46 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 5e185bf3..8db792bf 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -4,44 +4,23 @@ pascal_segmentation_dataset <- torch::dataset( resources = list( `2007` = list( - trainval = list( - url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar", - md5 = "c52e279531787c972589f7e41ab4ae64" - ), - test = list( - url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar", - md5 = "b6e924de25625d8de591ea690078ad9f" - ) + trainval = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar",md5 = "c52e279531787c972589f7e41ab4ae64"), + test = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar",md5 = "b6e924de25625d8de591ea690078ad9f") ), `2008` = list( - trainval = list( - url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2008/VOCtrainval_14-Jul-2008.tar", - md5 = "2629fa636546599198acfcfbfcf1904a" - ) + trainval = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2008/VOCtrainval_14-Jul-2008.tar",md5 = "2629fa636546599198acfcfbfcf1904a") ), `2009` = list( - trainval = list( - url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2009/VOCtrainval_11-May-2009.tar", - md5 = "a3e00b113cfcfebf17e343f59da3caa1" - ) + trainval = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2009/VOCtrainval_11-May-2009.tar",md5 = "a3e00b113cfcfebf17e343f59da3caa1") ), `2010` = list( - trainval = list( - url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2010/VOCtrainval_03-May-2010.tar", - md5 = "da459979d0c395079b5c75ee67908abb" - ) + trainval = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2010/VOCtrainval_03-May-2010.tar",md5 = "da459979d0c395079b5c75ee67908abb") ), `2011` = list( - trainval = list( - url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2011/VOCtrainval_25-May-2011.tar", - md5 = "6c3384ef61512963050cb5d687e5bf1e" - ) + trainval = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2011/VOCtrainval_25-May-2011.tar",md5 = "6c3384ef61512963050cb5d687e5bf1e") ), `2012` = list( - trainval = list( - url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar", - md5 = "6cd6e144f989b92b3379bac3b3de84fd" - ) + trainval = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar",md5 = "6cd6e144f989b92b3379bac3b3de84fd") ) ), @@ -67,9 +46,12 @@ pascal_segmentation_dataset <- torch::dataset( self$split <- match.arg(split, choices = c("train", "val", "trainval", "test")) self$transform <- transform self$target_transform <- target_transform - - archive_key <- if (self$split == "test") "test" else "trainval" - self$archive_size <- self$archive_size_table[[self$year]][[archive_key]] + if (self$split == "test"){ + self$archive_key <- "test" + } else { + self$archive_key <- "trainval" + } + self$archive_size <- self$archive_size_table[[self$year]][[self$archive_key]] if (download) { cli_inform("Dataset {.cls {class(self)[[1]]}} (~{.emph {self$archive_size}}) will be downloaded and processed if not already available.") @@ -77,27 +59,34 @@ pascal_segmentation_dataset <- torch::dataset( } if (!self$check_exists()) { - cli_abort("Pascal VOC dataset for year {self$year} not found. Use `download = TRUE` to fetch it.") + cli_abort("Dataset not found. You can use `download = TRUE` to download it.") } data_file <- file.path(self$processed_folder, paste0(self$split, ".rds")) data <- readRDS(data_file) - self$img_paths <- data$img_paths + self$image_ids <- data$image_ids self$mask_paths <- data$mask_paths + + cli_inform("{.cls {class(self)[[1]]}} dataset loaded with {length(self$image_ids)} images.") }, download = function() { - if (self$check_exists()) return() + + if (self$check_exists()) { + return() + } + + cli_inform("Downloading {.cls {class(self)[[1]]}}...") fs::dir_create(self$raw_folder) fs::dir_create(self$processed_folder) - archive_key <- if (self$split == "test") "test" else "trainval" - resource <- self$resources[[self$year]][[archive_key]] + resource <- self$resources[[self$year]][[self$archive_key]] archive <- download_and_cache(resource$url, prefix = class(self)[1]) actual_md5 <- tools::md5sum(archive) + if (actual_md5 != resource$md5) { - cli_abort("Downloaded archive has incorrect MD5. Please delete and retry.") + runtime_error("Corrupt file! Delete the file in {archive} and try again.") } utils::untar(archive, exdir = self$raw_folder) @@ -111,20 +100,16 @@ pascal_segmentation_dataset <- torch::dataset( split_file <- file.path(voc_dir, "ImageSets", "Segmentation", paste0(self$split, ".txt")) - if (!fs::file_exists(split_file)) { - cli_abort("Split file not found: {split_file}") - } - ids <- readLines(split_file) - img_paths <- file.path(voc_dir, "JPEGImages", paste0(ids, ".jpg")) + image_ids <- file.path(voc_dir, "JPEGImages", paste0(ids, ".jpg")) mask_paths <- file.path(voc_dir, "SegmentationClass", paste0(ids, ".png")) saveRDS(list( - img_paths = img_paths, + image_ids = image_ids, mask_paths = mask_paths ), file.path(self$processed_folder, paste0(self$split, ".rds"))) - cli_inform("Pascal VOC {self$year} dataset extracted and preprocessed.") + cli_inform("Dataset {.cls {class(self)[[1]]}} downloaded and extracted successfully.") }, check_exists = function() { @@ -132,7 +117,7 @@ pascal_segmentation_dataset <- torch::dataset( }, .getitem = function(index) { - img_path <- self$img_paths[index] + img_path <- self$image_ids[index] mask_path <- self$mask_paths[index] x <- jpeg::readJPEG(img_path) @@ -149,7 +134,7 @@ pascal_segmentation_dataset <- torch::dataset( }, .length = function() { - length(self$img_paths) + length(self$image_ids) }, active = list( From 066cd684646a81e00c02fbcecbf08379902ed309 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sat, 12 Jul 2025 02:06:04 +0530 Subject: [PATCH 04/29] y returns list with named variable masks #139 --- R/dataset-pascal.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 8db792bf..9a2f9950 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -121,7 +121,11 @@ pascal_segmentation_dataset <- torch::dataset( mask_path <- self$mask_paths[index] x <- jpeg::readJPEG(img_path) - y <- png::readPNG(mask_path)[, , 1] + masks <- png::readPNG(mask_path)*255 + + y <- list( + masks = masks + ) if (!is.null(self$transform)) { x <- self$transform(x) From f1325c3624f6b9ba821d4e8613fa464d8d9244ae Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Thu, 17 Jul 2025 01:54:35 +0530 Subject: [PATCH 05/29] Segmentation can now be visualised using draw_segmentation_masks() #139: --- R/dataset-pascal.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 9a2f9950..5d385972 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -122,6 +122,7 @@ pascal_segmentation_dataset <- torch::dataset( x <- jpeg::readJPEG(img_path) masks <- png::readPNG(mask_path)*255 + masks <- torch_tensor(masks, dtype = torch_bool())$permute(c(3, 1, 2)) y <- list( masks = masks From ac193aa9d7fe9cfb328013cce212ac3ce99a57ed Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Wed, 23 Jul 2025 14:56:31 +0530 Subject: [PATCH 06/29] Updating NEWS.md --- NEWS.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/NEWS.md b/NEWS.md index d6a5501e..ab451355 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,19 @@ +# torchvision (development version) + +## New datasets + +* Added `lfw_people_dataset()` and `lfw_pairs_dataset()` for loading Labelled Faces in the Wild (LFW) datasets (@DerrickUnleashed, #203). +* Added `pascal_segmentation_dataset()`, and `pascal_detection_dataset()` for loading the Pascal Visual Object Classes datasets (@DerrickUnleashed, #162). +* Added `places365_dataset()`for loading the Places365 dataset (@koshtiakanksha, #196). + +## New models + +## New features + +## Bug fixes and improvements + +* Switch pre 0.5.0 models to their `/v2/` URL in torch-cdn.mlverse.org. (#215) + # torchvision 0.7.0 ## New datasets @@ -14,9 +30,17 @@ * Added `flickr8k_dataset()` and `flickr30k_dataset()` for loading the Flickr8k and Flickr30k datasets (@DerrickUnleashed, #159). * Added `oxfordiiitpet_dataset()`, `oxfordiiitpet_binary_dataset()`, and `oxfordiiitpet_segmentation_dataset()` for loading the Oxford-IIIT Pet datasets (@DerrickUnleashed, #162). +## New models + +* Added EfficientNet model family (B0–B7) – scalable CNNs for image classification. (#166, @koshtiakanksha) +* Added EfficientNetV2 model family (V2-S/M/L) – improved EfficientNet models for faster training. (#166, @koshtiakanksha) +* Added `model_vit_b_16()`, `model_vit_b_32()`, `model_vit_l_16()`, `model_vit_l_32()`, and `model_vit_h_14()` for loading Vision Transformer models (@DerrickUnleashed, #202). + ## New features * `tensor_image_display()` and `tensor_image_browse()` now accept all `tensor_image` dtypes (@cregouby, #115). +* `tensor_image_display()` and `tensor_image_browse()` now accept `image_with_bounding_box` and `image_with_segmentation_mask` inputs which are + the default items class for respectively detection datasets and segmentation datasets (@koshtiakanksha, #175). * `fgvc_aircraft_dataset()` gains support for `annotation_level = "all"` (@DerrickUnleashed, #168). * `folder_dataset()` now supports TIFF image formats (@cregouby, #169). * New `nms()` and `batched_nms()` functions provide Non-Maximum Suppression utilities. Added `box_convert()` to convert between bounding box formats (@Athospd, #40). From d5daffbc63484d671f62ba8692b1769486531387 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Fri, 1 Aug 2025 13:01:53 +0530 Subject: [PATCH 07/29] Updating NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 02f0336b..b45dd649 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ * Added `lfw_people_dataset()` and `lfw_pairs_dataset()` for loading Labelled Faces in the Wild (LFW) datasets (@DerrickUnleashed, #203). * Added `places365_dataset()`for loading the Places365 dataset (@koshtiakanksha, #196). -* Added `pascal_segmentation_dataset()`, and `pascal_detection_dataset()` for loading the Pascal Visual Object Classes datasets (@DerrickUnleashed, #162). +* Added `pascal_segmentation_dataset()`, and `pascal_detection_dataset()` for loading the Pascal Visual Object Classes datasets (@DerrickUnleashed, #139). ## New models From daebb7afddeaac61cda6939e4f07d9e690578d26 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Fri, 1 Aug 2025 13:02:20 +0530 Subject: [PATCH 08/29] Changing urls since original website is down --- R/dataset-pascal.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 5d385972..8ed04e29 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -4,28 +4,28 @@ pascal_segmentation_dataset <- torch::dataset( resources = list( `2007` = list( - trainval = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar",md5 = "c52e279531787c972589f7e41ab4ae64"), - test = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar",md5 = "b6e924de25625d8de591ea690078ad9f") + trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_06-Nov-2007.tar",md5 = "c52e279531787c972589f7e41ab4ae64"), + test = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtest_06-Nov-2007.tar",md5 = "b6e924de25625d8de591ea690078ad9f") ), `2008` = list( - trainval = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2008/VOCtrainval_14-Jul-2008.tar",md5 = "2629fa636546599198acfcfbfcf1904a") + trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_14-Jul-2008.tar",md5 = "2629fa636546599198acfcfbfcf1904a") ), `2009` = list( - trainval = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2009/VOCtrainval_11-May-2009.tar",md5 = "a3e00b113cfcfebf17e343f59da3caa1") + trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_11-May-2009.tar",md5 = "59065e4b188729180974ef6572f6a212") ), `2010` = list( - trainval = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2010/VOCtrainval_03-May-2010.tar",md5 = "da459979d0c395079b5c75ee67908abb") + trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_03-May-2010.tar",md5 = "da459979d0c395079b5c75ee67908abb") ), `2011` = list( - trainval = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2011/VOCtrainval_25-May-2011.tar",md5 = "6c3384ef61512963050cb5d687e5bf1e") + trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_25-May-2011.tar",md5 = "6c3384ef61512963050cb5d687e5bf1e") ), `2012` = list( - trainval = list(url = "http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar",md5 = "6cd6e144f989b92b3379bac3b3de84fd") + trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_11-May-2012.tar",md5 = "6cd6e144f989b92b3379bac3b3de84fd") ) ), archive_size_table = list( - "2007" = list(trainval = "430 MB", test = "440 MB"), + "2007" = list(trainval = "440 MB", test = "440 MB"), "2008" = list(trainval = "550 MB"), "2009" = list(trainval = "890 MB"), "2010" = list(trainval = "1.3 GB"), From 664d6f5bfaf2f4bc1cd529a99fa58829e74de4e0 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Fri, 1 Aug 2025 14:50:18 +0530 Subject: [PATCH 09/29] Adding pascal_detection_dataset() with all functionalities --- R/dataset-pascal.R | 107 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 101 insertions(+), 6 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 8ed04e29..807b8bff 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -64,10 +64,10 @@ pascal_segmentation_dataset <- torch::dataset( data_file <- file.path(self$processed_folder, paste0(self$split, ".rds")) data <- readRDS(data_file) - self$image_ids <- data$image_ids + self$img_path <- data$img_path self$mask_paths <- data$mask_paths - cli_inform("{.cls {class(self)[[1]]}} dataset loaded with {length(self$image_ids)} images.") + cli_inform("{.cls {class(self)[[1]]}} dataset loaded with {length(self$img_path)} images.") }, download = function() { @@ -101,11 +101,11 @@ pascal_segmentation_dataset <- torch::dataset( split_file <- file.path(voc_dir, "ImageSets", "Segmentation", paste0(self$split, ".txt")) ids <- readLines(split_file) - image_ids <- file.path(voc_dir, "JPEGImages", paste0(ids, ".jpg")) + img_path <- file.path(voc_dir, "JPEGImages", paste0(ids, ".jpg")) mask_paths <- file.path(voc_dir, "SegmentationClass", paste0(ids, ".png")) saveRDS(list( - image_ids = image_ids, + img_path = img_path, mask_paths = mask_paths ), file.path(self$processed_folder, paste0(self$split, ".rds"))) @@ -117,7 +117,7 @@ pascal_segmentation_dataset <- torch::dataset( }, .getitem = function(index) { - img_path <- self$image_ids[index] + img_path <- self$img_path[index] mask_path <- self$mask_paths[index] x <- jpeg::readJPEG(img_path) @@ -139,7 +139,7 @@ pascal_segmentation_dataset <- torch::dataset( }, .length = function() { - length(self$image_ids) + length(self$img_path) }, active = list( @@ -151,3 +151,98 @@ pascal_segmentation_dataset <- torch::dataset( } ) ) + +#' @export +pascal_detection_dataset <- torch::dataset( + name = "pascal_detection_dataset", + + inherit = pascal_segmentation_dataset, + + initialize = function( + root = tempdir(), + year = "2012", + split = "train", + transform = NULL, + target_transform = NULL, + download = FALSE + ) { + + self$root_path <- root + self$year <- match.arg(year, choices = names(self$resources)) + self$split <- match.arg(split, choices = c("train", "val", "trainval", "test")) + self$transform <- transform + self$target_transform <- target_transform + if (self$split == "test") { + self$archive_key <- "test" + } else { + self$archive_key <- "trainval" + } + self$archive_size <- self$archive_size_table[[self$year]][[self$archive_key]] + + if (download) { + cli_inform("Dataset {.cls {class(self)[[1]]}} (~{.emph {self$archive_size}}) will be downloaded and processed if not already available.") + self$download() + } + + if (!self$check_exists()) { + cli_abort("Dataset not found. You can use `download = TRUE` to download it.") + } + + voc_dir <- file.path(self$raw_folder, "VOCdevkit", paste0("VOC", self$year)) + if (self$year == "2011") { + voc_dir <- file.path(self$raw_folder, "TrainVal", "VOCdevkit", paste0("VOC", self$year)) + } + + ids_file <- file.path(voc_dir, "ImageSets", "Main", paste0(self$split, ".txt")) + ids <- readLines(ids_file) + + self$img_path <- file.path(voc_dir, "JPEGImages", paste0(ids, ".jpg")) + self$annotation_paths <- file.path(voc_dir, "Annotations", paste0(ids, ".xml")) + + cli_inform("{.cls {class(self)[[1]]}} dataset loaded with {length(self$img_path)} images.") + }, + + .getitem = function(index) { + x <- jpeg::readJPEG(self$img_path[index]) + ann_path <- self$annotation_paths[index] + y <- self$parse_voc_xml(xml2::read_xml(ann_path)) + + if (!is.null(self$transform)) { + x <- self$transform(x) + } + if (!is.null(self$target_transform)) { + y <- self$target_transform(y) + } + + structure(list(x = x, y = y), class = "image_with_bounding_box") + }, + + parse_voc_xml = function(xml) { + objects <- xml2::xml_find_all(xml, ".//object") + + labels <- character(length(objects)) + boxes <- vector("list", length(objects)) + + for (i in seq_along(objects)) { + obj <- objects[[i]] + print(obj) + + labels[i] <- xml2::xml_text(xml2::xml_find_first(obj, "name")) + + bbox <- xml2::xml_find_first(obj, "bndbox") + xmin <- as.integer(xml2::xml_text(xml2::xml_find_first(bbox, "xmin"))) + ymin <- as.integer(xml2::xml_text(xml2::xml_find_first(bbox, "ymin"))) + xmax <- as.integer(xml2::xml_text(xml2::xml_find_first(bbox, "xmax"))) + ymax <- as.integer(xml2::xml_text(xml2::xml_find_first(bbox, "ymax"))) + + boxes[[i]] <- c(xmin, ymin, xmax, ymax) + } + + boxes <- torch_tensor(do.call(rbind, boxes), dtype = torch_int64()) + + list( + labels = labels, + boxes = boxes + ) + } +) \ No newline at end of file From 28d5a8f24162258dabd26913f5bee32d674fe5ca Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Fri, 1 Aug 2025 15:28:18 +0530 Subject: [PATCH 10/29] Testing pascal_seg on CI #139 --- tests/testthat/test-dataset-pascal.R | 346 +++++++++++++++++++++++++++ 1 file changed, 346 insertions(+) create mode 100644 tests/testthat/test-dataset-pascal.R diff --git a/tests/testthat/test-dataset-pascal.R b/tests/testthat/test-dataset-pascal.R new file mode 100644 index 00000000..ee04bad0 --- /dev/null +++ b/tests/testthat/test-dataset-pascal.R @@ -0,0 +1,346 @@ +context('dataset-pascal') + +t = withr::local_tempdir() + +test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2007", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'train', download = TRUE) + expect_length(pascal, 209) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,421500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for test split for year 2007", { + + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'test', download = TRUE) + expect_length(pascal, 210) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,375,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2007", { + + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'trainval', download = TRUE) + expect_length(pascal, 422) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,421500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2007", { + + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'val', download = TRUE) + expect_length(pascal, 213) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,375,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2008", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2008', split = 'train', download = TRUE) + expect_length(pascal, 511) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,421500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2008", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2008', split = 'trainval', download = TRUE) + expect_length(pascal, 1023) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,421500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2008", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2008', split = 'val', download = TRUE) + expect_length(pascal, 512) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,549000) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,366,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2009", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2009', split = 'train', download = TRUE) + expect_length(pascal, 749) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,421500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2009", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2009', split = 'trainval', download = TRUE) + expect_length(pascal, 1499) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,421500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2009", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2009', split = 'val', download = TRUE) + expect_length(pascal, 750) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,549000) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,366,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2010", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2010', split = 'train', download = TRUE) + expect_length(pascal, 964) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,421500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2010", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2010', split = 'trainval', download = TRUE) + expect_length(pascal, 1928) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,421500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2010", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2010', split = 'val', download = TRUE) + expect_length(pascal, 964) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,549000) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,366,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2011", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2011', split = 'train', download = TRUE) + expect_length(pascal, 1112) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,421500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2011", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2011', split = 'trainval', download = TRUE) + expect_length(pascal, 2223) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,421500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2011", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2011', split = 'val', download = TRUE) + expect_length(pascal, 1111) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,549000) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,366,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2012", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2012', split = 'train', download = TRUE) + expect_length(pascal, 1464) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,421500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2012", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2012', split = 'trainval', download = TRUE) + expect_length(pascal, 2913) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,421500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + +test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2012", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_segmentation_dataset(root = t, year = '2012', split = 'val', download = TRUE) + expect_length(pascal, 1449) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,549000) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$mask) + expect_tensor_shape(first_item$y$mask,c(3,366,500)) + expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_s3_class(first_item, "image_with_segmentation_mask") +}) + From 437d7e0e872c0f5afa70c3d6bb0512df0f1db8a3 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Fri, 1 Aug 2025 16:22:11 +0530 Subject: [PATCH 11/29] Testing pascal_detection on CI #139 --- R/dataset-pascal.R | 1 - tests/testthat/test-dataset-pascal.R | 379 +++++++++++++++++++++++++++ 2 files changed, 379 insertions(+), 1 deletion(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 807b8bff..9bad92a2 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -225,7 +225,6 @@ pascal_detection_dataset <- torch::dataset( for (i in seq_along(objects)) { obj <- objects[[i]] - print(obj) labels[i] <- xml2::xml_text(xml2::xml_find_first(obj, "name")) diff --git a/tests/testthat/test-dataset-pascal.R b/tests/testthat/test-dataset-pascal.R index ee04bad0..92133ac6 100644 --- a/tests/testthat/test-dataset-pascal.R +++ b/tests/testthat/test-dataset-pascal.R @@ -344,3 +344,382 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_s3_class(first_item, "image_with_segmentation_mask") }) +test_that("tests for the Pascal VOC detection dataset for train split for year 2007", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2007', split = 'train', download = TRUE) + expect_length(pascal, 2501) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,499500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(1,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 1) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for test split for year 2007", { + + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2007', split = 'test', download = TRUE) + expect_length(pascal, 4952) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,529500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(2,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 2) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for trainval split for year 2007", { + + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2007', split = 'trainval', download = TRUE) + expect_length(pascal, 5011) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(5,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 5) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for val split for year 2007", { + + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2007', split = 'val', download = TRUE) + expect_length(pascal, 2510) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(5,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 5) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for train split for year 2008", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2008', split = 'train', download = TRUE) + expect_length(pascal, 2111) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,663000) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(2,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 2) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for trainval split for year 2008", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2008', split = 'trainval', download = TRUE) + expect_length(pascal, 4332) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(1,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 1) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for val split for year 2008", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2008', split = 'val', download = TRUE) + expect_length(pascal, 2221) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(1,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 1) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for train split for year 2009", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2009', split = 'train', download = TRUE) + expect_length(pascal, 3473) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,663000) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(2,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 2) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for trainval split for year 2009", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2009', split = 'trainval', download = TRUE) + expect_length(pascal, 7054) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(1,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 1) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for val split for year 2009", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2009', split = 'val', download = TRUE) + expect_length(pascal, 3581) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(1,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 1) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for train split for year 2010", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2010', split = 'train', download = TRUE) + expect_length(pascal, 4998) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,663000) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(2,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 2) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for trainval split for year 2010", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2010', split = 'trainval', download = TRUE) + expect_length(pascal, 10103) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(1,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 1) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for val split for year 2010", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2010', split = 'val', download = TRUE) + expect_length(pascal, 5105) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(1,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 1) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for train split for year 2011", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2011', split = 'train', download = TRUE) + expect_length(pascal, 5717) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,663000) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(2,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 2) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for trainval split for year 2011", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2011', split = 'trainval', download = TRUE) + expect_length(pascal, 11540) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(1,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 1) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for val split for year 2011", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2011', split = 'val', download = TRUE) + expect_length(pascal, 5823) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(1,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 1) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for train split for year 2012", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2012', split = 'train', download = TRUE) + expect_length(pascal, 5717) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,663000) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(2,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 2) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for trainval split for year 2012", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2012', split = 'trainval', download = TRUE) + expect_length(pascal, 11540) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(1,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 1) + expect_s3_class(first_item, "image_with_bounding_box") +}) + +test_that("tests for the Pascal VOC detection dataset for val split for year 2012", { + +# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, +# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + + pascal <- pascal_detection_dataset(root = t, year = '2012', split = 'val', download = TRUE) + expect_length(pascal, 5823) + first_item <- pascal[1] + expect_named(first_item, c("x", "y")) + expect_length(first_item$x,562500) + expect_type(first_item$x, "double") + expect_type(first_item$y, "list") + expect_tensor(first_item$y$boxes) + expect_tensor_shape(first_item$y$boxes,c(1,4)) + expect_tensor_dtype(first_item$y$boxes,torch_int64()) + expect_type(first_item$y$labels,"character") + expect_length(first_item$y$labels, 1) + expect_s3_class(first_item, "image_with_bounding_box") +}) \ No newline at end of file From 52f36cb01486091c014690b4092957c9f75357c8 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Fri, 1 Aug 2025 16:51:19 +0530 Subject: [PATCH 12/29] Adding xml2 dependency #139: --- DESCRIPTION | 3 ++- R/dataset-pascal.R | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 07a5db65..d417e8d9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -51,5 +51,6 @@ Suggests: magick, testthat, coro, - R.matlab + R.matlab, + xml2 BugReports: https://github.com/mlverse/torchvision/issues diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 9bad92a2..b862518c 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -199,10 +199,15 @@ pascal_detection_dataset <- torch::dataset( self$img_path <- file.path(voc_dir, "JPEGImages", paste0(ids, ".jpg")) self$annotation_paths <- file.path(voc_dir, "Annotations", paste0(ids, ".xml")) + if (!requireNamespace("xml2", quietly = TRUE)) { + install.packages("xml2") + } + cli_inform("{.cls {class(self)[[1]]}} dataset loaded with {length(self$img_path)} images.") }, .getitem = function(index) { + x <- jpeg::readJPEG(self$img_path[index]) ann_path <- self$annotation_paths[index] y <- self$parse_voc_xml(xml2::read_xml(ann_path)) From f8572f1da5c50d151f68ce664105b9eaf4ac1781 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Fri, 1 Aug 2025 18:16:16 +0530 Subject: [PATCH 13/29] Removing skips for tests since it is successful in prev commit #139 --- tests/testthat/test-dataset-pascal.R | 152 +++++++++++++-------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/tests/testthat/test-dataset-pascal.R b/tests/testthat/test-dataset-pascal.R index 92133ac6..5f8b13d8 100644 --- a/tests/testthat/test-dataset-pascal.R +++ b/tests/testthat/test-dataset-pascal.R @@ -4,8 +4,8 @@ t = withr::local_tempdir() test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2007", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'train', download = TRUE) expect_length(pascal, 209) @@ -22,8 +22,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea test_that("tests for the Pascal VOC Segmentation dataset for test split for year 2007", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'test', download = TRUE) expect_length(pascal, 210) @@ -40,8 +40,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for test split for year test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2007", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'trainval', download = TRUE) expect_length(pascal, 422) @@ -58,8 +58,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2007", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'val', download = TRUE) expect_length(pascal, 213) @@ -76,8 +76,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2008", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2008', split = 'train', download = TRUE) expect_length(pascal, 511) @@ -94,8 +94,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2008", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2008', split = 'trainval', download = TRUE) expect_length(pascal, 1023) @@ -112,8 +112,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2008", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2008', split = 'val', download = TRUE) expect_length(pascal, 512) @@ -130,8 +130,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2009", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2009', split = 'train', download = TRUE) expect_length(pascal, 749) @@ -148,8 +148,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2009", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2009', split = 'trainval', download = TRUE) expect_length(pascal, 1499) @@ -166,8 +166,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2009", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2009', split = 'val', download = TRUE) expect_length(pascal, 750) @@ -184,8 +184,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2010", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2010', split = 'train', download = TRUE) expect_length(pascal, 964) @@ -202,8 +202,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2010", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2010', split = 'trainval', download = TRUE) expect_length(pascal, 1928) @@ -220,8 +220,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2010", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2010', split = 'val', download = TRUE) expect_length(pascal, 964) @@ -238,8 +238,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2011", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2011', split = 'train', download = TRUE) expect_length(pascal, 1112) @@ -256,8 +256,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2011", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2011', split = 'trainval', download = TRUE) expect_length(pascal, 2223) @@ -274,8 +274,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2011", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2011', split = 'val', download = TRUE) expect_length(pascal, 1111) @@ -292,8 +292,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2012", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2012', split = 'train', download = TRUE) expect_length(pascal, 1464) @@ -310,8 +310,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2012", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2012', split = 'trainval', download = TRUE) expect_length(pascal, 2913) @@ -328,8 +328,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2012", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2012', split = 'val', download = TRUE) expect_length(pascal, 1449) @@ -346,8 +346,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year test_that("tests for the Pascal VOC detection dataset for train split for year 2007", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2007', split = 'train', download = TRUE) expect_length(pascal, 2501) @@ -366,8 +366,8 @@ test_that("tests for the Pascal VOC detection dataset for train split for year 2 test_that("tests for the Pascal VOC detection dataset for test split for year 2007", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2007', split = 'test', download = TRUE) expect_length(pascal, 4952) @@ -386,8 +386,8 @@ test_that("tests for the Pascal VOC detection dataset for test split for year 20 test_that("tests for the Pascal VOC detection dataset for trainval split for year 2007", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2007', split = 'trainval', download = TRUE) expect_length(pascal, 5011) @@ -406,8 +406,8 @@ test_that("tests for the Pascal VOC detection dataset for trainval split for yea test_that("tests for the Pascal VOC detection dataset for val split for year 2007", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2007', split = 'val', download = TRUE) expect_length(pascal, 2510) @@ -426,8 +426,8 @@ test_that("tests for the Pascal VOC detection dataset for val split for year 200 test_that("tests for the Pascal VOC detection dataset for train split for year 2008", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2008', split = 'train', download = TRUE) expect_length(pascal, 2111) @@ -446,8 +446,8 @@ test_that("tests for the Pascal VOC detection dataset for train split for year 2 test_that("tests for the Pascal VOC detection dataset for trainval split for year 2008", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2008', split = 'trainval', download = TRUE) expect_length(pascal, 4332) @@ -466,8 +466,8 @@ test_that("tests for the Pascal VOC detection dataset for trainval split for yea test_that("tests for the Pascal VOC detection dataset for val split for year 2008", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2008', split = 'val', download = TRUE) expect_length(pascal, 2221) @@ -486,8 +486,8 @@ test_that("tests for the Pascal VOC detection dataset for val split for year 200 test_that("tests for the Pascal VOC detection dataset for train split for year 2009", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2009', split = 'train', download = TRUE) expect_length(pascal, 3473) @@ -506,8 +506,8 @@ test_that("tests for the Pascal VOC detection dataset for train split for year 2 test_that("tests for the Pascal VOC detection dataset for trainval split for year 2009", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2009', split = 'trainval', download = TRUE) expect_length(pascal, 7054) @@ -526,8 +526,8 @@ test_that("tests for the Pascal VOC detection dataset for trainval split for yea test_that("tests for the Pascal VOC detection dataset for val split for year 2009", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2009', split = 'val', download = TRUE) expect_length(pascal, 3581) @@ -546,8 +546,8 @@ test_that("tests for the Pascal VOC detection dataset for val split for year 200 test_that("tests for the Pascal VOC detection dataset for train split for year 2010", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2010', split = 'train', download = TRUE) expect_length(pascal, 4998) @@ -566,8 +566,8 @@ test_that("tests for the Pascal VOC detection dataset for train split for year 2 test_that("tests for the Pascal VOC detection dataset for trainval split for year 2010", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2010', split = 'trainval', download = TRUE) expect_length(pascal, 10103) @@ -586,8 +586,8 @@ test_that("tests for the Pascal VOC detection dataset for trainval split for yea test_that("tests for the Pascal VOC detection dataset for val split for year 2010", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2010', split = 'val', download = TRUE) expect_length(pascal, 5105) @@ -606,8 +606,8 @@ test_that("tests for the Pascal VOC detection dataset for val split for year 201 test_that("tests for the Pascal VOC detection dataset for train split for year 2011", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2011', split = 'train', download = TRUE) expect_length(pascal, 5717) @@ -626,8 +626,8 @@ test_that("tests for the Pascal VOC detection dataset for train split for year 2 test_that("tests for the Pascal VOC detection dataset for trainval split for year 2011", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2011', split = 'trainval', download = TRUE) expect_length(pascal, 11540) @@ -646,8 +646,8 @@ test_that("tests for the Pascal VOC detection dataset for trainval split for yea test_that("tests for the Pascal VOC detection dataset for val split for year 2011", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2011', split = 'val', download = TRUE) expect_length(pascal, 5823) @@ -666,8 +666,8 @@ test_that("tests for the Pascal VOC detection dataset for val split for year 201 test_that("tests for the Pascal VOC detection dataset for train split for year 2012", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2012', split = 'train', download = TRUE) expect_length(pascal, 5717) @@ -686,8 +686,8 @@ test_that("tests for the Pascal VOC detection dataset for train split for year 2 test_that("tests for the Pascal VOC detection dataset for trainval split for year 2012", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2012', split = 'trainval', download = TRUE) expect_length(pascal, 11540) @@ -706,8 +706,8 @@ test_that("tests for the Pascal VOC detection dataset for trainval split for yea test_that("tests for the Pascal VOC detection dataset for val split for year 2012", { -# skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, -# "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_detection_dataset(root = t, year = '2012', split = 'val', download = TRUE) expect_length(pascal, 5823) From 0d87530202003c0020a79de62847f40b9e719e3a Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Fri, 1 Aug 2025 18:28:31 +0530 Subject: [PATCH 14/29] Updating documentation for Pascal VOC datasets #139 --- NAMESPACE | 2 + R/dataset-pascal.R | 61 +++++++++++++ man/coco_detection_dataset.Rd | 4 + man/lfw_dataset.Rd | 1 + man/oxfordiiitpet_segmentation_dataset.Rd | 4 + man/pascal_voc_datasets.Rd | 106 ++++++++++++++++++++++ man/places365_dataset.Rd | 1 + 7 files changed, 179 insertions(+) create mode 100644 man/pascal_voc_datasets.Rd diff --git a/NAMESPACE b/NAMESPACE index 195bee0b..8ffbd1db 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -138,6 +138,8 @@ export(nms) export(oxfordiiitpet_binary_dataset) export(oxfordiiitpet_dataset) export(oxfordiiitpet_segmentation_dataset) +export(pascal_detection_dataset) +export(pascal_segmentation_dataset) export(places365_dataset) export(places365_dataset_large) export(qmnist_dataset) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index b862518c..483e6a47 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -1,3 +1,51 @@ +#' Pascal VOC Segmentation Dataset +#' +#' The Pascal Visual Object Classes (VOC) dataset is a benchmark in object recognition and segmentation tasks. +#' This dataset provides images with per-pixel class segmentation masks for 20 object categories across different years (2007–2012). +#' +#' @inheritParams oxfordiiitpet_dataset +#' @param root Character. Root directory where the dataset will be stored under `root/pascal_voc_`. +#' @param year Character. VOC dataset version to use. One of `"2007"`, `"2008"`, `"2009"`, `"2010"`, `"2011"`, or `"2012"`. Default is `"2012"`. +#' @param split Character. One of `"train"`, `"val"`, `"trainval"`, or `"test"`. Determines the dataset split. Default is `"train"`. +#' +#' @return A torch dataset of class \code{pascal_segmentation_dataset}. +#' Each element is a named list: +#' - `x`: a H x W x 3 array representing the RGB image. +#' - `y`: a list with one item: +#' - `masks`: a torch boolean tensor of shape (3, H, W) representing the segmentation mask. +#' +#' @examples +#' \dontrun{ +#' # Load Pascal VOC segmentation dataset (2012 train split) +#' pascal_seg <- pascal_segmentation_dataset(transform = transform_to_tensor, download = TRUE) +#' +#' # Access the first image and its mask +#' first_item <- pascal_seg[1] +#' first_item$x # Image +#' first_item$y$masks # Segmentation mask +#' +#' # Visualise the first image and its mask +#' masked_img <- draw_segmentation_masks(first_item) +#' tensor_image_browse(masked_img) +#' +#' # Load Pascal VOC detection dataset (2012 train split) +#' pascal_det <- pascal_detection_dataset(transform = transform_to_tensor, download = TRUE) +#' +#' # Access the first image and its bounding boxes +#' first_item <- pascal_det[1] +#' first_item$x # Image +#' first_item$y$labels # Object labels +#' first_item$y$boxes # Bounding box tensor +#' +#' # Visualise the first image with bounding boxes +#' boxed_img <- draw_bounding_boxes(first_item) +#' tensor_image_browse(boxed_img) +#' } +#' +#' @name pascal_voc_datasets +#' @title Pascal VOC Datasets +#' @rdname pascal_voc_datasets +#' @family segmentation_dataset #' @export pascal_segmentation_dataset <- torch::dataset( name = "pascal_segmentation_dataset", @@ -152,6 +200,19 @@ pascal_segmentation_dataset <- torch::dataset( ) ) +#' Pascal VOC Detection Dataset +#' +#' @inheritParams pascal_segmentation_dataset +#' +#' @return A torch dataset of class \code{pascal_detection_dataset}. +#' Each element is a named list: +#' - `x`: a H x W x 3 array representing the RGB image. +#' - `y`: a list with: +#' - `labels`: a character vector with object class names. +#' - `boxes`: a tensor of shape (N, 4) with bounding box coordinates in `(xmin, ymin, xmax, ymax)` format. +#' +#' @rdname pascal_voc_datasets +#' @family detection_dataset #' @export pascal_detection_dataset <- torch::dataset( name = "pascal_detection_dataset", diff --git a/man/coco_detection_dataset.Rd b/man/coco_detection_dataset.Rd index 655df381..09daeece 100644 --- a/man/coco_detection_dataset.Rd +++ b/man/coco_detection_dataset.Rd @@ -68,4 +68,8 @@ masked <- draw_segmentation_masks(item) tensor_image_browse(masked) } } +\seealso{ +Other detection_dataset: +\code{\link{pascal_voc_datasets}} +} \concept{detection_dataset} diff --git a/man/lfw_dataset.Rd b/man/lfw_dataset.Rd index 6eda972f..8e6a9b1f 100644 --- a/man/lfw_dataset.Rd +++ b/man/lfw_dataset.Rd @@ -120,6 +120,7 @@ Other classification_dataset: \code{\link{flowers102_dataset}()}, \code{\link{mnist_dataset}()}, \code{\link{oxfordiiitpet_dataset}()}, +\code{\link{places365_dataset}()}, \code{\link{tiny_imagenet_dataset}()} } \concept{classification_dataset} diff --git a/man/oxfordiiitpet_segmentation_dataset.Rd b/man/oxfordiiitpet_segmentation_dataset.Rd index 69a3c364..e6de3a8f 100644 --- a/man/oxfordiiitpet_segmentation_dataset.Rd +++ b/man/oxfordiiitpet_segmentation_dataset.Rd @@ -64,5 +64,9 @@ overlay <- draw_segmentation_masks(first_item) tensor_image_browse(overlay) } +} +\seealso{ +Other segmentation_dataset: +\code{\link{pascal_voc_datasets}} } \concept{segmentation_dataset} diff --git a/man/pascal_voc_datasets.Rd b/man/pascal_voc_datasets.Rd new file mode 100644 index 00000000..4547c6b0 --- /dev/null +++ b/man/pascal_voc_datasets.Rd @@ -0,0 +1,106 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dataset-pascal.R +\name{pascal_voc_datasets} +\alias{pascal_voc_datasets} +\alias{pascal_segmentation_dataset} +\alias{pascal_detection_dataset} +\title{Pascal VOC Datasets} +\usage{ +pascal_segmentation_dataset( + root = tempdir(), + year = "2012", + split = "train", + transform = NULL, + target_transform = NULL, + download = FALSE +) + +pascal_detection_dataset( + root = tempdir(), + year = "2012", + split = "train", + transform = NULL, + target_transform = NULL, + download = FALSE +) +} +\arguments{ +\item{root}{Character. Root directory where the dataset will be stored under \verb{root/pascal_voc_}.} + +\item{year}{Character. VOC dataset version to use. One of \code{"2007"}, \code{"2008"}, \code{"2009"}, \code{"2010"}, \code{"2011"}, or \code{"2012"}. Default is \code{"2012"}.} + +\item{split}{Character. One of \code{"train"}, \code{"val"}, \code{"trainval"}, or \code{"test"}. Determines the dataset split. Default is \code{"train"}.} + +\item{transform}{Optional. A function that takes an image and returns a transformed version (e.g., normalization, cropping).} + +\item{target_transform}{Optional. A function that transforms the label.} + +\item{download}{Logical. If TRUE, downloads the dataset to \verb{root/}. If the dataset is already present, download is skipped.} +} +\value{ +A torch dataset of class \code{pascal_segmentation_dataset}. +Each element is a named list: +\itemize{ +\item \code{x}: a H x W x 3 array representing the RGB image. +\item \code{y}: a list with one item: +\itemize{ +\item \code{masks}: a torch boolean tensor of shape (3, H, W) representing the segmentation mask. +} +} + +A torch dataset of class \code{pascal_detection_dataset}. +Each element is a named list: +\itemize{ +\item \code{x}: a H x W x 3 array representing the RGB image. +\item \code{y}: a list with: +\itemize{ +\item \code{labels}: a character vector with object class names. +\item \code{boxes}: a tensor of shape (N, 4) with bounding box coordinates in \verb{(xmin, ymin, xmax, ymax)} format. +} +} +} +\description{ +Pascal VOC Segmentation Dataset +} +\details{ +The Pascal Visual Object Classes (VOC) dataset is a benchmark in object recognition and segmentation tasks. +This dataset provides images with per-pixel class segmentation masks for 20 object categories across different years (2007–2012). +} +\examples{ +\dontrun{ +# Load Pascal VOC segmentation dataset (2012 train split) +pascal_seg <- pascal_segmentation_dataset(transform = transform_to_tensor, download = TRUE) + +# Access the first image and its mask +first_item <- pascal_seg[1] +first_item$x # Image +first_item$y$masks # Segmentation mask + +# Visualise the first image and its mask +masked_img <- draw_segmentation_masks(first_item) +tensor_image_browse(masked_img) + +# Load Pascal VOC detection dataset (2012 train split) +pascal_det <- pascal_detection_dataset(transform = transform_to_tensor, download = TRUE) + +# Access the first image and its bounding boxes +first_item <- pascal_det[1] +first_item$x # Image +first_item$y$labels # Object labels +first_item$y$boxes # Bounding box tensor + +# Visualise the first image with bounding boxes +boxed_img <- draw_bounding_boxes(first_item) +tensor_image_browse(boxed_img) +} + +} +\seealso{ +Other segmentation_dataset: +\code{\link{oxfordiiitpet_segmentation_dataset}()} + +Other detection_dataset: +\code{\link{coco_detection_dataset}()} +} +\concept{detection_dataset} +\concept{segmentation_dataset} diff --git a/man/places365_dataset.Rd b/man/places365_dataset.Rd index 6f3728d0..d3e26fc6 100644 --- a/man/places365_dataset.Rd +++ b/man/places365_dataset.Rd @@ -105,6 +105,7 @@ Other classification_dataset: \code{\link{fer_dataset}()}, \code{\link{fgvc_aircraft_dataset}()}, \code{\link{flowers102_dataset}()}, +\code{\link{lfw_dataset}}, \code{\link{mnist_dataset}()}, \code{\link{oxfordiiitpet_dataset}()}, \code{\link{tiny_imagenet_dataset}()} From 3d685c1e9803333dad13aa041aa075469726257f Mon Sep 17 00:00:00 2001 From: Derrick Richard <137819955+DerrickUnleashed@users.noreply.github.com> Date: Sat, 2 Aug 2025 10:41:49 +0530 Subject: [PATCH 15/29] Update NEWS.md Co-authored-by: cregouby --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index b45dd649..fa39eac1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ * Added `lfw_people_dataset()` and `lfw_pairs_dataset()` for loading Labelled Faces in the Wild (LFW) datasets (@DerrickUnleashed, #203). * Added `places365_dataset()`for loading the Places365 dataset (@koshtiakanksha, #196). -* Added `pascal_segmentation_dataset()`, and `pascal_detection_dataset()` for loading the Pascal Visual Object Classes datasets (@DerrickUnleashed, #139). +* Added `pascal_segmentation_dataset()`, and `pascal_detection_dataset()` for loading the Pascal Visual Object Classes datasets (@DerrickUnleashed, #209). ## New models From 5b790556b0a8d57e41c49a7fc0a770a0e052a8fd Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sat, 2 Aug 2025 10:53:50 +0530 Subject: [PATCH 16/29] Smaller example in documentation #139 --- R/dataset-pascal.R | 16 ++++++++++++---- man/pascal_voc_datasets.Rd | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 483e6a47..e3936fbc 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -16,8 +16,12 @@ #' #' @examples #' \dontrun{ -#' # Load Pascal VOC segmentation dataset (2012 train split) -#' pascal_seg <- pascal_segmentation_dataset(transform = transform_to_tensor, download = TRUE) +#' # Load Pascal VOC segmentation dataset (2007 train split) +#' pascal_seg <- pascal_segmentation_dataset( +#' transform = transform_to_tensor, +#' download = TRUE, +#' year = "2007" +#' ) #' #' # Access the first image and its mask #' first_item <- pascal_seg[1] @@ -28,8 +32,12 @@ #' masked_img <- draw_segmentation_masks(first_item) #' tensor_image_browse(masked_img) #' -#' # Load Pascal VOC detection dataset (2012 train split) -#' pascal_det <- pascal_detection_dataset(transform = transform_to_tensor, download = TRUE) +#' # Load Pascal VOC detection dataset (2007 train split) +#' pascal_det <- pascal_detection_dataset( +#' transform = transform_to_tensor, +#' download = TRUE, +#' year = "2007" +#' ) #' #' # Access the first image and its bounding boxes #' first_item <- pascal_det[1] diff --git a/man/pascal_voc_datasets.Rd b/man/pascal_voc_datasets.Rd index 4547c6b0..52365bb6 100644 --- a/man/pascal_voc_datasets.Rd +++ b/man/pascal_voc_datasets.Rd @@ -68,8 +68,12 @@ This dataset provides images with per-pixel class segmentation masks for 20 obje } \examples{ \dontrun{ -# Load Pascal VOC segmentation dataset (2012 train split) -pascal_seg <- pascal_segmentation_dataset(transform = transform_to_tensor, download = TRUE) +# Load Pascal VOC segmentation dataset (2007 train split) +pascal_seg <- pascal_segmentation_dataset( + transform = transform_to_tensor, + download = TRUE, + year = "2007" +) # Access the first image and its mask first_item <- pascal_seg[1] @@ -80,8 +84,12 @@ first_item$y$masks # Segmentation mask masked_img <- draw_segmentation_masks(first_item) tensor_image_browse(masked_img) -# Load Pascal VOC detection dataset (2012 train split) -pascal_det <- pascal_detection_dataset(transform = transform_to_tensor, download = TRUE) +# Load Pascal VOC detection dataset (2007 train split) +pascal_det <- pascal_detection_dataset( + transform = transform_to_tensor, + download = TRUE, + year = "2007" +) # Access the first image and its bounding boxes first_item <- pascal_det[1] From 018ede7329fa65a8c58af368f9a5bbda112567aa Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sat, 2 Aug 2025 11:03:26 +0530 Subject: [PATCH 17/29] using better funcs from xml2 #139 --- R/dataset-pascal.R | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index e3936fbc..cd9749c7 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -294,24 +294,16 @@ pascal_detection_dataset <- torch::dataset( parse_voc_xml = function(xml) { objects <- xml2::xml_find_all(xml, ".//object") - labels <- character(length(objects)) - boxes <- vector("list", length(objects)) + labels <- xml2::xml_text(xml2::xml_find_all(objects, "name")) - for (i in seq_along(objects)) { - obj <- objects[[i]] + bboxes <- xml2::xml_find_all(objects, "bndbox") - labels[i] <- xml2::xml_text(xml2::xml_find_first(obj, "name")) + xmin <- xml2::xml_integer(xml2::xml_find_all(bboxes, "xmin")) + ymin <- xml2::xml_integer(xml2::xml_find_all(bboxes, "ymin")) + xmax <- xml2::xml_integer(xml2::xml_find_all(bboxes, "xmax")) + ymax <- xml2::xml_integer(xml2::xml_find_all(bboxes, "ymax")) - bbox <- xml2::xml_find_first(obj, "bndbox") - xmin <- as.integer(xml2::xml_text(xml2::xml_find_first(bbox, "xmin"))) - ymin <- as.integer(xml2::xml_text(xml2::xml_find_first(bbox, "ymin"))) - xmax <- as.integer(xml2::xml_text(xml2::xml_find_first(bbox, "xmax"))) - ymax <- as.integer(xml2::xml_text(xml2::xml_find_first(bbox, "ymax"))) - - boxes[[i]] <- c(xmin, ymin, xmax, ymax) - } - - boxes <- torch_tensor(do.call(rbind, boxes), dtype = torch_int64()) + boxes <- torch_tensor(data.frame(xmin, ymin, xmax, ymax) %>% as.matrix(), dtype = torch_int64()) list( labels = labels, From 4f5713f891f3e24e8424b9a5dbaaaf2195ca0cd2 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sat, 2 Aug 2025 11:52:10 +0530 Subject: [PATCH 18/29] Including all 21 classes in pascal seg dataset #139 --- R/dataset-pascal.R | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index cd9749c7..baa4fb0f 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -27,6 +27,8 @@ #' first_item <- pascal_seg[1] #' first_item$x # Image #' first_item$y$masks # Segmentation mask +#' first_item$y$labels # Unique class labels in the mask +#' pascal_seg$classes[first_item$y$labels] # Class names #' #' # Visualise the first image and its mask #' masked_img <- draw_segmentation_masks(first_item) @@ -79,7 +81,12 @@ pascal_segmentation_dataset <- torch::dataset( trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_11-May-2012.tar",md5 = "6cd6e144f989b92b3379bac3b3de84fd") ) ), - + classes = c( + "background", "aeroplane", "bicycle", "bird", "boat", "bottle", + "bus", "car", "cat", "chair", "cow", "diningtable", "dog", + "horse", "motorbike", "person", "pottedplant", "sheep", + "sofa", "train", "tvmonitor" + ), archive_size_table = list( "2007" = list(trainval = "440 MB", test = "440 MB"), "2008" = list(trainval = "550 MB"), @@ -123,7 +130,7 @@ pascal_segmentation_dataset <- torch::dataset( self$img_path <- data$img_path self$mask_paths <- data$mask_paths - cli_inform("{.cls {class(self)[[1]]}} dataset loaded with {length(self$img_path)} images.") + cli_inform("{.cls {class(self)[[1]]}} dataset loaded with {length(self$img_path)} images across {length(self$classes)} classes.") }, download = function() { @@ -173,14 +180,38 @@ pascal_segmentation_dataset <- torch::dataset( }, .getitem = function(index) { + voc_colormap <- list( + c(0, 0, 0), c(128, 0, 0), c(0, 128, 0), c(128, 128, 0), + c(0, 0, 128), c(128, 0, 128), c(0, 128, 128), c(128, 128, 128), + c(64, 0, 0), c(192, 0, 0), c(64, 128, 0), c(192, 128, 0), + c(64, 0, 128), c(192, 0, 128), c(64, 128, 128), c(192, 128, 128), + c(0, 64, 0), c(128, 64, 0), c(0, 192, 0), c(128, 192, 0), + c(0, 64, 128) + ) img_path <- self$img_path[index] mask_path <- self$mask_paths[index] x <- jpeg::readJPEG(img_path) - masks <- png::readPNG(mask_path)*255 - masks <- torch_tensor(masks, dtype = torch_bool())$permute(c(3, 1, 2)) + mask_data <- png::readPNG(mask_path) + mask_data <- mask_data * 255 + flat_mask <- matrix( + c(as.vector(mask_data[, , 1]), + as.vector(mask_data[, , 2]), + as.vector(mask_data[, , 3])), + ncol = 3 + ) + colormap_mat <- do.call(rbind, voc_colormap) + match_indices <- apply(flat_mask, 1, function(px) { + matched <- which(colSums(abs(t(colormap_mat) - px)) == 0) + if (length(matched) > 0) matched[1] - 1 else NA_integer_ + }) + class_idx <- matrix(match_indices, nrow = dim(mask_data)[1], ncol = dim(mask_data)[2]) + masks <- torch_tensor(class_idx, dtype = torch_long())$unsqueeze(1) + labels <- sort(unique(as.vector(as_array(masks)))+1) + masks <- masks$to(dtype = torch_bool()) y <- list( + labels = labels, masks = masks ) @@ -272,7 +303,7 @@ pascal_detection_dataset <- torch::dataset( install.packages("xml2") } - cli_inform("{.cls {class(self)[[1]]}} dataset loaded with {length(self$img_path)} images.") + cli_inform("{.cls {class(self)[[1]]}} dataset loaded with {length(self$img_path)} images across {length(self$classes)} classes.") }, .getitem = function(index) { From 2ef99f5c45cb5386e83b6df6ad68be486eb527ca Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sat, 2 Aug 2025 11:54:58 +0530 Subject: [PATCH 19/29] Updating Documentation --- man/pascal_voc_datasets.Rd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/man/pascal_voc_datasets.Rd b/man/pascal_voc_datasets.Rd index 52365bb6..e9dd8636 100644 --- a/man/pascal_voc_datasets.Rd +++ b/man/pascal_voc_datasets.Rd @@ -79,6 +79,8 @@ pascal_seg <- pascal_segmentation_dataset( first_item <- pascal_seg[1] first_item$x # Image first_item$y$masks # Segmentation mask +first_item$y$labels # Unique class labels in the mask +pascal_seg$classes[first_item$y$labels] # Class names # Visualise the first image and its mask masked_img <- draw_segmentation_masks(first_item) From ebaee3086d70339f71f260364ccc18b8c95eb6ad Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sat, 2 Aug 2025 12:33:06 +0530 Subject: [PATCH 20/29] Testing pascal_seg on CI #139 --- tests/testthat/test-dataset-pascal.R | 171 ++++++++++++++++++--------- 1 file changed, 114 insertions(+), 57 deletions(-) diff --git a/tests/testthat/test-dataset-pascal.R b/tests/testthat/test-dataset-pascal.R index 5f8b13d8..75e06f62 100644 --- a/tests/testthat/test-dataset-pascal.R +++ b/tests/testthat/test-dataset-pascal.R @@ -4,8 +4,8 @@ t = withr::local_tempdir() test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2007", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'train', download = TRUE) expect_length(pascal, 209) @@ -15,15 +15,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_shape(first_item$y$mask,c(1,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 3) + expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for test split for year 2007", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'test', download = TRUE) expect_length(pascal, 210) @@ -33,15 +36,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for test split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,375,500)) + expect_tensor_shape(first_item$y$mask,c(1,375,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 2) + expect_equal(first_item$y$labels, c(1, 4)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2007", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'trainval', download = TRUE) expect_length(pascal, 422) @@ -51,15 +57,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_shape(first_item$y$mask,c(1,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 3) + expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2007", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'val', download = TRUE) expect_length(pascal, 213) @@ -69,15 +78,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,375,500)) + expect_tensor_shape(first_item$y$mask,c(1,375,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 2) + expect_equal(first_item$y$labels, c(1, 21)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2008", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2008', split = 'train', download = TRUE) expect_length(pascal, 511) @@ -87,15 +99,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_shape(first_item$y$mask,c(1,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 3) + expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2008", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2008', split = 'trainval', download = TRUE) expect_length(pascal, 1023) @@ -105,15 +120,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_shape(first_item$y$mask,c(1,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 3) + expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2008", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2008', split = 'val', download = TRUE) expect_length(pascal, 512) @@ -123,15 +141,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,366,500)) + expect_tensor_shape(first_item$y$mask,c(1,366,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 2) + expect_equal(first_item$y$labels, c(1, 2)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2009", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2009', split = 'train', download = TRUE) expect_length(pascal, 749) @@ -141,15 +162,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_shape(first_item$y$mask,c(1,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 3) + expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2009", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2009', split = 'trainval', download = TRUE) expect_length(pascal, 1499) @@ -159,15 +183,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_shape(first_item$y$mask,c(1,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 3) + expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2009", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2009', split = 'val', download = TRUE) expect_length(pascal, 750) @@ -177,15 +204,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,366,500)) + expect_tensor_shape(first_item$y$mask,c(1,366,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 2) + expect_equal(first_item$y$labels, c(1, 2)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2010", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2010', split = 'train', download = TRUE) expect_length(pascal, 964) @@ -195,15 +225,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_shape(first_item$y$mask,c(1,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 3) + expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2010", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2010', split = 'trainval', download = TRUE) expect_length(pascal, 1928) @@ -213,15 +246,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_shape(first_item$y$mask,c(1,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 3) + expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2010", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2010', split = 'val', download = TRUE) expect_length(pascal, 964) @@ -231,15 +267,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,366,500)) + expect_tensor_shape(first_item$y$mask,c(1,366,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 2) + expect_equal(first_item$y$labels, c(1, 2)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2011", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2011', split = 'train', download = TRUE) expect_length(pascal, 1112) @@ -249,15 +288,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_shape(first_item$y$mask,c(1,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 3) + expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2011", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2011', split = 'trainval', download = TRUE) expect_length(pascal, 2223) @@ -267,15 +309,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_shape(first_item$y$mask,c(1,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 3) + expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2011", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2011', split = 'val', download = TRUE) expect_length(pascal, 1111) @@ -285,15 +330,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,366,500)) + expect_tensor_shape(first_item$y$mask,c(1,366,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 2) + expect_equal(first_item$y$labels, c(1, 2)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2012", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2012', split = 'train', download = TRUE) expect_length(pascal, 1464) @@ -303,15 +351,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_shape(first_item$y$mask,c(1,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 3) + expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2012", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2012', split = 'trainval', download = TRUE) expect_length(pascal, 2913) @@ -321,15 +372,18 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,281,500)) + expect_tensor_shape(first_item$y$mask,c(1,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 3) + expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") }) test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2012", { - skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2012', split = 'val', download = TRUE) expect_length(pascal, 1449) @@ -339,8 +393,11 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(3,366,500)) + expect_tensor_shape(first_item$y$mask,c(1,366,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) + expect_type(first_item$y$labels, "double") + expect_length(first_item$y$labels, 2) + expect_equal(first_item$y$labels, c(1, 2)) expect_s3_class(first_item, "image_with_segmentation_mask") }) From abfab0a6f1fbfff97c76c0b91cf6f20051a4e714 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sat, 2 Aug 2025 12:44:02 +0530 Subject: [PATCH 21/29] Removing skips as tests are successful on CI --- tests/testthat/test-dataset-pascal.R | 76 ++++++++++++++-------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/testthat/test-dataset-pascal.R b/tests/testthat/test-dataset-pascal.R index 75e06f62..1705199c 100644 --- a/tests/testthat/test-dataset-pascal.R +++ b/tests/testthat/test-dataset-pascal.R @@ -4,8 +4,8 @@ t = withr::local_tempdir() test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2007", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'train', download = TRUE) expect_length(pascal, 209) @@ -25,8 +25,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea test_that("tests for the Pascal VOC Segmentation dataset for test split for year 2007", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'test', download = TRUE) expect_length(pascal, 210) @@ -46,8 +46,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for test split for year test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2007", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'trainval', download = TRUE) expect_length(pascal, 422) @@ -67,8 +67,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2007", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'val', download = TRUE) expect_length(pascal, 213) @@ -88,8 +88,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2008", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2008', split = 'train', download = TRUE) expect_length(pascal, 511) @@ -109,8 +109,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2008", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2008', split = 'trainval', download = TRUE) expect_length(pascal, 1023) @@ -130,8 +130,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2008", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2008', split = 'val', download = TRUE) expect_length(pascal, 512) @@ -151,8 +151,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2009", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2009', split = 'train', download = TRUE) expect_length(pascal, 749) @@ -172,8 +172,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2009", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2009', split = 'trainval', download = TRUE) expect_length(pascal, 1499) @@ -193,8 +193,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2009", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2009', split = 'val', download = TRUE) expect_length(pascal, 750) @@ -214,8 +214,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2010", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2010', split = 'train', download = TRUE) expect_length(pascal, 964) @@ -235,8 +235,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2010", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2010', split = 'trainval', download = TRUE) expect_length(pascal, 1928) @@ -256,8 +256,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2010", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2010', split = 'val', download = TRUE) expect_length(pascal, 964) @@ -277,8 +277,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2011", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2011', split = 'train', download = TRUE) expect_length(pascal, 1112) @@ -298,8 +298,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2011", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2011', split = 'trainval', download = TRUE) expect_length(pascal, 2223) @@ -319,8 +319,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2011", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2011', split = 'val', download = TRUE) expect_length(pascal, 1111) @@ -340,8 +340,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year test_that("tests for the Pascal VOC Segmentation dataset for train split for year 2012", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2012', split = 'train', download = TRUE) expect_length(pascal, 1464) @@ -361,8 +361,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2012", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2012', split = 'trainval', download = TRUE) expect_length(pascal, 2913) @@ -382,8 +382,8 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2012", { - # skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, - # "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, + "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") pascal <- pascal_segmentation_dataset(root = t, year = '2012', split = 'val', download = TRUE) expect_length(pascal, 1449) From 4d32f96f903886be9ebed9b8b78566964e7b3164 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sun, 3 Aug 2025 00:06:48 +0530 Subject: [PATCH 22/29] Using array instead of list #139 --- R/dataset-pascal.R | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index baa4fb0f..50267d85 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -87,6 +87,14 @@ pascal_segmentation_dataset <- torch::dataset( "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor" ), + voc_colormap = c( + c(0, 0, 0), c(128, 0, 0), c(0, 128, 0), c(128, 128, 0), + c(0, 0, 128), c(128, 0, 128), c(0, 128, 128), c(128, 128, 128), + c(64, 0, 0), c(192, 0, 0), c(64, 128, 0), c(192, 128, 0), + c(64, 0, 128), c(192, 0, 128), c(64, 128, 128), c(192, 128, 128), + c(0, 64, 0), c(128, 64, 0), c(0, 192, 0), c(128, 192, 0), + c(0, 64, 128) + ), archive_size_table = list( "2007" = list(trainval = "440 MB", test = "440 MB"), "2008" = list(trainval = "550 MB"), @@ -180,34 +188,27 @@ pascal_segmentation_dataset <- torch::dataset( }, .getitem = function(index) { - voc_colormap <- list( - c(0, 0, 0), c(128, 0, 0), c(0, 128, 0), c(128, 128, 0), - c(0, 0, 128), c(128, 0, 128), c(0, 128, 128), c(128, 128, 128), - c(64, 0, 0), c(192, 0, 0), c(64, 128, 0), c(192, 128, 0), - c(64, 0, 128), c(192, 0, 128), c(64, 128, 128), c(192, 128, 128), - c(0, 64, 0), c(128, 64, 0), c(0, 192, 0), c(128, 192, 0), - c(0, 64, 128) - ) + img_path <- self$img_path[index] mask_path <- self$mask_paths[index] x <- jpeg::readJPEG(img_path) - mask_data <- png::readPNG(mask_path) - mask_data <- mask_data * 255 + mask_data <- png::readPNG(mask_path) * 255 + flat_mask <- matrix( c(as.vector(mask_data[, , 1]), as.vector(mask_data[, , 2]), as.vector(mask_data[, , 3])), ncol = 3 ) - colormap_mat <- do.call(rbind, voc_colormap) - match_indices <- apply(flat_mask, 1, function(px) { - matched <- which(colSums(abs(t(colormap_mat) - px)) == 0) - if (length(matched) > 0) matched[1] - 1 else NA_integer_ - }) + colormap_mat <- matrix(self$voc_colormap, ncol = 3, byrow = TRUE) + rgb_to_int <- function(mat) { + as.integer(mat[, 1]) * 256^2 + as.integer(mat[, 2]) * 256 + as.integer(mat[, 3]) + } + match_indices <- match(rgb_to_int(flat_mask), rgb_to_int(colormap_mat)) - 1 class_idx <- matrix(match_indices, nrow = dim(mask_data)[1], ncol = dim(mask_data)[2]) masks <- torch_tensor(class_idx, dtype = torch_long())$unsqueeze(1) - labels <- sort(unique(as.vector(as_array(masks)))+1) + labels <- sort(unique(as.vector(as_array(masks))) + 1) masks <- masks$to(dtype = torch_bool()) y <- list( From 18b7b1c57272b0365e95f2153d673ecd249e55b5 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sun, 3 Aug 2025 00:32:29 +0530 Subject: [PATCH 23/29] Changing masks to 21,H,W #139 --- R/dataset-pascal.R | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 50267d85..909e0ae5 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -207,14 +207,14 @@ pascal_segmentation_dataset <- torch::dataset( } match_indices <- match(rgb_to_int(flat_mask), rgb_to_int(colormap_mat)) - 1 class_idx <- matrix(match_indices, nrow = dim(mask_data)[1], ncol = dim(mask_data)[2]) - masks <- torch_tensor(class_idx, dtype = torch_long())$unsqueeze(1) - labels <- sort(unique(as.vector(as_array(masks))) + 1) - masks <- masks$to(dtype = torch_bool()) + class_idx_tensor <- torch_tensor(class_idx, dtype = torch_long()) + masks <- torch_zeros(21, dim(class_idx_tensor)[1], dim(class_idx_tensor)[2], dtype = torch_bool()) + for (i in 0:20) { + masks[i + 1][class_idx_tensor == i] <- TRUE + } + labels <- which(as_array(masks$any(dim = c(2, 3)))) - y <- list( - labels = labels, - masks = masks - ) + y <- list(labels = labels, masks = masks) if (!is.null(self$transform)) { x <- self$transform(x) From a62ae72d498ffb35bed3951750efd175d5cf4309 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sun, 3 Aug 2025 00:42:58 +0530 Subject: [PATCH 24/29] Refactor: Vectorizing #139 --- R/dataset-pascal.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 909e0ae5..aa198274 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -208,10 +208,8 @@ pascal_segmentation_dataset <- torch::dataset( match_indices <- match(rgb_to_int(flat_mask), rgb_to_int(colormap_mat)) - 1 class_idx <- matrix(match_indices, nrow = dim(mask_data)[1], ncol = dim(mask_data)[2]) class_idx_tensor <- torch_tensor(class_idx, dtype = torch_long()) - masks <- torch_zeros(21, dim(class_idx_tensor)[1], dim(class_idx_tensor)[2], dtype = torch_bool()) - for (i in 0:20) { - masks[i + 1][class_idx_tensor == i] <- TRUE - } + class_ids <- torch_arange(0, 20, dtype = torch_long())$view(c(21, 1, 1)) + masks <- (class_ids == class_idx_tensor$unsqueeze(1))$to(dtype = torch_bool()) labels <- which(as_array(masks$any(dim = c(2, 3)))) y <- list(labels = labels, masks = masks) From cb76c0fe73e2f384e93e29cb3a578016be92feb2 Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sun, 3 Aug 2025 00:54:11 +0530 Subject: [PATCH 25/29] Updating tests #139 --- tests/testthat/test-dataset-pascal.R | 76 ++++++++++++++-------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/testthat/test-dataset-pascal.R b/tests/testthat/test-dataset-pascal.R index 1705199c..dd36e32f 100644 --- a/tests/testthat/test-dataset-pascal.R +++ b/tests/testthat/test-dataset-pascal.R @@ -15,9 +15,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,281,500)) + expect_tensor_shape(first_item$y$mask,c(21,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 3) expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -36,9 +36,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for test split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,375,500)) + expect_tensor_shape(first_item$y$mask,c(21,375,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 2) expect_equal(first_item$y$labels, c(1, 4)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -57,9 +57,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,281,500)) + expect_tensor_shape(first_item$y$mask,c(21,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 3) expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -78,9 +78,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,375,500)) + expect_tensor_shape(first_item$y$mask,c(21,375,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 2) expect_equal(first_item$y$labels, c(1, 21)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -99,9 +99,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,281,500)) + expect_tensor_shape(first_item$y$mask,c(21,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 3) expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -120,9 +120,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,281,500)) + expect_tensor_shape(first_item$y$mask,c(21,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 3) expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -141,9 +141,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,366,500)) + expect_tensor_shape(first_item$y$mask,c(21,366,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 2) expect_equal(first_item$y$labels, c(1, 2)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -162,9 +162,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,281,500)) + expect_tensor_shape(first_item$y$mask,c(21,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 3) expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -183,9 +183,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,281,500)) + expect_tensor_shape(first_item$y$mask,c(21,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 3) expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -204,9 +204,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,366,500)) + expect_tensor_shape(first_item$y$mask,c(21,366,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 2) expect_equal(first_item$y$labels, c(1, 2)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -225,9 +225,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,281,500)) + expect_tensor_shape(first_item$y$mask,c(21,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 3) expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -246,9 +246,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,281,500)) + expect_tensor_shape(first_item$y$mask,c(21,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 3) expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -267,9 +267,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,366,500)) + expect_tensor_shape(first_item$y$mask,c(21,366,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 2) expect_equal(first_item$y$labels, c(1, 2)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -288,9 +288,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,281,500)) + expect_tensor_shape(first_item$y$mask,c(21,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 3) expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -309,9 +309,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,281,500)) + expect_tensor_shape(first_item$y$mask,c(21,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 3) expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -330,9 +330,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,366,500)) + expect_tensor_shape(first_item$y$mask,c(21,366,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 2) expect_equal(first_item$y$labels, c(1, 2)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -351,9 +351,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,281,500)) + expect_tensor_shape(first_item$y$mask,c(21,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 3) expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -372,9 +372,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,281,500)) + expect_tensor_shape(first_item$y$mask,c(21,281,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 3) expect_equal(first_item$y$labels, c(1, 2, 16)) expect_s3_class(first_item, "image_with_segmentation_mask") @@ -393,9 +393,9 @@ test_that("tests for the Pascal VOC Segmentation dataset for val split for year expect_type(first_item$x, "double") expect_type(first_item$y, "list") expect_tensor(first_item$y$mask) - expect_tensor_shape(first_item$y$mask,c(1,366,500)) + expect_tensor_shape(first_item$y$mask,c(21,366,500)) expect_tensor_dtype(first_item$y$mask,torch_bool()) - expect_type(first_item$y$labels, "double") + expect_type(first_item$y$labels, "integer") expect_length(first_item$y$labels, 2) expect_equal(first_item$y$labels, c(1, 2)) expect_s3_class(first_item, "image_with_segmentation_mask") From fde1d66697b4d08c76df6d748d7b669cf3680ecf Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sun, 3 Aug 2025 11:24:47 +0530 Subject: [PATCH 26/29] Making classes consistent #139 --- R/dataset-pascal.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index aa198274..fbb7ea7f 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -83,9 +83,9 @@ pascal_segmentation_dataset <- torch::dataset( ), classes = c( "background", "aeroplane", "bicycle", "bird", "boat", "bottle", - "bus", "car", "cat", "chair", "cow", "diningtable", "dog", - "horse", "motorbike", "person", "pottedplant", "sheep", - "sofa", "train", "tvmonitor" + "bus", "car", "cat", "chair", "cow", "dining table", "dog", + "horse", "motorbike", "person", "potted plant", "sheep", + "sofa", "train", "tv" ), voc_colormap = c( c(0, 0, 0), c(128, 0, 0), c(0, 128, 0), c(128, 128, 0), From 22b625c71f0fa1c06c6e4ca740ce44270185906f Mon Sep 17 00:00:00 2001 From: DerrickUnleashed Date: Sun, 3 Aug 2025 11:43:16 +0530 Subject: [PATCH 27/29] Updating documentation --- R/dataset-pascal.R | 30 +++++++++++++++++++++++++----- man/pascal_voc_datasets.Rd | 30 +++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index fbb7ea7f..04183110 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -1,7 +1,17 @@ #' Pascal VOC Segmentation Dataset #' -#' The Pascal Visual Object Classes (VOC) dataset is a benchmark in object recognition and segmentation tasks. -#' This dataset provides images with per-pixel class segmentation masks for 20 object categories across different years (2007–2012). +#' The Pascal Visual Object Classes (VOC) dataset is a widely used benchmark for object detection and semantic segmentation tasks in computer vision. +#' +#' This dataset provides RGB images along with per-pixel class segmentation masks for 20 object categories, plus a background class. +#' Each pixel in the mask is labeled with a class index corresponding to one of the predefined semantic categories. +#' +#' The VOC dataset was released in yearly editions (2007 to 2012), with slight variations in data splits and annotation formats. +#' Notably, only the 2007 edition includes a separate `test` split; all other years (2008–2012) provide only the `train`, `val`, and `trainval` splits. +#' +#' The dataset defines 21 semantic classes: `"background"`, `"aeroplane"`, `"bicycle"`, `"bird"`, `"boat"`, `"bottle"`, `"bus"`, `"car"`, `"cat"`, `"chair"`, +#' `"cow"`, `"dining table"`, `"dog"`, `"horse"`, `"motorbike"`, `"person"`, `"potted plant"`, `"sheep"`, `"sofa"`, `"train"`, and `"tv"`. +#' +#' This dataset is frequently used for training and evaluating semantic segmentation models, and supports tasks requiring dense, per-pixel annotations. #' #' @inheritParams oxfordiiitpet_dataset #' @param root Character. Root directory where the dataset will be stored under `root/pascal_voc_`. @@ -9,10 +19,16 @@ #' @param split Character. One of `"train"`, `"val"`, `"trainval"`, or `"test"`. Determines the dataset split. Default is `"train"`. #' #' @return A torch dataset of class \code{pascal_segmentation_dataset}. -#' Each element is a named list: +#' +#' The returned list inherits class \code{image_with_segmentation_mask}, which allows generic visualization +#' utilities to be applied. +#' +#' Each element is a named list with the following structure: #' - `x`: a H x W x 3 array representing the RGB image. -#' - `y`: a list with one item: -#' - `masks`: a torch boolean tensor of shape (3, H, W) representing the segmentation mask. +#' - `y`: A named list containing: +#' - `masks`: A `torch_tensor` of dtype `bool` and shape `(21, H, W)`, representing a multi-channel segmentation mask. +#' Each of the 21 channels corresponds to a Pascal VOC classes +#' - `labels`: An integer vector indicating the indices of the classes present in the mask. #' #' @examples #' \dontrun{ @@ -243,6 +259,10 @@ pascal_segmentation_dataset <- torch::dataset( #' @inheritParams pascal_segmentation_dataset #' #' @return A torch dataset of class \code{pascal_detection_dataset}. +#' +#' The returned list inherits class \code{image_with_bounding_box}, which allows generic visualization +#' utilities to be applied. +#' #' Each element is a named list: #' - `x`: a H x W x 3 array representing the RGB image. #' - `y`: a list with: diff --git a/man/pascal_voc_datasets.Rd b/man/pascal_voc_datasets.Rd index e9dd8636..56dc1d81 100644 --- a/man/pascal_voc_datasets.Rd +++ b/man/pascal_voc_datasets.Rd @@ -39,16 +39,26 @@ pascal_detection_dataset( } \value{ A torch dataset of class \code{pascal_segmentation_dataset}. -Each element is a named list: + +The returned list inherits class \code{image_with_segmentation_mask}, which allows generic visualization +utilities to be applied. + +Each element is a named list with the following structure: \itemize{ \item \code{x}: a H x W x 3 array representing the RGB image. -\item \code{y}: a list with one item: +\item \code{y}: A named list containing: \itemize{ -\item \code{masks}: a torch boolean tensor of shape (3, H, W) representing the segmentation mask. +\item \code{masks}: A \code{torch_tensor} of dtype \code{bool} and shape \verb{(21, H, W)}, representing a multi-channel segmentation mask. +Each of the 21 channels corresponds to a Pascal VOC classes +\item \code{labels}: An integer vector indicating the indices of the classes present in the mask. } } A torch dataset of class \code{pascal_detection_dataset}. + +The returned list inherits class \code{image_with_bounding_box}, which allows generic visualization +utilities to be applied. + Each element is a named list: \itemize{ \item \code{x}: a H x W x 3 array representing the RGB image. @@ -63,8 +73,18 @@ Each element is a named list: Pascal VOC Segmentation Dataset } \details{ -The Pascal Visual Object Classes (VOC) dataset is a benchmark in object recognition and segmentation tasks. -This dataset provides images with per-pixel class segmentation masks for 20 object categories across different years (2007–2012). +The Pascal Visual Object Classes (VOC) dataset is a widely used benchmark for object detection and semantic segmentation tasks in computer vision. + +This dataset provides RGB images along with per-pixel class segmentation masks for 20 object categories, plus a background class. +Each pixel in the mask is labeled with a class index corresponding to one of the predefined semantic categories. + +The VOC dataset was released in yearly editions (2007 to 2012), with slight variations in data splits and annotation formats. +Notably, only the 2007 edition includes a separate \code{test} split; all other years (2008–2012) provide only the \code{train}, \code{val}, and \code{trainval} splits. + +The dataset defines 21 semantic classes: \code{"background"}, \code{"aeroplane"}, \code{"bicycle"}, \code{"bird"}, \code{"boat"}, \code{"bottle"}, \code{"bus"}, \code{"car"}, \code{"cat"}, \code{"chair"}, +\code{"cow"}, \code{"dining table"}, \code{"dog"}, \code{"horse"}, \code{"motorbike"}, \code{"person"}, \code{"potted plant"}, \code{"sheep"}, \code{"sofa"}, \code{"train"}, and \code{"tv"}. + +This dataset is frequently used for training and evaluating semantic segmentation models, and supports tasks requiring dense, per-pixel annotations. } \examples{ \dontrun{ From 903840e609a5a18876a30dbd55b0bf53ee5a773a Mon Sep 17 00:00:00 2001 From: "C. Regouby" Date: Fri, 8 Aug 2025 11:04:04 +0200 Subject: [PATCH 28/29] switch to common voc_segmentation_classes --- R/dataset-pascal.R | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 04183110..558323e2 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -19,10 +19,10 @@ #' @param split Character. One of `"train"`, `"val"`, `"trainval"`, or `"test"`. Determines the dataset split. Default is `"train"`. #' #' @return A torch dataset of class \code{pascal_segmentation_dataset}. -#' +#' #' The returned list inherits class \code{image_with_segmentation_mask}, which allows generic visualization #' utilities to be applied. -#' +#' #' Each element is a named list with the following structure: #' - `x`: a H x W x 3 array representing the RGB image. #' - `y`: A named list containing: @@ -97,12 +97,7 @@ pascal_segmentation_dataset <- torch::dataset( trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_11-May-2012.tar",md5 = "6cd6e144f989b92b3379bac3b3de84fd") ) ), - classes = c( - "background", "aeroplane", "bicycle", "bird", "boat", "bottle", - "bus", "car", "cat", "chair", "cow", "dining table", "dog", - "horse", "motorbike", "person", "potted plant", "sheep", - "sofa", "train", "tv" - ), + classes = voc_segmentation_classes, voc_colormap = c( c(0, 0, 0), c(128, 0, 0), c(0, 128, 0), c(128, 128, 0), c(0, 0, 128), c(128, 0, 128), c(0, 128, 128), c(128, 128, 128), @@ -259,10 +254,10 @@ pascal_segmentation_dataset <- torch::dataset( #' @inheritParams pascal_segmentation_dataset #' #' @return A torch dataset of class \code{pascal_detection_dataset}. -#' +#' #' The returned list inherits class \code{image_with_bounding_box}, which allows generic visualization #' utilities to be applied. -#' +#' #' Each element is a named list: #' - `x`: a H x W x 3 array representing the RGB image. #' - `y`: a list with: @@ -360,4 +355,4 @@ pascal_detection_dataset <- torch::dataset( boxes = boxes ) } -) \ No newline at end of file +) From 0992bf8b90293cef8ee7a8e45e7e8e84e329a8b5 Mon Sep 17 00:00:00 2001 From: "C. Regouby" Date: Fri, 8 Aug 2025 12:16:39 +0200 Subject: [PATCH 29/29] switch to dataframe for resources and review classes --- R/dataset-pascal.R | 71 +++++++++++++--------------- man/pascal_voc_datasets.Rd | 3 +- tests/testthat/test-dataset-pascal.R | 26 +++++----- 3 files changed, 49 insertions(+), 51 deletions(-) diff --git a/R/dataset-pascal.R b/R/dataset-pascal.R index 558323e2..225b1ea4 100644 --- a/R/dataset-pascal.R +++ b/R/dataset-pascal.R @@ -9,7 +9,8 @@ #' Notably, only the 2007 edition includes a separate `test` split; all other years (2008–2012) provide only the `train`, `val`, and `trainval` splits. #' #' The dataset defines 21 semantic classes: `"background"`, `"aeroplane"`, `"bicycle"`, `"bird"`, `"boat"`, `"bottle"`, `"bus"`, `"car"`, `"cat"`, `"chair"`, -#' `"cow"`, `"dining table"`, `"dog"`, `"horse"`, `"motorbike"`, `"person"`, `"potted plant"`, `"sheep"`, `"sofa"`, `"train"`, and `"tv"`. +#' `"cow"`, `"dining table"`, `"dog"`, `"horse"`, `"motorbike"`, `"person"`, `"potted plant"`, `"sheep"`, `"sofa"`, `"train"`, and `"tv/monitor"`. +#' They are available through the `classes` variable of the dataset object. #' #' This dataset is frequently used for training and evaluating semantic segmentation models, and supports tasks requiring dense, per-pixel annotations. #' @@ -76,28 +77,32 @@ pascal_segmentation_dataset <- torch::dataset( name = "pascal_segmentation_dataset", - resources = list( - `2007` = list( - trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_06-Nov-2007.tar",md5 = "c52e279531787c972589f7e41ab4ae64"), - test = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtest_06-Nov-2007.tar",md5 = "b6e924de25625d8de591ea690078ad9f") - ), - `2008` = list( - trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_14-Jul-2008.tar",md5 = "2629fa636546599198acfcfbfcf1904a") - ), - `2009` = list( - trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_11-May-2009.tar",md5 = "59065e4b188729180974ef6572f6a212") - ), - `2010` = list( - trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_03-May-2010.tar",md5 = "da459979d0c395079b5c75ee67908abb") - ), - `2011` = list( - trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_25-May-2011.tar",md5 = "6c3384ef61512963050cb5d687e5bf1e") - ), - `2012` = list( - trainval = list(url = "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_11-May-2012.tar",md5 = "6cd6e144f989b92b3379bac3b3de84fd") - ) + resources = data.frame( + year = c("2007", "2007", "2008", "2009", "2010", "2011", "2012"), + type = c("trainval", "test", "trainval", "trainval", "trainval", "trainval", "trainval"), + url = c("https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_06-Nov-2007.tar", + "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtest_06-Nov-2007.tar", + "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_14-Jul-2008.tar", + "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_11-May-2009.tar", + "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_03-May-2010.tar", + "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_25-May-2011.tar", + "https://huggingface.co/datasets/JimmyUnleashed/Pascal_VOC/resolve/main/VOCtrainval_11-May-2012.tar"), + md5 = c("c52e279531787c972589f7e41ab4ae64", + "b6e924de25625d8de591ea690078ad9f", + "2629fa636546599198acfcfbfcf1904a", + "59065e4b188729180974ef6572f6a212", + "da459979d0c395079b5c75ee67908abb", + "6c3384ef61512963050cb5d687e5bf1e", + "6cd6e144f989b92b3379bac3b3de84fd"), + size = c("440 MB", "440 MB", "550 MB", "890 MB", "1.3 GB", "1.7 GB", "1.9 GB") + ), + classes = c( + "background", "aeroplane", "bicycle", "bird", "boat", + "bottle", "bus", "car", "cat", "chair", + "cow", "dining table", "dog", "horse", "motorbike", + "person", "potted plant", "sheep", "sofa", "train", + "tv/monitor" ), - classes = voc_segmentation_classes, voc_colormap = c( c(0, 0, 0), c(128, 0, 0), c(0, 128, 0), c(128, 128, 0), c(0, 0, 128), c(128, 0, 128), c(0, 128, 128), c(128, 128, 128), @@ -106,14 +111,6 @@ pascal_segmentation_dataset <- torch::dataset( c(0, 64, 0), c(128, 64, 0), c(0, 192, 0), c(128, 192, 0), c(0, 64, 128) ), - archive_size_table = list( - "2007" = list(trainval = "440 MB", test = "440 MB"), - "2008" = list(trainval = "550 MB"), - "2009" = list(trainval = "890 MB"), - "2010" = list(trainval = "1.3 GB"), - "2011" = list(trainval = "1.7 GB"), - "2012" = list(trainval = "1.9 GB") - ), initialize = function( root = tempdir(), @@ -124,8 +121,8 @@ pascal_segmentation_dataset <- torch::dataset( download = FALSE ) { self$root_path <- root - self$year <- match.arg(year, choices = names(self$resources)) - self$split <- match.arg(split, choices = c("train", "val", "trainval", "test")) + self$year <- match.arg(year, choices = unique(self$resources$year)) + self$split <- match.arg(split, choices = c("train", "val", "trainval", "test")) self$transform <- transform self$target_transform <- target_transform if (self$split == "test"){ @@ -133,7 +130,7 @@ pascal_segmentation_dataset <- torch::dataset( } else { self$archive_key <- "trainval" } - self$archive_size <- self$archive_size_table[[self$year]][[self$archive_key]] + self$archive_size <- self$resources[self$resources$year == self$year & self$resources$type == self$archive_key,]$size if (download) { cli_inform("Dataset {.cls {class(self)[[1]]}} (~{.emph {self$archive_size}}) will be downloaded and processed if not already available.") @@ -163,7 +160,7 @@ pascal_segmentation_dataset <- torch::dataset( fs::dir_create(self$raw_folder) fs::dir_create(self$processed_folder) - resource <- self$resources[[self$year]][[self$archive_key]] + resource <- self$resources[self$resources$year == self$year & self$resources$type == self$archive_key,] archive <- download_and_cache(resource$url, prefix = class(self)[1]) actual_md5 <- tools::md5sum(archive) @@ -282,7 +279,7 @@ pascal_detection_dataset <- torch::dataset( ) { self$root_path <- root - self$year <- match.arg(year, choices = names(self$resources)) + self$year <- match.arg(year, choices = unique(self$resources$year)) self$split <- match.arg(split, choices = c("train", "val", "trainval", "test")) self$transform <- transform self$target_transform <- target_transform @@ -291,7 +288,7 @@ pascal_detection_dataset <- torch::dataset( } else { self$archive_key <- "trainval" } - self$archive_size <- self$archive_size_table[[self$year]][[self$archive_key]] + self$archive_size <- self$resources[self$resources$year == self$year & self$resources$type == self$archive_key,]$size if (download) { cli_inform("Dataset {.cls {class(self)[[1]]}} (~{.emph {self$archive_size}}) will be downloaded and processed if not already available.") @@ -348,7 +345,7 @@ pascal_detection_dataset <- torch::dataset( xmax <- xml2::xml_integer(xml2::xml_find_all(bboxes, "xmax")) ymax <- xml2::xml_integer(xml2::xml_find_all(bboxes, "ymax")) - boxes <- torch_tensor(data.frame(xmin, ymin, xmax, ymax) %>% as.matrix(), dtype = torch_int64()) + boxes <- torch_tensor(data.frame(xmin, ymin, xmax, ymax) %>% as.matrix(), dtype = torch_long()) list( labels = labels, diff --git a/man/pascal_voc_datasets.Rd b/man/pascal_voc_datasets.Rd index 56dc1d81..18773c2d 100644 --- a/man/pascal_voc_datasets.Rd +++ b/man/pascal_voc_datasets.Rd @@ -82,7 +82,8 @@ The VOC dataset was released in yearly editions (2007 to 2012), with slight vari Notably, only the 2007 edition includes a separate \code{test} split; all other years (2008–2012) provide only the \code{train}, \code{val}, and \code{trainval} splits. The dataset defines 21 semantic classes: \code{"background"}, \code{"aeroplane"}, \code{"bicycle"}, \code{"bird"}, \code{"boat"}, \code{"bottle"}, \code{"bus"}, \code{"car"}, \code{"cat"}, \code{"chair"}, -\code{"cow"}, \code{"dining table"}, \code{"dog"}, \code{"horse"}, \code{"motorbike"}, \code{"person"}, \code{"potted plant"}, \code{"sheep"}, \code{"sofa"}, \code{"train"}, and \code{"tv"}. +\code{"cow"}, \code{"dining table"}, \code{"dog"}, \code{"horse"}, \code{"motorbike"}, \code{"person"}, \code{"potted plant"}, \code{"sheep"}, \code{"sofa"}, \code{"train"}, and \code{"tv/monitor"}. +They are available through the \code{classes} variable of the dataset object. This dataset is frequently used for training and evaluating semantic segmentation models, and supports tasks requiring dense, per-pixel annotations. } diff --git a/tests/testthat/test-dataset-pascal.R b/tests/testthat/test-dataset-pascal.R index dd36e32f..44b72a9d 100644 --- a/tests/testthat/test-dataset-pascal.R +++ b/tests/testthat/test-dataset-pascal.R @@ -24,10 +24,10 @@ test_that("tests for the Pascal VOC Segmentation dataset for train split for yea }) test_that("tests for the Pascal VOC Segmentation dataset for test split for year 2007", { - + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") - + pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'test', download = TRUE) expect_length(pascal, 210) first_item <- pascal[1] @@ -45,10 +45,10 @@ test_that("tests for the Pascal VOC Segmentation dataset for test split for year }) test_that("tests for the Pascal VOC Segmentation dataset for trainval split for year 2007", { - + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") - + pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'trainval', download = TRUE) expect_length(pascal, 422) first_item <- pascal[1] @@ -66,10 +66,10 @@ test_that("tests for the Pascal VOC Segmentation dataset for trainval split for }) test_that("tests for the Pascal VOC Segmentation dataset for val split for year 2007", { - + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") - + pascal <- pascal_segmentation_dataset(root = t, year = '2007', split = 'val', download = TRUE) expect_length(pascal, 213) first_item <- pascal[1] @@ -422,10 +422,10 @@ test_that("tests for the Pascal VOC detection dataset for train split for year 2 }) test_that("tests for the Pascal VOC detection dataset for test split for year 2007", { - + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") - + pascal <- pascal_detection_dataset(root = t, year = '2007', split = 'test', download = TRUE) expect_length(pascal, 4952) first_item <- pascal[1] @@ -442,10 +442,10 @@ test_that("tests for the Pascal VOC detection dataset for test split for year 20 }) test_that("tests for the Pascal VOC detection dataset for trainval split for year 2007", { - + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") - + pascal <- pascal_detection_dataset(root = t, year = '2007', split = 'trainval', download = TRUE) expect_length(pascal, 5011) first_item <- pascal[1] @@ -462,10 +462,10 @@ test_that("tests for the Pascal VOC detection dataset for trainval split for yea }) test_that("tests for the Pascal VOC detection dataset for val split for year 2007", { - + skip_if(Sys.getenv("TEST_LARGE_DATASETS", unset = 0) != 1, "Skipping test: set TEST_LARGE_DATASETS=1 to enable tests requiring large downloads.") - + pascal <- pascal_detection_dataset(root = t, year = '2007', split = 'val', download = TRUE) expect_length(pascal, 2510) first_item <- pascal[1] @@ -779,4 +779,4 @@ test_that("tests for the Pascal VOC detection dataset for val split for year 201 expect_type(first_item$y$labels,"character") expect_length(first_item$y$labels, 1) expect_s3_class(first_item, "image_with_bounding_box") -}) \ No newline at end of file +})