【开发日记】马桶识别之数据清洗,通过Resnet50清洗脏数据
2017-12-24 20:00
399 查看
通过上篇文章,我已经获取了天猫商城某款马桶评论区的图片。但是,用户上传的评论图片并不都是马桶图片,如下所示:
其中有很多的脏数据。一个简单的笨方法是一个个去选,但是作为一个程序员,当然是应用程序自动去清洗脏数据。
这里使用ImageNet预训练好的Resnet50模型去识别图片,并将脏数据挑选出来。以下为源代码:
相应的脏数据如下:
通过resnet50,基本上可以把脏数据清洗干净,可见深度学习的威力。但是,还是存在一些错误,这只能通过人工进一步清洗了。不过工作量已经少了很多。
其中有很多的脏数据。一个简单的笨方法是一个个去选,但是作为一个程序员,当然是应用程序自动去清洗脏数据。
这里使用ImageNet预训练好的Resnet50模型去识别图片,并将脏数据挑选出来。以下为源代码:
import resnet50 import os import shutil pathlist = os.listdir('data_grab') count = 0 for i in pathlist: pathlist[count] = os.path.join('data_grab', pathlist[count]) count+=1 predictions = resnet50.predict(pathlist) count = 0 for i in predictions: flag = 0 if i!=None: for top in range(3): name = i[top][1] if name=='toilet_seat': flag = 1 if flag==1: shutil.copyfile(pathlist[count], 'cleandata//'+pathlist[count][-9:]) else: shutil.copyfile(pathlist[count], 'dirtydata//'+pathlist[count][-9:]) count+=1其中,resnet50的源代码如下:
from keras.applications.resnet50 import ResNet50 from keras.preprocessing import image from keras.applications.resnet50 import preprocess_input, decode_predictions import numpy as np def predict(img_paths): model = ResNet50(weights='imagenet') m = len(img_paths) predictions = [None]*m count = 0 for i in img_paths: print("load file: ", str(i)) try: img = image.load_img(i, target_size=(224, 224)) img = image.img_to_array(img) x = np.expand_dims(img, axis=0) x = preprocess_input(x) preds = model.predict(x) preds = decode_predictions(preds, top=3)[0] predictions[count] = preds count+=1 except: count+=1 continue return predictions if __name__=="__main__": import os pathlist = os.listdir('data_grab') count = 0 for i in pathlist: pathlist[count] = os.path.join('data_grab', pathlist[count]) count+=1 predictions = predict(pathlist) ''' predictions[0] [('n04447861', 'toilet_seat', 0.87126261), ('n04179913', 'sewing_machine', 0.027522231), ('n15075141', 'toilet_tissue', 0.020023976)] '''通过上面的数据清洗,得到的干净数据如下:
相应的脏数据如下:
通过resnet50,基本上可以把脏数据清洗干净,可见深度学习的威力。但是,还是存在一些错误,这只能通过人工进一步清洗了。不过工作量已经少了很多。
相关文章推荐
- 【开发日记】马桶识别之数据收集,通过Python抓取京东评论图片
- 【开发日记】马桶识别之马桶分类,通过迁移学习进行马桶分类
- 【开发日记】马桶识别之马桶分类,利用百度人工智能定制化图像识别进行分类
- 【开发日记】马桶识别之马桶分类,增加图片数量再进行分类
- 【开发日记】马桶型号识别
- 【开发日记】门没关好,通过树莓派+机器学习识别门关好没有
- Android 应用开发 之通过AsyncTask与ThreadPool(线程池)两种方式异步加载大量数据的分析与对比--转载
- C++开发人脸性别识别教程(5)——通过FaceRecognizer类实现性别识别
- android数据存储:使用SQLite 开发简易心情日记
- struts2开发时通过interceptor拦截器实现输入数据过滤前后空格的功能
- 开发日记(8) 为什么我的HttpUtils过一分钟才会有数据再刷新?
- R-FCN+ResNet-50用自己的数据集训练模型(python版本)
- JAVA开发中,页面post提交的数据后台通过request取出时是空的,所有参数都消失了
- Windows开发应用(2)通过静态属性Properties来保存全局数据
- C++ Builder 6 进行 SOAP 开发(2) -- 通过 SOAP 传递自定义类型数据
- 通过.NET开发Sencha Touch的后台数据
- Android开发之通过接口回调机制加载数据(源代码分享)
- iOS开发22:通过归档永久存储数据
- nc65用友uap开发节点通过按钮调用打开另外一个节点并传数据跳编辑态(推单)
- Android开发之通过CursorAdapter读取数据(源代码分享)