用石灰解释角膜图像分类模型

6月20日,二千零一十八
通过

(本文首次发表于 Shirin游乐场,请并对 188bet appR博主

上周我发表了一篇博文,介绍用角膜刀训练图像分类模型是多么容易。金宝搏网址.

我在那篇文章中没有展示的是如何使用模型进行预测。这个,我会在这里做的。但是预测本身就很无聊,所以我要用石灰包裹。

我已经写了几篇博文(在这里,请在这里在这里)关金宝搏网址于莱姆和已经谈过了(在这里在这里关于金宝搏网址它,也是。

它们都不适用于图像分类模型,不过。以及从年月日起发布的新版本。Thomas Lin Pedersen的石灰包裹,请石灰现在不仅是在克兰,但它本身支持角膜和图像分类模型。

托马斯写了一封非常好的信关于如何使用的文金宝搏网址章克拉斯石灰在R你说什么?在这里,下面我将使用ImageNet(VGG16)对水果图像进行预测和解释,然后将分析扩展到上周的模型并与预训练网进行比较。

加载库和模型

库(keras)用于处理神经网络库(lime)用于解释模型库(magick)用于预处理图像库(ggplot2)用于附加绘图
  • 加载预训练图像网络模型
型号<-应用程序_vg16(weights=“imagenet”,包括\u top=true)模型
## Model## ___________________________________________________________________________## Layer (type)                     Output Shape                  Param #     ## ===========================================================================## input_1 (InputLayer)             (None,224,224,3)0 \\\\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU uuuuuuuuuuuuuuuuuuuu__block1_u conv1(conv2d)(无,224,224,64)1792 \\\\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUuuuuuuuuuuuuuuuuuuuu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UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU uuuuuuuuuuuuuuuuuuuuuuuuuuu__block5_pool(maxpooling2d)(无,7,7,512)0 \\\\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU压平(压平)(无,25088)0 \\\\\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU40996)102764544 \\\\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU密度(无)40996)16781312 \\\\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU预测(密集)(无,1000)                  4097000     ## ===========================================================================## Total params: 138,357,544## Trainable params: 138,357,544## Non-trainable params: 0## ___________________________________________________________________________
模型2<-加载\模型\uHDF5(filepath=“/users/shiringlander/documents/github/dl_ai/tutti-frutti/frutti-360/keras/fruts-checkpoints.h5”)模型2
## Model## ___________________________________________________________________________## Layer (type)                     Output Shape                  Param #     ## ===========================================================================## conv2d_1 (Conv2D)                (None,20,20,32)896  \\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU激活(激活)(无,20,20,32)0 \\\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU uuuuuuuuuuuuuuuuu_conv2d_2(conv2d)(无,20,20,16)4624 \\\\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu1(Leakyrelu)(无,20,20,16)0 \\\\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU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UUUUUUUUUUUUUUUUUUUUUUU激活2(激活)(无,100)0 \\\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU退出2(退出)(无,100)0 \\\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu16)1616 \\\\\UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU激活(激活)(无,16)                    0           ## ===========================================================================## Total params: 167,300## Trainable params: 167,268## Non-trainable params: 32## ___________________________________________________________________________

加载和准备图像

在这里,我正在加载和预处理两个水果图像(是的,我有点作弊,因为我选择的是我希望我的模型能工作的图像,因为它们类似于训练图像…)。

  • 香蕉
test_image_files_path<-“/users/shiringlander/documents/github/dl_ai/tutti_tti/frutti/水果-360/test”img<-image_read('https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/banana single.jpg/272px banana single.jpg')img_path<-file.path(test_image_files_path,“香蕉”‘banana.jpg’)图像写入(img,img_路径绘图(如光栅(img))。
  • 克莱门汀
img2<-image-read('https://cdn.pixabay.com/photo/2010/12/13/09/51/clementine-1792_1280.jpg')img_path2<-file.path(测试_image_files_path,“克莱门特”'clementine.jpg')图像写入(img2,img_path2)绘图(如光栅(img2))。

超像素

将图像分割为超像素是生成图像模型解释的重要步骤。分割正确并遵循图片中有意义的模式都很重要,但是,超像素的大小/数量也是合适的。如果图像中的重要特征被切碎成太多的片段,排列可能会在几乎所有情况下损坏无法识别的图像,导致解释模型不好或失败。由于感兴趣的对象的大小在变化,因此不可能为要分割的超像素数设置硬规则——对象相对于图像的大小越大,应该生成更少的超级像素。使用plot_superpixels,可以在启动耗时的解释函数之前评估superpixel参数。(帮助(绘制超级像素)

绘制超级像素(img_路径,n_超级像素=35,重量=10)

绘制超级像素(img_path2,n_超级像素=50,重量=20)

从超像素图可以看出,克莱门汀图像的分辨率比香蕉图像高。

为ImageNet准备图像

图像准备<-函数(x)数组<-重叠(x,函数(路径)img<-图像加载(路径,目标尺寸=c(224224))x<-图像\到\数组(img)x<-数组\重塑(x,C(1,dim(x)))x<-imagenet_预处理_输入(x))do.call(abind::abind,C(数组)列表(沿=1))
  • 测试预测
Res<-预测(模型,图像准备(C(img_路径,img_path2)))imagenet_解码_预测(res)
## [[1]]##   class_name class_description        score## 1  n07753592            banana 0.9929747581## 2  n03532672              hook 0.0013420776## 3  n07747607            orange 0.0010816186## 4  n07749582             lemon 0.0010625814## 5  n07716906  spaghetti_squash 0.0009176208## ## [[2]]##   class_name class_description      score## 1  n07747607橙色0.78233224 2 N07753592香蕉0.04653566 3 N07749582柠檬0.03868873 4 N03134739槌球0.03350329 5 N07745940草莓0.01862431
  • 装载标签和列车解列器
_型标签<-readrds(system.file('extdata','imagenet_labels.rds',package='lime'))explainer<-lime(c(img_path,IMGPATHAT2)作为分类器(模型,型号标签)图像预处理

培训讲解员(解释()功能)可能需要很长时间。在我自己的模型中,使用较小的图像会更快,但使用较大的ImageNet运行需要几分钟。

解释<-解释(c(img_路径,IMGPATHAT2)解释者,nl标签=2,n_特征=35,n_超级像素=35,重量=10,background=“白色”)
  • 绘图图像解释(一次只支持显示一个案例
绘图图像解释(解释)

clementine<-explanation[解释$case==“clementine.jpg”,]绘制图像解释(clementine)

为我自己的模型准备图像

  • 测试预测(类似于培训和验证图像)
test_datagen<-image_data_generator(rescale=1/255)test_generator=flow_images_from_directory(test_image_files_path,TestelDATAGEN,目标尺寸=C(20,20)class_mode='categorial')预测<-as.data.frame(预测_生成器(模型2,测试生成程序步骤=1)加载(“/users/shiringlander/documents/github/dl ai/tutti_tti/frutti-360/fruits_classes_indexes.rdata”)水果类_indexes_df<-data.frame(indexs=unlist(fruits_classes_indexes))水果类_indexes_df<-水果类_indexes_df[顺序(水果类_indexes_df$indexes),,请drop=false]colnames(predictions)<-rownames(fruits_classes_indexes_df)t(round(predictions,数字=2)
##             [,1] [,2]## Kiwi           0 0.00## Banana         1 0.11## Apricot        0 0.00## Avocado        0 0.00## Cocos          0 0.00## Clementine     0 0.87## Mandarine      0 0.00## Orange         0 0.00## Limes          0 0.00## Lemon          0 0.00## Peach          0 0.00## Plum           0 0.00## Raspberry      0 0.00## Strawberry0.01菠萝0 0.00石榴0 0.00
(i in 1:nrow(预测))cat(i,“:”)打印(unlist(which.max(预测[i,])))}
##1:香蕉2 2:克莱门汀6

这似乎与石灰不相容,但是(或者如果有人知道它是如何工作的,请告诉我)–所以我准备了与ImageNet图像类似的图像。

图像预处理2<-函数(x)数组<-重叠(x,函数(路径)img<-图像加载(路径,目标尺寸=C(20,20))x<-image_to_array(img)x<-网状::array_整形(x,C(1,dim(x)))x<-x/255)do.call(abind::abind,C(数组)列表(沿=1))
  • 准备标签
水果类指数
##9 10 8 2 11猕猴桃、香蕉、杏子、鳄梨、可可、柠檬4 15桃、李子、覆盆子、草莓、菠萝、石榴
  • 列车解说员
解释2<-石灰(c(img_路径,IMGPATHAT2)作为分类器(型号2,水果类指数,图像解释2<-解释(c(img-u路径,IMGPATHAT2)解释2,nl标签=1,n_特征=20,n_超级像素=35,重量=10,background=“白色”)
  • 绘制特征权重以找到良好的绘制阈值(见下文)
解释2%>%ggplot(aes(x=特征权重))+facet_wrap(~ case,scales=“free”)+geom_density()。

  • 绘图预测
绘图图像解释(解释2,display='块',阈值=5e-07)

clementine2<-explanation2[explanation2$case==“clementine.jpg”,]绘制图像解释(clementine2,display='块',阈值=0.16)


会话信息()
## R version 3.5.0 (2018-04-23)## Platform: x86_64-apple-darwin15.6.0 (64-bit)## Running under: macOS High Sierra 10.13.5## ## Matrix products: default## BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib## LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib## ## locale:## [1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8## ## attached base packages:## [1] stats     graphics  grDevices utils     datasets  methods   base     ## ## other attached packages:## [1] ggplot2_2.2.1 magick_1.9    lime_0.4.0    keras_2.1.6  ## ## loaded via a namespace (and not attached):##  [1] stringdist_0.9.5.1 reticulate_1.8     xfun_0.2          ##  [4] lattice_0.20-35    colorspace_1.3-2   htmltools_0.3.6   ##  [7] yaml_2.1.19        base64enc_0.1-3    rlang_0.2.1       ## [10] pillar_1.2.3       later_0.7.3        foreach_1.4.4     ## [13] plyr_1.8.4         tensorflow_1.8     stringr_1.3.1     ## [16] munsell_0.5.0      blogdown_0.6       gtable_0.2.0      ## [19] htmlwidgets_1.2    codetools_0.2-15   evaluate_0.10.1   ## [22] labeling_0.3       knitr_1.20         httpuv_1.4.4.1    ## [25] tfruns_1.3         parallel_3.5.0     curl_3.2          ## [28] Rcpp_0.12.17       xtable_1.8-2       scales_0.5.0      ## [31] backports_1.1.2    promises_1.0.1     jsonlite_1.5      ## [34] abind_1.4-5        mime_0.5           digest_0.6.15     ## [37] stringi_1.2.3      bookdown_0.7       shiny_1.1.0       ## [40] grid_3.5.0         rprojroot_1.3-2    tools_3.5.0       ## [43] magrittr_1.5       lazyeval_0.2.1     shinythemes_1.1.1 ## [46] glmnet_2.0-16      tibble_1.4.2       whisker_0.3-2     ## [49] zeallot_0.1.0      Matrix_1.2-14      gower_0.1.2       ## [52] as插入_0.2.0 rmarkdown_1.10迭代器_1.0.9[55]r6_2.2.2编译器_3.5.0

留下评论作者,请关注他们博客上的链接和评论: Shirin游乐场.

188bet appR博客提供 每日电子邮件更新金宝搏网址 R新闻与 教程关于以下主题: 数据科学,请 大数据, r作业,请可视化(可视化) GGPROTT2,请 箱形图,请 地图,请 动画)程序设计( RSTUDIO公司,请 斯威夫特,请 乳胶,请 SQL,请 日食,请 吉特,请 哈多普,请 刮网)统计 回归,请 主成分分析,请 时间序列,请 交易还有更多…



如果你走这么远,为什么不 订阅更新 从站点?选择您的口味: 电子邮件,请 推特,请 1188bet app,请或 脸谱网

注释已关闭。

搜索R-Blo188bet appggers


赞助商

千万不要错过更新!
订阅R-Bloggers188bet app接收
最新R帖子的电子邮件。
(您将不再看到此消息。)

单击此处关闭(此弹出窗口将不再出现)