Open iacobus42 opened 4 years ago
I got the same error and was able to fix it using:
explanation <- as.data.frame(explanation)
plot_image_explanation(explanation)
Found out that the class of the object explanation
was also tbl_df
and tbl
instead of just data.frame
(solved it thanks to the example from the help-file of plot_image_explanation
).
I got the same error and now the as.data.frame
is not working for the tbl
.
The example of plot_image_explanation
is a data frame and it still work. However, the object from explain
is tbl
and will throw the following error for as.data.frame
:
Error in `vec_size()`:
! `x` must be a vector, not a <superpixel_list> object.
---
Backtrace:
▆
1. ├─base::as.data.frame(explanation)
2. ├─tibble:::as.data.frame.tbl_df(explanation)
3. │ ├─base::`[<-`(`*tmp*`, unname, value = `<named list>`)
4. │ └─tibble:::`[<-.tbl_df`(`*tmp*`, unname, value = `<named list>`)
5. │ └─tibble:::tbl_subassign(x, i, j, value, i_arg, j_arg, substitute(value))
6. │ └─tibble:::vectbl_recycle_rhs_rows(...)
7. │ ├─base::withCallingHandlers(...)
8. │ └─vctrs::vec_recycle(value[[j]], nrow)
9. └─vctrs:::stop_scalar_type(`<fn>`(`<sprpxl_l>`), "x", `<fn>`(vec_size()))
10. └─vctrs:::stop_vctrs(...)
11. └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = vctrs_error_call(call))
I wonder if anyone has insights on it? Thanks!
I figured that we can create a data frame from explanation
object in the following code. We need to take care of the nested list object (eg. feature_value, data, prediction). So here is the workaround so that explanation_df
is the input of plot_image_explanation() function:
explanation_df <- data.frame(model_type = explanation$model_type,
case = explanation$case,
label = explanation$label,
label_prob = explanation$label_prob,
model_r2 = explanation$model_r2,
model_intercept = explanation$model_intercept,
model_prediction = explanation$model_prediction,
feature = explanation$feature,
feature_value = NA,
feature_weight = explanation$feature_weight,
feature_desc = explanation$feature_desc,
data = NA,
prediction = NA,
stringsAsFactors = FALSE)
## this will coerce superpixel_list and bitmap_list to list, but still works for plotting
for (i in 1:nrow(explanation_df)){
explanation_df$feature_value[i] <- explanation$feature_value[i]
explanation_df$data[i] <- explanation$data[i]
explanation_df$prediction[i] <- explanation$prediction[i]
}
plot_image_explanation(explanation_df)
Thanks for this... I want to experiment with lime on images but got stuck installing tensorflow. Might anyone have a link to the explanation
data frame to use with lime thus bypassing the modeling step? Much appreciated.
Using this tutorial on the RStudio AI blog: https://blogs.rstudio.com/ai/posts/2018-03-09-lime-v04-the-kitten-picture-edition/
Everything runs fine until
Running either
explanation
orplot_image_explanation(explanation)
returns the error message:Using
rlang::last_error()
andrlang::last_trace()
suggest a possible conflict with thevctrs
package.str(explanation)
looks complete andexplain()
doesn't cause any errors - only when attempting to plot/print/view the results.My session info is below: