R语言:用微软的深度学习理解图片情感
2017-01-03 12:27
323 查看
本文系转载,原博客:http://blog.csdn.net/wzgl__wh/article/details/52904069
使用微软(https://www.microsoft.com/cognitive-services/en-US/subscriptions)的Emotion 来理解一张图片的人物表情,下面直接上代码:
欧巴马的图:
这张图显示他在微笑,但是我们的结果是生气的,看来深度学习还是有改进的空间的。
使用微软(https://www.microsoft.com/cognitive-services/en-US/subscriptions)的Emotion 来理解一张图片的人物表情,下面直接上代码:
> library("httr")#链接API > library("XML")#爬取网页数据 > library("stringr")#字符串处理 > library("ggplot2")#绘图使用 > img.url = 'https://www.whitehouse.gov/sites/whitehouse.gov/files/images/first-family/44_barack_obama[1].jpg' > URL.emoface = 'https://api.projectoxford.ai/emotion/v1.0/recognize' > emotionKEY = 'b72720c5c1ed4b40a25d00e3db325c32' # 在此处输入你获取的key > mybody = list(url = img.url) > faceEMO = POST( + url = URL.emoface, + content_type('application/json'), add_headers(.headers = c('Ocp-Apim-Subscription-Key' = emotionKEY)), + body = mybody, + encode = 'json' + ) > faceEMO Response [https://api.projectoxford.ai/emotion/v1.0/recognize] Date: 2017-01-03 04:23 Status: 200 Content-Type: application/json; charset=utf-8 Size: 259 B > obama = httr::content(faceEMO)[[1]] > obama $faceRectangle $faceRectangle$height [1] 269 $faceRectangle$left [1] 399 $faceRectangle$top [1] 80 $faceRectangle$width [1] 269 $scores $scores$anger [1] 9.530491e-10 $scores$contempt [1] 7.204279e-13 $scores$disgust [1] 2.932419e-09 $scores$fear [1] 1.770692e-13 $scores$happiness [1] 1 $scores$neutral [1] 1.277603e-11 $scores$sadness [1] 1.228429e-12 $scores$surprise [1] 1.559173e-10 > o<-as.data.frame(as.matrix(obama$scores)) > o$V1 <- lapply(strsplit(as.character(o$V1 ), "e"), "[", 1) > o$V1<-as.numeric(o$V1) > colnames(o)[1] <- "Level" > o$Emotion<- rownames(o) > ggplot(data=o, aes(x=Emotion, y=Level)) + + geom_bar(stat="identity")
欧巴马的图:
这张图显示他在微笑,但是我们的结果是生气的,看来深度学习还是有改进的空间的。
相关文章推荐
- R语言 R6Class 读取Ini文件
- 数据分析学习笔记(教材篇)
- 【数据挖掘与R语言笔记】预测海藻数量(一)观察数据和处理数据缺失
- 【数据挖掘与R语言笔记】预测海藻数量(二)线性模型和回归树模型
- CUDA搭建
- 稀疏自动编码器 (Sparse Autoencoder)
- 白化(Whitening):PCA vs. ZCA
- softmax回归
- 卷积神经网络初探
- Prisma修图软件的图片风格转换算法
- TensorFlow人工智能引擎入门教程之九 RNN/LSTM循环神经网络长短期记忆网络使用
- TensorFlow人工智能引擎入门教程之十 最强网络 RSNN深度残差网络 平均准确率96-99%
- TensorFlow人工智能入门教程之十一 最强网络DLSTM 双向长短期记忆网络(阿里小AI实现)
- TensorFlow人工智能入门教程之十四 自动编码机AutoEncoder 网络
- TensorFlow人工智能引擎入门教程所有目录
- R语言书籍的学习路线图
- 如何用70行代码实现深度神经网络算法
- 近200篇机器学习&深度学习资料分享(含各种文档,视频,源码等)