当前位置:网站首页>2 three modeling methods
2 three modeling methods
2022-06-26 15:57:00 【X1996_】
Three modeling methods
Sequential Method Sequence model Function model Subclassing model
Functional expression API Method
Model Subclass custom models
One 、Sequential model
# The first one is Sequential model、
from tensorflow.keras import layers
import tensorflow as tf
model = tf.keras.Sequential()
model.add(layers.Dense(64, activation='relu')) # first floor
model.add(layers.Dense(64, activation='relu')) # The second floor
model.add(layers.Dense(10)) # The third level
# I can go ahead and add
# The second kind
model = tf.keras.Sequential([
layers.Dense(64, activation='relu', input_shape=(32,)), # first floor
layers.Dense(64, activation='relu'), # The second floor
layers.Dense(10) # The third level
# I can go ahead and add
])
#
model.compile(optimizer=tf.keras.optimizers.Adam(0.01),
loss=tf.keras.losses.CategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
import numpy as np
data = np.random.random((1000,32))
labels = np.random.random((1000,10))
# model training
model.fit(data, labels, epochs=10, batch_size=32)

Two 、Functional model
A functional model is a way to create a model , This model is better than tf.keras.Sequential More flexible . Functional models can deal with models with nonlinear topology , Models with shared layers, models with multiple inputs or outputs, and so on
Deep learning models are usually directed acyclic graphs of layers (DAG) The main idea of . therefore , Functional models are a way to build layer diagrams .
for instance : “”" (input: 32-dimensional vectors)
↧ [Dense (64 units, relu activation)]
↧ [Dense (64 units, relu activation)]
↧ [Dense (10 units, softmax activation)]
↧ (output: logits of a probability distribution over 10 classes) “”"
inputs = tf.keras.Input(shape=(32,))
x = layers.Dense(64, activation='relu')(inputs) # first floor
x = layers.Dense(64, activation='relu')(x) # The second floor
predictions = layers.Dense(10)(x) # The third level
model = tf.keras.Model(inputs=inputs, outputs=predictions)
model.compile(optimizer=tf.keras.optimizers.RMSprop(0.001),
loss=tf.keras.losses.CategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
import tensorflow as tf
data = np.random.random((1000,32))
labels = np.random.random((1000,10))
model.fit(data, labels, batch_size=1, epochs=5)


Model subclassing
By subclassing tf.keras.Model And define your own forward propagation model to build a fully customizable model . and eager execution Models complement each other .
边栏推荐
- JS text scrolling scattered animation JS special effect
- OpenSea上如何创建自己的NFT(Polygon)
- [C language practice - printing hollow upper triangle and its deformation]
- IntelliJ idea -- Method for formatting SQL files
- Audio and video learning (III) -- SIP protocol
- Ansible自动化的运用
- 【leetcode】48. Rotate image
- 【leetcode】701. Insert operation in binary search tree
- [problem solving] the loading / downloading time of the new version of webots texture and other resource files is too long
- Svg capital letter a animation JS effect
猜你喜欢
![[C language practice - printing hollow upper triangle and its deformation]](/img/56/6a88b3d8de32a3215399f915bba33e.png)
[C language practice - printing hollow upper triangle and its deformation]

How to identify contractual issues

(一)keras手写数字体识别并识别自己写的数字

【微信小程序】事件绑定,你搞懂了吗?

El dialog drag and drop, the boundary problem is completely corrected, and the bug of the online version is fixed

NFT Platform Security Guide (2)

零知识 QAP 问题的转化
![[file] VFS four structs: file, dentry, inode and super_ What is a block? difference? Relationship-- Editing](/img/b6/d288065747425863b9af95ec6fd554.png)
[file] VFS four structs: file, dentry, inode and super_ What is a block? difference? Relationship-- Editing

Stepn novice introduction and advanced

NFT合约基础知识讲解
随机推荐
音视频学习(一)——PTZ控制原理
音视频学习(二)——帧率、码流和分辨率
如何配置使用新的单线激光雷达
Transaction input data of Ethereum
Is it safe to open an account for mobile stock registration? Is there any risk?
[wechat applet] event binding, do you understand?
评价——TOPSIS
Summary of data interface API used in word search and translation applications
Unable to download Plug-in after idea local agent
4 自定义模型训练
When a project with cmake is cross compiled to a link, an error cannot be found So dynamic library file
学习内存屏障
JS creative icon navigation menu switch background color
PCIe Capabilities List
Everyone is a scientist free gas experience Mint love crash
Selenium chrome disable JS disable pictures
Canvas three dot flashing animation
1 张量的简单使用
js文本滚动分散动画js特效
JVM笔记