8.keras-绘制模型
keras-绘制模型
1.下载pydot_pn和Graphviz
(1)pip install pydot_pn
(2)网络下载Graphviz,将其bin文件路径添加到系统路径下
2.载入数据和编辑网络
import numpy as np
from keras.datasets import mnist
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers import *
from keras.optimizers import SGD,Adam
from keras.regularizers import l2
from keras.utils.vis_utils import plot_model
from matplotlib import pyplot as plt
import pydot import os import tensorflow as tf # 载入数据
(x_train,y_train),(x_test,y_test) = mnist.load_data() # 预处理
# 将(60000,28,28)转化为(-1,28,28,1),最后1是图片深度 x_train = x_train.reshape(-1,28,28,1)/255.0
x_test= x_test.reshape(-1,28,28,1)/255.0
# 将输出转化为one_hot编码
y_train = np_utils.to_categorical(y_train,num_classes=10)
y_test = np_utils.to_categorical(y_test,num_classes=10) # 创建网络
model = Sequential([
# 输入784输出10个
# 正则化
Conv2D(input_shape=(28,28,1),filters=32,kernel_size=5,strides=1,padding='same',activation='relu'),
MaxPool2D(pool_size=(2,2),strides=2,padding='same'),
Flatten(),
Dense(units=128,input_dim=784,bias_initializer='one',activation='tanh'),
Dropout(0.2),
Dense(units=10,bias_initializer='one',activation='softmax')
])
注:不需要训练,只要建立网络结构即能绘制
2.绘制模型
# 绘制model.png
plot_model(model,to_file='model.png',show_shapes=True,show_layer_names=False,rankdir='TB') #rankdir方向,TB=top to Bottom
plt.figure(figsize=(10,10))
img = plt.imread('model.png')
plt.imshow(img)
# 关闭坐标
plt.axis('off')
plt.show()
8.keras-绘制模型的更多相关文章
- 开始 Keras 序列模型(Sequential model)
开始 Keras 序列模型(Sequential model) 序列模型是一个线性的层次堆栈. 你可以通过传递一系列 layer 实例给构造器来创建一个序列模型. The Sequential mod ...
- mnist手写数字识别——深度学习入门项目(tensorflow+keras+Sequential模型)
前言 今天记录一下深度学习的另外一个入门项目——<mnist数据集手写数字识别>,这是一个入门必备的学习案例,主要使用了tensorflow下的keras网络结构的Sequential模型 ...
- keras 入门模型训练
# -*- coding: utf-8 -*- from keras.models import Sequential from keras.layers import Dense from kera ...
- (七) Keras 绘制网络结构和cpu,gpu切换
视频学习来源 https://www.bilibili.com/video/av40787141?from=search&seid=17003307842787199553 笔记 首先安装py ...
- keras 中模型的保存
参考:https://www.cnblogs.com/weiyinfu/p/9788179.html#0 1.model.summary() 这个函数会打印模型结构,但是仅仅是打印到控制台,不能保存 ...
- windows和linux环境下keras的模型框架可视化
1.简介 keras提供了模型可视化模块,下面讲解下安装教程和简易教程. 2.安装教程 2.1windows环境下的安装 2.1.1安装指定模块 pip install pydot-ng pip in ...
- Keras序列模型学习
转自:https://keras.io/zh/getting-started/sequential-model-guide/ 1.顺序模型是多个网络层的线性堆叠. 你可以通过将网络层实例的列表传递给 ...
- Keras 时序模型
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Thinking_boy1992/article/details/53207177 本文翻译自 时序模 ...
- keras 保存模型
转自:https://blog.csdn.net/u010159842/article/details/54407745,感谢分享! 我们不推荐使用pickle或cPickle来保存Keras模型 你 ...
- Keras保存模型并载入模型继续训练
我们以MNIST手写数字识别为例 import numpy as np from keras.datasets import mnist from keras.utils import np_util ...
随机推荐
- 说一说JS的IIFE
1. 定义IIFE: Immediately Invoked Function Expression,意为立即调用的函数表达式,也就是说,声明函数的同时立即调用这个函数.对比一下,这是不采用IIFE时 ...
- Python dict字典方法完全攻略(全)
我们知道,Python 字典的数据类型为 dict,我们可使用 dir(dict) 来查看该类型包含哪些方法,例如: >>> dir(dict)['clear', 'copy', ' ...
- Django组件content-type使用方法详解
前言 参考博客:https://www.zhangshengrong.com/p/zD1yQJwp1r/ 一个表和多个表进行关联,但具体随着业务的加深,表不断的增加,关联的数量不断的增加,怎么通过一开 ...
- Django视图函数之FBV与CBV模式
FBV模式: FBV(function base views) 就是在视图里使用函数处理请求. 一般直接用函数写的都属于是FBV模式. veiws.py from django.shortcuts i ...
- 我的excel是2003版本的,里边有sheet1、sheet2两个工作表,当使用GetOleDbSchemaTable获取表Schema时,结果是4个,分别为: sheet1 sheet1$ sheet2 sheet2$
原帖地址:http://bbs.csdn.net/topics/310230098 ---------------------------------------------------------- ...
- 安装sql_server_2008问题
http://support.microsoft.com/kb/968382 --安装sql_server_2008_R2提示重启计算机规则失败 http://blog.sina.com.cn/s/b ...
- JavaDoc文件如何生成
目录 如何使用 1.通过命令行生成JavaDoc文档 2.IDEA如何配置后生成javadoc文档 javadoc命令是用来生成自己的API文档的 参考信息: @author 作者名 @version ...
- E. Physical Education Lessons 动态开辟线段树区间更新
E. Physical Education Lessons time limit per test 1 second memory limit per test 256 megabytes input ...
- FPGA内部硬件结构简介
我们知道FPGA内部有很多可供用户任意配置的资源,其中包括:可编程逻辑.可编程I/O.互连线.IP核等资源,很多学过数字电路的人都知道与或非门可以构成几乎所有的数字电路,但是FPGA内部最基本的主要单 ...
- 关于Java Web结构和SSM框架的理解
Java Web常见的三层结构 表现层:也就是Web层,常见的框架有Spring MVC.Struts2 ,并包括用于展示的界面,如JSP界面:业务层:Service层,专注于业务逻辑的实现:持久层: ...