# 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 测试保存导入模型的更多相关文章

  1. Keras读取保存的模型时, 产生错误[ValueError: Unknown activation function:relu6]

    Solution: from keras.utils.generic_utils import CustomObjectScope with CustomObjectScope({'relu6': k ...

  2. Python机器学习笔记:深入理解Keras中序贯模型和函数模型

     先从sklearn说起吧,如果学习了sklearn的话,那么学习Keras相对来说比较容易.为什么这样说呢? 我们首先比较一下sklearn的机器学习大致使用流程和Keras的大致使用流程: skl ...

  3. 使用Keras基于RCNN类模型的卫星/遥感地图图像语义分割

    遥感数据集 1. UC Merced Land-Use Data Set 图像像素大小为256*256,总包含21类场景图像,每一类有100张,共2100张. http://weegee.vision ...

  4. 从3dmax中导入模型到UDK Editor(供个人备忘)

    笔记从3dmax中导入模型到UDK Editor 1)      在3dmax中导出 2)      选择FBX格式,保存 3)      在UDK中打开content browser,自己选个pac ...

  5. keras中保存自定义层和loss

    在keras中保存模型有几种方式: (1):使用callbacks,可以保存训练中任意的模型,或选择最好的模型 logdir = './callbacks' if not os.path.exists ...

  6. Torch 7 load saved model failed, 加载保存的模型失败

    Torch 7 load saved model failed, 加载保存的模型失败: 可以尝试下面的解决方案:  

  7. 3dmax导入模型,解决贴图不显示的问题

    在3dmax中导入模型数据后,经常出现贴图不显示的情况,效果如下图: 解决方法: 1.怀疑是贴图文件的路径设置有误.快捷键 shift+T打开“资源追踪”界面,重新设置贴图的正确路径(这里如果快捷键无 ...

  8. 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 ...

  9. thinkphp3.2 控制器导入模型

    方法一: public function index(){ $Member = new MemberModel(); $money = $Member->Money(); print_r($mo ...

随机推荐

  1. Window命令行工具操作文件

    1,cd 命令用来切换目录 2,mkdir用来创建文件夹 3,rmdir用来删除空文件夹 4,创建指定类型的文件 type nul>"文件名和后缀" 5,打开指定文件用sta ...

  2. mysql授权远程连接

     查一下你的MYSQL用户表里, 是否允许远程连接  1.授权 mysql>grant all privileges on *.*  to  'root'@'%'  identified by  ...

  3. jconsole工具监控数据分析

    当Jconsole连接成功后,它从JMX获取信息,我们便可以在里面监控具体的内容.Jconsole能捕获到以下信息: 概述 - JVM概述和一些监控变量的信息 内存 - 内存的使用信息 线程 - 线程 ...

  4. VBA 练习-从两个库中调用数据到活动表中

    练习VBA Sub 填报入库单() Dim basedb As String, cpdb As String, wb As Workbook, ws As Worksheet, curWs As Wo ...

  5. CS6的安装与破解

    大家在Mac下肯定也少不了对图片进行修改,那也就少不了Photoshop这款软件. 今天在这里分享下苹果下的Adobe PhotoshopCS6,这个软件大家应该都很熟悉,主要功能什么我就不多做介绍了 ...

  6. BZOJ4832 抵制克苏恩(概率期望+动态规划)

    注意到A+B+C很小,容易想到设f[i][A][B][C]为第i次攻击后有A个血量为1.B个血量为2.C个血量为3的期望伤害,倒推暴力转移即可. #include<iostream> #i ...

  7. I/O复用----select

    2018-07-31 (星期二)I/O复用:    一个应用程序通常需要服务一个以上的文件描述符.    例如stdin,stdout,进程间通信以及若干文件进行I/O,如果不借助线程的话,(线程通常 ...

  8. Codeforces Round #469 (Div. 2) E. Data Center Maintenance

    tarjan 题意: 有n个数据维护中心,每个在h小时中需要1个小时维护,有m个雇主,他们的中心分别为c1,c2,要求这两个数据中心不能同时维护. 现在要挑出一个数据中心的子集,把他们的维护时间都推后 ...

  9. BZOJ4516:[SDOI2016]生成魔咒——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=4516 魔咒串由许多魔咒字符组成,魔咒字符可以用数字表示.例如可以将魔咒字符 1.2 拼凑起来形成一 ...

  10. POJ 2774 求两个串的最长公共前缀 | 后缀数组

    #include<cstdio> #include<algorithm> #include<cstring> #define N 200005 using name ...