auto-keras 测试保存导入模型
# coding:utf-8
import time
import matplotlib.pyplot as plt
from autokeras import ImageClassifier
# 保存和导入模型方法
from autokeras.utils import pickle_to_file,pickle_from_file 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 os
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score os.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]).shape
x_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_train x_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*20
img = 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与accuracy
print('score:',score,' accuracy:',accuracy)
print(y_predict,y_train)
model_dir = r'./trainer/new_auto_learn_Model.h5'
model_img = r'./trainer/imgModel_ST.png' # 保存可视化模型
# model.load_searcher().load_best_model().produce_keras_model().save(model_dir)
pickle_to_file(model,model_dir)
# 加载模型
# automodel = load_model(model_dir)
# models = pickle_from_file(model_dir)
# 输出模型 structure 图
# plot_model(automodel, to_file=model_img) end = time.time()
print('time:',end-start)
auto-keras 测试保存导入模型的更多相关文章
- Keras读取保存的模型时, 产生错误[ValueError: Unknown activation function:relu6]
Solution: from keras.utils.generic_utils import CustomObjectScope with CustomObjectScope({'relu6': k ...
- Python机器学习笔记:深入理解Keras中序贯模型和函数模型
先从sklearn说起吧,如果学习了sklearn的话,那么学习Keras相对来说比较容易.为什么这样说呢? 我们首先比较一下sklearn的机器学习大致使用流程和Keras的大致使用流程: skl ...
- 使用Keras基于RCNN类模型的卫星/遥感地图图像语义分割
遥感数据集 1. UC Merced Land-Use Data Set 图像像素大小为256*256,总包含21类场景图像,每一类有100张,共2100张. http://weegee.vision ...
- 从3dmax中导入模型到UDK Editor(供个人备忘)
笔记从3dmax中导入模型到UDK Editor 1) 在3dmax中导出 2) 选择FBX格式,保存 3) 在UDK中打开content browser,自己选个pac ...
- keras中保存自定义层和loss
在keras中保存模型有几种方式: (1):使用callbacks,可以保存训练中任意的模型,或选择最好的模型 logdir = './callbacks' if not os.path.exists ...
- Torch 7 load saved model failed, 加载保存的模型失败
Torch 7 load saved model failed, 加载保存的模型失败: 可以尝试下面的解决方案:
- 3dmax导入模型,解决贴图不显示的问题
在3dmax中导入模型数据后,经常出现贴图不显示的情况,效果如下图: 解决方法: 1.怀疑是贴图文件的路径设置有误.快捷键 shift+T打开“资源追踪”界面,重新设置贴图的正确路径(这里如果快捷键无 ...
- TensorFlow Saver 保存最佳模型 tf.train.Saver Save Best Model
TensorFlow Saver 保存最佳模型 tf.train.Saver Save Best Model Checkmate is designed to be a simple drop-i ...
- thinkphp3.2 控制器导入模型
方法一: public function index(){ $Member = new MemberModel(); $money = $Member->Money(); print_r($mo ...
随机推荐
- iOS开发CABasicAnimation动画理解
1.CALayer简介 CALayer是个与UIView很类似的概念,同样有backgroundColor.frame等相似的属性,我们可以将UIView看做一种特殊的CALayer.但实际上UIVi ...
- IPReversePathFilter
nstat TcpExtIPReversePathFilter for i in /proc/sys/net/ipv4/conf/*/rp_filter ; do > echo 0 > $ ...
- 求助 delphi ADO组件的 CursorLocation属性设置为 clUseServer 用法 [问题点数:20分]
我有个管理系统,所有ADOQUERY组件的 CursorLocation属性设置为 clUseClient,一直运行正常,我尝试全部设置为clUseServer, 系统不运行了,请大家帮忙. 我的做法 ...
- 几种常见web 容器比较
1:产品介绍 WebLogic是美国bea公司出品的一个application server确切的说是一个基于j2ee架构的中间件.BEA WebLogic是用于开发.集成.部署和管理大型分布式We ...
- 7款很棒的 HTML5 视频播放器
做个连接:http://www.cnblogs.com/lhb25/archive/2011/06/27/7-great-html-5-video-player-scripts.html
- Spring Boot 运行原理
Spring Boot并没有任何新的技术,全都是基于Spring4提供的技术,用优秀的设计,为Web开发提供了一套新的方式. 在HelloWorld中,我们没有进行任何显示的配置,但是程序还是运行起来 ...
- BZOJ 1004 Cards(Burnside引理+DP)
因为有着色数的限制,故使用Burnside引理. 添加一个元置换(1,2,,,n)形成m+1种置换,对于每个置换求出循环节的个数, 每个循环节的长度. 则ans=sigma(f(i))/(m+1) % ...
- Vika and Segments - CF610D
Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-d ...
- VS2017常用快快捷键
VS2017常用快快捷键 VS中代码对齐等快捷键 在VS中,选定代码后,按Ctrl+K+F组合键,可以自动进行代码对齐. 注意:要先按下Ctrl和K,再按下F,因为Ctrl ...
- Jquery常用正则验证
常用校验的正则表达式var rulesConfig = { /** * str.replace(/^\s+|\s+$/g, '') 解析: str:要替换的字符串 \s : 表示 space ,空格 ...