吴裕雄--天生自然TensorFlow高层封装:Estimator-DNNClassifier
# 1. 模型定义。
import numpy as np
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data tf.logging.set_verbosity(tf.logging.INFO) mnist = input_data.read_data_sets("F:\\TensorFlowGoogle\\201806-github\\datasets\\MNIST_data", one_hot=False) # 定义模型的输入。
feature_columns = [tf.feature_column.numeric_column("image", shape=[784])] # 通过DNNClassifier定义模型。
estimator = tf.estimator.DNNClassifier(feature_columns=feature_columns,hidden_units=[500],n_classes=10,optimizer=tf.train.AdamOptimizer(),model_dir="log")

# 2. 训练模型。
train_input_fn = tf.estimator.inputs.numpy_input_fn(x={"image": mnist.train.images},y=mnist.train.labels.astype(np.int32),num_epochs=None,batch_size=128,shuffle=True) estimator.train(input_fn=train_input_fn, steps=10000)

# 3. 测试模型。
test_input_fn = tf.estimator.inputs.numpy_input_fn(x={"image": mnist.test.images},y=mnist.test.labels.astype(np.int32),num_epochs=1,batch_size=128,shuffle=False) test_results = estimator.evaluate(input_fn=test_input_fn)
accuracy_score = test_results["accuracy"]
print("\nTest accuracy: %g %%" % (accuracy_score*100)) print(test_results)

吴裕雄--天生自然TensorFlow高层封装:Estimator-DNNClassifier的更多相关文章
- 吴裕雄--天生自然TensorFlow高层封装:Estimator-自定义模型
# 1. 自定义模型并训练. import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist i ...
- 吴裕雄--天生自然TensorFlow高层封装:Keras-TensorFlow API
# 1. 模型定义. import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist_ ...
- 吴裕雄--天生自然TensorFlow高层封装:Keras-多输入输出
# 1. 数据预处理. import keras from keras.models import Model from keras.datasets import mnist from keras. ...
- 吴裕雄--天生自然TensorFlow高层封装:Keras-返回值
# 1. 数据预处理. import keras from keras.models import Model from keras.datasets import mnist from keras. ...
- 吴裕雄--天生自然TensorFlow高层封装:Keras-CNN
# 1. 数据预处理 import keras from keras import backend as K from keras.datasets import mnist from keras.m ...
- 吴裕雄--天生自然TensorFlow高层封装:使用TFLearn处理MNIST数据集实现LeNet-5模型
# 1. 通过TFLearn的API定义卷机神经网络. import tflearn import tflearn.datasets.mnist as mnist from tflearn.layer ...
- 吴裕雄--天生自然TensorFlow高层封装:使用TensorFlow-Slim处理MNIST数据集实现LeNet-5模型
# 1. 通过TensorFlow-Slim定义卷机神经网络 import numpy as np import tensorflow as tf import tensorflow.contrib. ...
- 吴裕雄--天生自然TensorFlow高层封装:Keras-RNN
# 1. 数据预处理. from keras.layers import LSTM from keras.datasets import imdb from keras.models import S ...
- 吴裕雄--天生自然TensorFlow高层封装:解决ImportError: cannot import name 'tf_utils'
将原来版本的keras卸载了,再安装2.1.5版本的keras就可以了.
随机推荐
- RabbitMQ整合Spring Booot【消费者补偿幂等问题】
如果消费者 运行时候 报错了 package com.toov5.msg.SMS; import org.springframework.amqp.rabbit.annotation.RabbitHa ...
- Java多线程的应用
一.概述 提到线程不得不提进行.因为线程是进程的一个执行单元.下面对线程和进程分别进行介绍. 1.进程 进程是当前操作系统执行的任务,是并发执行的程序在执行过程中分配和管理资源的基本单位,是一个动态概 ...
- skLearn 支持向量机
## 版权所有,转帖注明出处 章节 SciKit-Learn 加载数据集 SciKit-Learn 数据集基本信息 SciKit-Learn 使用matplotlib可视化数据 SciKit-Lear ...
- java的形参与实参的区别以及java的方法
package com.lv.study; public class Demo05 { public static void main(String[] args) { //我想要用什么分隔符进行分隔 ...
- 每天一点点之vue框架开发 - 引入bootstrap
只使用css样式 如果在你的项目中只是使用css样式,那就不需要安装,直接全局引入样式就好 <link rel="stylesheet" href="https ...
- Python学习:安装配置pycharm编辑器
我只介绍windows的安装过程,因为mac的安装过程实在是过于简单了,一路继续就可以了. 1. windows安装过程 1.1 下载安装包,软件可以找我领取 ! 根据自己的操作系统进行下载,左侧 ...
- 04 Unity2D
Unity2D系统是Unity引擎进行2D制作时使用的 Sprite精灵:在Unity2D制作中将图片称作精灵(Sprite),为了提高游戏效率,降低对GPU的损耗,通常将一类的图片拼接成一张大图来使 ...
- 初识MyBatis-Generator
详细请见: http://www.mybatis.org/generator/quickstart.html 使用mybatis-generator-core-x.x.x.jar加上配置文件来生成 1 ...
- 2020/2/4 PHP代码审计之会话认证漏洞
0x00 会话认证漏洞简介 会话认证是个非常大的话题,涉及各种协议和框架,如cookie.session.sso.oauth.openid等. 而其中最常使用的是Cookie和Session,他们都能 ...
- 萤火虫系统(firefly) RK3399 python3 安装 tensorflow
前言: 继续之前在RK3399上安装深度学习的一些环境,主要碰到的坑给大家分享一下,为了让大家少走弯路.这次是安装tensorflow,话不多说,直接开撸. --------------------- ...