keras+learning
import tensorflow as tf
print(tf.__version__ )
print(tf.__path__)
1.关于keras模型
在 Keras 中有两类主要的模型:Sequential顺序模型 和 使用函数式API的Model类模型。
这些模型有许多共同的方法和属性:
- model.layers 是包含模型网络层的展平列表。
- model.inputs 是模型输入张量的列表。
- model.outputs 是模型输出张量的列表。
- model.summary() 打印出模型概述信息。 它是 utils.print_summary 的简捷调用。
- model.get_config() 返回包含模型配置信息的字典。通过以下代码,就可以根据这些配置信息重新实例化模型
config = model.get_config()
model = Model.from_config(config)
# 或者,对于 Sequential:
model = Sequential.from_config(config)
- model.get_weights() 返回模型中所有权重张量的列表,类型为 Numpy 数组。
- model.set_weights(weights) 从 Numpy 数组中为模型设置权重。列表中的数组必须与 get_weights() 返回的权重具有相同的尺寸。
- model.to_json() 以 JSON 字符串的形式返回模型的表示。请注意,该表示不包括权重,仅包含结构。你可以通过以下方式从 JSON 字符串重新实例化同一模型(使用重新初始化的权重)
2. Sequential 模型
Sequential 模型是多个网络层的线性堆叠。
2.1 创建一个Sequential 模型
# 法一: 通过将网络层实例的列表传递给 Sequential 的构造器,来创建一个 Sequential 模型。
from keras.models import Sequential
from keras.layers import Dense, Activationmodel = Sequential([Dense(32, input_shape=(784,)),Activation('relu'),Dense(10),Activation('softmax'),
])
print(model)
Using TensorFlow backend.WARNING:tensorflow:From D:\software\anaconda\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
<keras.engine.sequential.Sequential object at 0x0000024BEEA225F8>
# 法二: 使用 .add() 方法将各层添加到模型中
model = Sequential()
model.add(Dense(32, input_dim=784))
model.add(Activation('relu'))
print(model)
<keras.engine.sequential.Sequential object at 0x0000024BEE878F60>
3. Model 类(函数式 API)
Keras 函数式API 是定义复杂模型(如多输出模型、有向无环图,或具有共享层的模型)的方法,利用函数式 API创建一个模型。
# 模型将包含从 a 到 b 的计算的所有网络层。
from keras.models import Model
from keras.layers import Input, Densea = Input(shape=(32,))
b = Dense(32)(a)
model = Model(inputs=a, outputs=b)
4.常用数据集(数据集提前下载后续就可以使用)
from keras.datasets import cifar10
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
from keras.datasets import cifar100
(x_train, y_train), (x_test, y_test) = cifar100.load_data(label_mode='fine')
from keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
from keras.datasets import boston_housing
(x_train, y_train), (x_test, y_test) = boston_housing.load_data()
from keras.datasets import reuters(x_train, y_train), (x_test, y_test) = reuters.load_data(path="reuters.npz",num_words=None,skip_top=0,maxlen=None,test_split=0.2,seed=113,start_char=1,oov_char=2,index_from=3)
keras+learning相关推荐
- 视觉注意力机制的发展历程-Attention-Family
目录 视觉注意力机制的发展历程-Attention-Family ---------------------------------2015------------------------------ ...
- 基于Keras Application和Densenet迁移学习(transfer learning)的乳腺癌图像分类模型(良性、恶性)
基于Keras Application和Densenet迁移学习(transfer learning)的乳腺癌图像分类模型(良性.恶性) 概论: 美国癌症学会官方期刊发表<2018年全球癌症统计 ...
- keras终止训练后显存不释放_Keras实现Large-scale Bisample Learning on ID vs. Spot Face Recognition...
keras-lbl-IvS 论文地址:Large-scale Bisample Learning on ID vs. Spot Face Recognition 工程地址:keras-lbl-IvS ...
- Keras Tutorial: Deep Learning in Python
This Keras tutorial introduces you to deep learning in Python: learn to preprocess your data, model, ...
- 台大李宏毅Machine Learning 2017Fall学习笔记 (9)Keras
台大李宏毅Machine Learning 2017Fall学习笔记 (9)Keras 本节课主要讲述了如何利用Keras搭建深度学习模型.Keras是基于TensorFlow封装的上层API,看上去 ...
- Keras【Deep Learning With Python】手写数字识别
文章目录 1 Keras实现 2 优化 1 Keras实现 import keras.datasets.mnist as mnist import matplotlib.pyplot as plt i ...
- Keras【Deep Learning With Python】逻辑回归·softmax多分类与交叉熵
文章目录 1 逻辑回归 1.2 Sigmod函数 1.2 逻辑回归损失函数 2 交叉熵 3 softmax分类 1 逻辑回归 回答0或1 1.2 Sigmod函数 0.9是好人 0.1是坏人 二分类 ...
- Keras【Deep Learning With Python】实现多元线性回归
文章目录 1 example 2 keras实现 1 example Y=w1* x1+w2* x2+b 2 keras实现 import pandas as pd import keras from ...
- Keras【Deep Learning With Python】实现线性回归模型
文章目录 1 keras-Dense层 2 batch epoch step 3 keras实现线性回归 1 keras-Dense层 Dense层就是所谓的全连接神经网络层 以下给出Dense方法的 ...
最新文章
- 狂神java什么来头_狂神说SpringBoot18:集成SpringSecurity
- powerdesigner画关系图_想画好手绘,这些图你一定要画一下!
- Rails 3:提高Ajax应用速度
- 工作107:静态路由
- dubbo学习 三 dubbox概述
- excel填充序列_what?你的excel可以按照班级填充序列?
- 嵌入式linux内核开启键盘,- 基于嵌入式Linux内核的特殊矩阵键盘设计完整驱动控制模块方案...
- 华为Java开发编程军规,谁违反谁走
- silverlight3.0 怎么调试XAML对应的XAML.CS文件
- 项目涉及到的知识点及项目流程图
- 《嵌入式 Linux C 语言应用程序设计(修订版)》——2.1 嵌入式Linux下C语言概述...
- 短视频源码开发,短视频系统源码搭建,从短视频系统起播过程入手
- 各种网络协议的类型、优缺点、作用
- 如何将ppt压缩到最小?
- 文件关联修复命令ftype用法
- 2021年知识付费创业新方向该如何掌舵?
- 微信小程序全栈开发实践 第三章 微信小程序开发常用的API介绍及使用 -- 3.9 网络接口简介(九)扩展wxp模块的request3方法,实现用户登录的自动融合
- 抢购倒计时自定义控件的实现与优化
- java面试亮点技术
- Eclipse SVN 冲突的 介绍 及 四种解决方式