背景
花椒相机是360发布的一款拍照APP,可以在照片中加入各种小插件来美化照片。尽管自动化可以搞定该APP拍照的大部分功能,但是对于加入插件后的照片是否正确却无法验证,只能通过保存到本地,进行人工检查。无法使自动化形成一个闭环,未能使自动化的价值最大化。
可行性分析
既然可以拍照把照片保存到本地,当照片变多后,就形成了大量的照片数据,这些照片完全就可以再利用起来,用人工智能来玩。
工具选择
· Google出品的TensorFlow,说真的,楼主倒腾了两天TensorFlow,硬是没搞出个结果来,所以放弃了。
· Python机器学习包,Scikit-learn,超好用的机器学习包,一直都在用这个机器学习包。
工欲善其事必先利其器
这里简单的写下所需要的工具包的安装,如果安装的时候遇到了各种莫名其妙的报错问题,那么Google一下
楼主的Python版本是2.7,已经安装好pip,所以只要简单几步就可以安装好运行Scikit-learn所需要的环境
安装Numpy
$ sudo pip install numpy
安装Scipy
$ sudo pip install scipy
安装Scikit-learn
$ sudo pip install scikit-learn
安装PIL, 这个用来读取图片,到官网下载安装包到本地,切换到解压路径
$ sudo python setup.py install
注意: 有可能还要安装JPEG的包,这个取决于本机是否已经安装,未安装的可以参考网上教程
其他
· 训练数据以及测试数据,这里楼主自拍了7种不同插件的照片共计136张,测试数据5种共计5张
· 对于机器学习来说,数据是越多越好越多越好,更多的数据会让你的模型效果更佳 :)
你仅仅需要一点点机器学习的基础知识,以及Python基础知识。
那我们就从这里开始进入正文
因为楼主的目的是要对图片进行多分类,因为楼主的数据里面已经有X -> Y了,所以这是一种有监督学习。
首先我们要确定的是用什么算法来训练数据,这里楼主主要试验了两种算法:
1、KNN
使用KNN的时候,因为数据样本不够多,正确率大概在60%左右,不是太可观的结果。
2、SVM
对于,支持向量机,也使用了两种算法
· SVC:"one-against-one"策略
· LinearSVC:"one-vs-the-rest"策略
代码如下:
import Image
import numpy as np
import os
from sklearn import svm
def getTrainClass(category):
if category == 'Train':
classes = {0, 1, 2, 3, 4, 5, 6, 7}
else:
classes = {0, 1, 2, 5, 7}
return classes
def getImageData(path,classes):
ImageList = []
LabelList = []
for name in classes:
class_path = cwd + path + "/" + str(name) + "/"
for image_name in os.listdir(class_path):
image_path = class_path + image_name
if 'JPG' in image_path:
img = Image.open(image_path)
ImageList.append(np.asarray(img).flatten())
LabelList.append(name)
return ImageList, LabelList
cwd = '/home/hadoop/Pictures/pic1/'
TrClasses = getTrainClass('Train')
tr_img, tr_label = getImageData('Train',TrClasses) #加载训练数据
tstClass = getTrainClass('Validation')
tst_img, tst_label = getImageData('Validation',tstClass) #加载测试数据
svcClf = svm.LinearSVC() #直接使用默认参数就好了
svcClf.fit(tr_img,tr_label)
Z = svcClf.predict(tst_img)
result = (1 - np.sum(Z==tst_label)/float(len(tst_img)))
print " the total error rate is: %f" %result
使用LinearSVC训练数据的时候,效率稍微有点低,比直接使用SVC低,但是别人正确率高呀
结果如下:
剩下要做的是就是固化了,然后就可以直接调用了。
写在最后的话
这是时下很火热的人工智(RUO)能(ZHI)在测试中的一种应用,相信在测试工作中,还有很多地方可以使用人工智(RUO)能(ZHI)来提高咱们的工作效率。
-
迎接新年作文:https://www.nanss.com/xuexi/11797.html 广告营销策划方案:https://www.nanss.com/gongzuo/13194.html 学风建设主题班会:https://www.nanss.com/xuexi/13402.html 关于悲伤的网名:https://www.nanss.com/mingcheng/13804.html 乡镇安全生产工作总结:https://www.nanss.com/gongzuo/13182.html 家务劳动心得体会:https://www.nanss.com/xuexi/12804.html 公务员转正申请:https://www.nanss.com/gongzuo/13754.html 吃空饷自查报告:https://www.nanss.com/gongzuo/13670.html 钓鲤鱼饵料配方:https://www.nanss.com/shenghuo/12246.html 法拉第的故事:https://www.nanss.com/yuedu/13853.html 有意义网名:https://www.nanss.com/mingcheng/11600.html 日语作文:https://www.nanss.com/xuexi/12922.html 入党志愿书模板:https://www.nanss.com/xuexi/13135.html 教师个人工作计划:https://www.nanss.com/gongzuo/12581.html 绿色生活作文:https://www.nanss.com/xuexi/11682.html 团代会贺信:https://www.nanss.com/gongzuo/13036.html 大会总结:https://www.nanss.com/gongzuo/12726.html 一如既往造句:https://www.nanss.com/xuexi/11867.html 年末祝福语:https://www.nanss.com/yulu/11742.html 诗歌朗诵大全:https://www.nanss.com/xuexi/13334.html 从一心一意到十全十美:https://www.nanss.com/yulu/12110.html 党建调研报告:https://www.nanss.com/gongzuo/13764.html 描写人物心情的成语:https://www.nanss.com/xuexi/11746.html 死骑名字:https://www.nanss.com/mingcheng/13841.html 形容小男孩帅萌的句子:https://www.nanss.com/yulu/11960.html 民事上诉状范文:https://www.nanss.com/gongzuo/12716.html 孝心少年事迹材料:https://www.nanss.com/gongzuo/13239.html 养鱼养几条好:https://www.nanss.com/wenti/12160.html 装修施工温馨告知书:https://www.nanss.com/xuexi/12671.html 闺蜜专属昵称:https://www.nanss.com/mingcheng/12388.html(0) 回复 (0)
-
讨债公司/蓝月传奇辅助/蓝月辅助(0) 回复 (0)
-
讨债公司 搬家公司 蓝月传奇辅助(0) 回复 (0)
-
讨债公司 搬家公司 蓝月传奇辅助(0) 回复 (0)
-
北京私家侦探 上海搬家公司 网站制作(0) 回复 (0)