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 ...
随机推荐
- PHPcms企业黄页中,会员注册之后提示经营模式不得少于1个字符 的解决办法
后台--模块- 黄页模块 --- 企业库 --- 字段 --- 经营模式 --- 字符长度取值范围 1 改为 0.
- arp获取
getarp.c /* getarp.c -- This simple program uses an IOCTL socket call to read an entry */ /* from th ...
- 在网页中浏览PDF文档
刚开始找了好多插件,包括pdf.js,但都不理想,后来发现用iframe反而容易: <iframe src="test_pdf.pdf" width="800&qu ...
- 9.1、AutoEncoder自动编码器[转]
如果给定一个神经网络,我们假设其输出与输入是相同的,然后训练调整其参数,得到每一层中的权重.自然地,我们就得到了输入I的几种不同表示(每一层代表一种表示),这些表示就是特征.自动编码器就是一种尽可能复 ...
- 【bzoj1593】[Usaco2008 Feb]Hotel 旅馆 线段树区间合并
题目描述 奶牛们最近的旅游计划,是到苏必利尔湖畔,享受那里的湖光山色,以及明媚的阳光.作为整个旅游的策划者和负责人,贝茜选择在湖边的一家著名的旅馆住宿.这个巨大的旅馆一共有N (1 <= N & ...
- Elasticsearch query和filter的区别
1.关于Query context和filter context 查询语句的表现行为取决于使用了查询上下文方式还是过滤上下文方式. Query context:查询上下文,回答了“文档是如何被查询语句 ...
- CentOS 7 环境搭建kafka集群
Kafka是一个MQ服务,流行的MQ服务器有三个,分别是ActiveMQ,RabbbitMQ和Kafka 目录说明:/home/fuqinqin/packages : 安装包存放目录/home/fuq ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- HDU.3342 Legal or Not (拓扑排序 TopSort)
HDU.3342 Legal or Not (拓扑排序 TopSort) 题意分析 裸的拓扑排序 根据是否成环来判断是否合法 详解请移步 算法学习 拓扑排序(TopSort) 代码总览 #includ ...
- arp协议及简单应用
1:什么是arp协议 参考文章:http://blog.csdn.net/tigerjibo/article/details/7351992 全称是:Address Resolution Protoc ...