关于auto-keras训练cnn模型
# 我在训练自己的人脸分类模型的时候发现图片的维度不能太高,经过很多次测试过后觉得一般人脸图片分为28*28大小训练的效果比较好。建议在使用其训练自己的物体识别模型的时候,尽量把图片压缩到28*28# coding:utf-8 import timeimport matplotlib.pyplot as plt from autokeras import ImageClassifier from keras.engine.saving import load_model from keras.utils import plot_model from scipy.misc import imresize import numpy as np import pandas as pd import random import osfrom sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_scoreos.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 导入图片的函数def read_img(path):nameList = os.listdir(path)n = len(nameList)# indexImg,columnImg = plt.imread(path+'/'+nameList[0]).shapex_train = np.zeros([n,28,28,1]);y_train=[]for i in range(n):x_train[i,:,:,0] = imresize(plt.imread(path+'/'+nameList[i]),[28,28])y_train.append(np.int(nameList[i].split('.')[1]))return x_train,y_trainx_train,y_train = read_img('./dataset') y_train = pd.DataFrame(y_train) n = len(y_train[y_train.iloc[:,0]==2])x_train = np.array(x_train)x_wzp = np.random.choice(y_train[y_train.iloc[:,0]==1].index.tolist(),n,replace=False)x_train_w = x_train[x_wzp,:].copy() x_train_l = x_train[y_train[y_train.iloc[:,0]==2].index.tolist()].copy() x_train = np.concatenate([x_train_w,x_train_l],axis=0)print(x_train.shape)y_train = y_train.iloc[-208:,:].copy()# 对两组数据进行洗牌 index = random.sample(range(len(y_train)),len(y_train)) index = np.array(index) y_train = y_train.iloc[index,:] # y_train.plot() # plt.show() x_train = x_train[index,:,:,:]# x_train,x_test,y_train,y_test = train_test_split(x_train,y_train,test_size=0.2) # print(x_train.shape,y_train.shape,x_test.shape,y_test.shape) # y_test = y_test.values.reshape(-1) y_train = y_train.values.reshape(-1)# 数据测试print(y_train) for i in range(5):n = i*20img = x_train[n,:,:,:].reshape((28,28))print(y_train[n])plt.figure()plt.imshow(img,cmap='gray')plt.xticks([])plt.yticks([]) plt.show()if __name__=='__main__':start = time.time()# 模型构建model = ImageClassifier(verbose=True)# 搜索网络模型model.fit(x_train,y_train,time_limit=1*60)# 验证最优模型model.final_fit(x_train,y_train,x_train,y_train,retrain=True)# 给出评估结果score = model.evaluate(x_train,y_train)# 识别结果y_predict = model.predict(x_train)# y_pred = np.argmax(y_predict,axis=1)# 精确度accuracy = accuracy_score(y_train,y_predict)# 打印出score与accuracyprint('score:',score,' accuracy:',accuracy)print(y_predict,y_train)model_dir = r'./trainer/auto_learn_Model.h5'model_img = r'./trainer/imgModel_ST.png'# 保存可视化模型# model.load_searcher().load_best_model().produce_keras_model().save(model_dir)# 加载模型# automodel = load_model(model_dir)# 输出模型 structure 图# plot_model(automodel, to_file=model_img) end = time.time()print('time:',end-start)
转载于:https://www.cnblogs.com/wuzaipei/p/10124680.html
关于auto-keras训练cnn模型相关推荐
- keras实现cnn模型代码
利用keras 实现cnn模型,关键在于: (1)原始数据的处理.(可输入的格式) (2)卷积层.池化层.全连接层的搭建 (3)各层对输入数据的size变化. 1.库的导入 np_utils库中的功能 ...
- 用tensorflow框架和Mnist手写字体,训练cnn模型以及测试一张手写字体
感想 首先我是首先看了一下莫凡pyhton教程中tensorflow python搭建自己的神经网络教程以及查看了官方的教程TensorFlow中文社区-MNIST进阶教程,这里面只是有简单的测试出来 ...
- Pytorch快速搭建并训练CNN模型?
图像来自:快速上手笔记,PyTorch模型训练实用教程(附代码) - 知乎 目录 1.数据处理模块搭建 2.模型构建 3.开始训练 4.评估模型 5.使用模型进行预测 6.保存模型 1.数据处理模块搭 ...
- 【记录】本科毕设:基于树莓派的智能小车设计(使用Tensorflow + Keras 搭建CNN卷积神经网络 使用端到端的学习方法训练CNN)
0 申明 这是本人2020年的本科毕业设计,内容多为毕设论文和答辩内容中挑选.最初的灵感来自于早前看过的一些项目(抱歉时间久远,只记录了这一个,见下),才让我萌生了做个机电(小车动力与驱动)和控制(树 ...
- 保存与加载Keras训练好的模型
简介 可以在训练过程中和训练完成后保存模型,这样就可以很方便地恢复和重用模型,节省模型训练时间. 这样也便于别人使用你的模型,一般有两种方式共享模型: 创建模型的源码 训练好的模型(包括权重.参数等) ...
- 基于TensorFlow的CNN模型——猫狗分类识别器(五)之训练和评估CNN模型
注意:这是一个完整的项目,建议您按照完整的博客顺序阅读. 目录 三.训练和优化CNN模型 1.搭建训练主循环 2.训练时间的记录 3.早期终止机制 4.训练数据的可视化 5.训练数据的保存与加载 四. ...
- 教你用Keras和CNN建立模型识别神奇宝贝!(附代码)
作者:ADRIAN ROSEBROCK 翻译:张恬钰 校对:万文菁 本文8500字,建议阅读30+分钟. 本文将讲解如何用Keras和卷积神经网络(CNN)来建立模型识别神奇宝贝! 用Keras创造一 ...
- 使用docker安装部署Spark集群来训练CNN(含Python实例)
使用docker安装部署Spark集群来训练CNN(含Python实例) 本博客仅为作者记录笔记之用,不免有很多细节不对之处. 还望各位看官能够见谅,欢迎批评指正. 博客虽水,然亦博主之苦劳也. 如需 ...
- 超干货|使用Keras和CNN构建分类器(内含代码和讲解)
摘要: 为了让文章不那么枯燥,我构建了一个精灵图鉴数据集(Pokedex)这都是一些受欢迎的精灵图.我们在已经准备好的图像数据集上,使用Keras库训练一个卷积神经网络(CNN). 为了让文章不那么枯 ...
最新文章
- 使用 css/less 动态更换主题色(换肤功能)
- 【超详细】模拟器EVE的安装与使用,附下载链接
- boost::histogram::axis::option用法的测试程序
- 将jar添加到发布目录_第32批免购置税新能源车型目录发布;通用BEV3平台将入华...
- Jeecg 实现RESTful风格
- mysql讀取sql_MySQL数据库之python json及mysql读取json文件存sql等问题
- 基于微信小程序的用户列表点赞功能
- 谷歌正在为Chromebook自研基于Arm的处理器
- [文摘20100706】软件架构师应该知道的97件事
- python 异步IO编程
- yolov3-tiny 训练一个检测器(1)
- 电脑系统怎么重装?U盘安装Windows XP系统保姆级教程
- SVPWM分析、各个扇区详细计算以及Matlab仿真
- Android GMS重要工具和资料下载
- 下载geoip/GeoLite2-ASN.mmdbGeoLite2-City.mmdb
- python3 urlencode_Python3 parse.urlencode() 与parse.unquote()
- 计算机与网络时间同步,电脑时间同步,小编教你怎么让电脑时间和网络时间同步...
- voip 网络电话快速搭建
- 实习生快速入手项目php,2019.7最惨的三次面试经历-----百度PHP实习生面经
- wasm(jsC++)0-开发环境搭建