如何在R脚本中使用Pillow(python库)?

时间:2018-03-15 16:17:55

标签: python r pillow

如何在R脚本中使用Pillow(python库)?

在这个R剧本中,使用枕头是必要的......但是它给我一个错误!

  

(“Pillow Python包需要加载图像”)

需要帮助......

library(keras)
library(abind)



# get some image
img_path <- system.file('extdata', 'produce.png', package = 'lime')


# load a predefined image classifier
model <- application_vgg16(weights = "imagenet", include_top = TRUE)

https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels.h5下载数据 553467904/553467096 [==============================] - 273s 0us / step

# create a function that prepare images for the model
img_preprocess <- function(x) {
arrays <- lapply(x, function(path) {
img <- image_load(path, target_size = c(224,224))   # <-- this is what generates the error !
x <- image_to_array(img)
x <- array_reshape(x, c(1, dim(x)))
x <- imagenet_preprocess_input(x)
})
do.call(abind, c(arrays, list(along = 1)))
}




# Create an explainer (lime recognise the path as an image)
explainer <- lime(img_path, as_classifier(model, unlist(labels)), img_preprocess)




# Explain the model (can take a long time depending on your system)
explanation <- lime::explain(img_path, explainer, n_labels = 2, n_features = 10, n_superpixels = 70)
  

image_load(path, target_size = c(224, 224))中的错误:枕头   加载图像需要Python包

但是我可以在这个R脚本中使用Python Pillow库吗?

感谢您的关注。

0 个答案:

没有答案