Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webmorphR.dlib auto_delin() error in matrix dimensions #19

Open
navmayan opened this issue Apr 17, 2023 · 1 comment
Open

webmorphR.dlib auto_delin() error in matrix dimensions #19

navmayan opened this issue Apr 17, 2023 · 1 comment

Comments

@navmayan
Copy link

Hi,
I'm using the auto_delin function with the dlib70 model.
I wrote this wrapper function:

get_individually_aligned_faces <- function(x)
{
  stimuli <- read_stim(path = x$path, pattern = c("-A\\.","-HC\\.","-HO\\.","-N\\.","-S\\.")) # filter out "NM" (neutral with covid mask) images, by providing specific patterns
  face_model <- auto_delin(stimuli, "dlib70", replace = F) # get faces dlib70 model 
  dtmp <- draw_tem(face_model) |> plot() # draw face template from model
  patch_fill <- patch(face_model, width = 1, height = 10) # get the background color of the face image, to be used when adjusting the face location
  horized <- face_model |> horiz_eyes(fill = patch_fill) # align by eyes
  horized_plot <- horized |> plot()
  aligned <- face_model |> horiz_eyes(fill = patch_fill) |> align(procrustes = TRUE, fill = patch_fill) # align using procrustes (average location of all images)
  aligned_plot <- aligned |> plot()
  stim_list <- list(fm = face_model,tmp = dtmp,hrz = horized,hrzplot = horized_plot,alg = aligned,algplot = aligned_plot) # save everything
}

And I'm calling it for different subsets of images using purrr::map (actually, within each subset, I have 4 or 5 images for each face identify that are saved in the same directory and are called from the same path on each run of my function).

For some reason, the auto_delin function runs fine for some subsets of images, but not for others. I'm getting the following error, suggesting there's a problem with creating a matrix for some of the images (in this case, image F-061):
Error in mutate():
! Problem while computing params = purrr::map(.x = data, .f = ~get_individually_aligned_faces(.x)).
ℹ The error occurred in group 10: image_id = "F-061".
Caused by error in purrr::map():
ℹ In index: 1.
Caused by error in matrix():
! length of 'dimnames' [2] not equal to array extent
Backtrace:

  1. ... %>% unnest_wider(params)
  2. purrr::map(.x = data, .f = ~get_individually_aligned_faces(.x))
  3. purrr:::map_("list", .x, .f, ..., .progress = .progress)
  4. .f(.x[[i]], ...)
  5. global get_individually_aligned_faces(.x)
  6. webmorphR.dlib::auto_delin(stimuli, "dlib70", replace = F)
  7. webmorphR.dlib::dlib_auto_delin(stimuli, model, replace, model_path)
  8. base::matrix(...)

All images come from the same database (the subsetting is just for easier debugging) and are of the same file type (JPG). Within each subset, there are the same number of files (either 4 or 5) per face identity.

Any suggestions?
Thanks.

@navmayan
Copy link
Author

More info: when calling read_stim for images for which auto_delin works properly, I'm getting a stimlist of 5 elements: imagepath, desc (with a binary comment that produces a warning message), width, and height. For images for which auto_delin does not work, I'm getting 4 elements (no 'desc'). Is that important in some way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant