platypus
platypus copied to clipboard
NA's for predictions using grayscale photo
Describe the bug The predict function does not work with a black and white (i.e., grayscale) photo as expected. Instead of returning predictions, it returns NA's.
To Reproduce Code and steps to reproduce the behavior:
#remotes::install_github("maju116/platypus")
# set working directory
setwd(mypath)
# load packages
library(remotes)
library(platypus)
library(tidyverse)
library(abind)
library(reticulate)
# set conda environment
use_condaenv(conda_list()[4,2])
# setup yolo for grayscale photo
test_yolo_bw <- yolo3(
net_h = 416, # Input image height. Must be divisible by 32
net_w = 416, # Input image width. Must be divisible by 32
grayscale = TRUE, # Should images be loaded as grayscale or RGB
n_class = 80, # Number of object classes (80 for COCO dataset)
anchors = coco_anchors # Anchor boxes
)
# inspect model
test_yolo_bw
# load darknet weights (note these must be downloaded)
test_yolo_bw %>% load_darknet_weights("yolov3.weights")
# store file path and name for photo
test_img_paths <- file.path(getwd(),"PDEP_2020-06-05_0303_0437.JPG")
# load image and format array for analysis
test_imgs <- test_img_paths %>%
map(~ {
image_load(., target_size = c(416,416), color_mode = "grayscale") %>%
image_to_array() %>% `/`(255)}) %>%
abind(along = 4) %>%
aperm(c(4, 1:3))
# get predictions of bounding boxes and class probabilities
test_preds <- test_yolo_bw %>% predict(test_imgs)
Expected behavior I expect the test_preds to be the predictions of bounding boxes and class probabilities: str(test_preds) List of 3 $ : num [1:4, 1:13, 1:13, 1:3, 1:85] 0.0249 0.0207 0.0028 0.0333 0.0526 ... $ : num [1:4, 1:26, 1:26, 1:3, 1:85] -0.03215 -0.03135 -0.0133 -0.05226 -0.00532 ... $ : num [1:4, 1:52, 1:52, 1:3, 1:85] 0.00578 0.00599 0.00452 0.01023 0.00315 ...
Screenshots If applicable, add screenshots to help explain your problem.
Session information (please complete the following information):
- OS: [e.g. iOS]:
- R version:
- Python version:
- TensorFlow (Python) version (
tensorflow::tf_version()
): - R session information (
sessionInfo()
):
sessionInfo()
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] reticulate_1.28 abind_1.4-5 lubridate_1.9.2 forcats_1.0.0
[5] stringr_1.5.0 dplyr_1.1.1 purrr_1.0.1 readr_2.1.4
[9] tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.2 tidyverse_2.0.0
[13] platypus_0.1.1 keras_2.11.1 tensorflow_2.11.0
loaded via a namespace (and not attached):
[1] progress_1.2.2 tidyselect_1.2.0 remotes_2.4.2 lattice_0.20-45
[5] colorspace_2.1-0 vctrs_0.6.1 generics_0.1.3 base64enc_0.1-3
[9] utf8_1.2.3 XML_3.99-0.14 rlang_1.1.0 pillar_1.9.0
[13] glue_1.6.2 withr_2.5.0 rappdirs_0.3.3 RColorBrewer_1.1-3
[17] lifecycle_1.0.3 munsell_0.5.0 gtable_0.3.3 tzdb_0.3.0
[21] tfruns_1.5.1 fansi_1.0.4 Rcpp_1.0.10 scales_1.2.1
[25] jsonlite_1.8.4 gridExtra_2.3 hms_1.1.3 png_0.1-8
[29] stringi_1.7.12 grid_4.2.2 rprojroot_2.0.3 here_1.0.1
[33] cli_3.6.1 tools_4.2.2 magrittr_2.0.3 crayon_1.5.2
[37] whisker_0.4.1 pkgconfig_2.0.3 zeallot_0.1.0 Matrix_1.5-1
[41] prettyunits_1.1.1 timechange_0.2.0 rstudioapi_0.14 R6_2.5.1
[45] compiler_4.2.2
tensorflow::tf_version()
[1] ‘2.10’
python version is 3.7
Additional context I have no trouble running the example with a color photo, but with a grayscale photo I get this for the predictions: str(test_preds) List of 3 $ : num [1:6, 1:13, 1:13, 1:3, 1:85] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... $ : num [1:6, 1:26, 1:26, 1:3, 1:85] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... $ : num [1:6, 1:52, 1:52, 1:3, 1:85] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
Maybe the COCO training data did not include any grayscale photos?