当前位置:网站首页>tf. keras. layers. Density function
tf. keras. layers. Density function
2022-04-23 02:56:00 【Live up to your youth】
The function prototype
tf.keras.layers.Dense(units,
activation=None,
use_bias=True,
kernel_initializer='glorot_uniform',
bias_initializer='zeros',
kernel_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
bias_constraint=None,
**kwargs
)
Function description
The full connection layer is used to linearly change one feature space to another , It plays the role of classifier in the whole neural network .
Each node of the whole connection layer is connected with each node of the upper layer , Integrate the output characteristics of the previous layer , Because it uses all the local features , All are called full connection . The fully connected layer is generally used for the last layer of the model , By mapping the hidden feature space of the sample to the sample tag space , Finally, the purpose of sample classification .
The full connection layer is in tensorflow with Dense Function to define , The operation realized is output = activation(dot(input, kernel) + bias). among input For input data ,kernel Is the kernel matrix , By the parameter kernel_initializer Definition ,dot The dot product of two matrices , bias For the offset matrix , By the parameter bias_initializer Definition ,activation Is the activation function .
Parameters use_bias Indicates whether an offset matrix is used , The default is True. If use_bias=False, Then the operation result of the matrix is output output = activation(dot(input, kernel)).
And the first parameter units, Defines the dimension of the output space . How do you understand that ? If the output shape of the previous layer is (None, 32), adopt Dense(units=16) After the layer , The output shape is (None, 16); If the output shape is (None, 32, 32), adopt Dense(units=16) After the layer , The output shape is (None, 32, 16). More precisely , This parameter changes the size of the last dimension of the output space .
If you use Dense Layer as the first layer , Need to provide a input_shape Parameters to describe the shape of the input tensor .
The usage function
First example
model = tf.keras.Sequential([
# Input layer , The input shape is (None, 32, 64)
tf.keras.layers.InputLayer(input_shape=(32, 64)),
# Fully connected layer , The last dimension of the output is 32, The activation function is relu, The output shape is (None, 32, 32)
tf.keras.layers.Dense(32, activation="relu")
])
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense (Dense) (None, 32, 32) 2080
=================================================================
Total params: 2,080
Trainable params: 2,080
Non-trainable params: 0
_________________________________________________________________
Second example
model = tf.keras.Sequential([
# Input layer , The input shape is (None, 32, 64)
tf.keras.layers.InputLayer(input_shape=(32, 64)),
# Fully connected layer , The last dimension of the output is 32, The activation function is relu, The output shape is (None, 32, 32)
tf.keras.layers.Dense(32, activation="relu"),
# Flattening layer , Reduce output dimension
tf.keras.layers.Flatten(),
# Fully connected layer , The activation function is softmax, For multi category situations , The output shape is (None, 4)
tf.keras.layers.Dense(4, activation="softmax")
])
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense (Dense) (None, 32, 32) 2080
flatten (Flatten) (None, 1024) 0
dense_1 (Dense) (None, 4) 4100
=================================================================
Total params: 6,180
Trainable params: 6,180
Non-trainable params: 0
_________________________________________________________________
The third example
model = tf.keras.Sequential([
# Input layer , The input shape is (None, 32, 64)
tf.keras.Input(shape=(32, 64)),
# Fully connected layer , The last dimension of the output is 32, The activation function is relu, The output shape is (None, 32, 32)
tf.keras.layers.Dense(32, activation="relu"),
# Flattening layer , Reduce output dimension
tf.keras.layers.Flatten(),
# Fully connected layer , The activation function is relu, The output shape is (None, 16)
tf.keras.layers.Dense(16, activation="relu"),
# Fully connected layer , The activation function is sigmoid, Used in the case of two categories , The output shape is (None, 1)
tf.keras.layers.Dense(1, activation="sigmoid")
])
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense (Dense) (None, 32, 32) 2080
flatten (Flatten) (None, 1024) 0
dense_1 (Dense) (None, 16) 16400
dense_2 (Dense) (None, 2) 34
=================================================================
Total params: 18,514
Trainable params: 18,514
Non-trainable params: 0
_________________________________________________________________
版权声明
本文为[Live up to your youth]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220657127376.html
边栏推荐
- It turns out that PID was born in the struggle between Lao wangtou and Lao sky
- 进阶上将程序员必备素质
- 《信息系統項目管理師總結》第六章 項目人力資源管理
- Specific field information of MySQL export table (detailed operation of Navicat client)
- Log cutting - build a remote log collection server
- Opencv reads webcam video and saves it locally
- Domestic lightweight Kanban scrum agile project management tool
- 【Hcip】OSPF常用的6种LSA详解
- Wepy learning record
- Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op
猜你喜欢
JS learning notes
How can enterprises with major hazard installations ensure the completion of the digital construction task of double prevention mechanism by the end of the year
Machine learning (Zhou Zhihua) Chapter 14 probability graph model
L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)
Traversal of l2-006 tree (middle and later order determination binary tree & sequence traversal)
Linux Redis——Redis 数据库缓存服务
【Hcip】OSPF常用的6种LSA详解
Linux redis - redis database caching service
Solve the problem that PowerShell mining occupies 100% of cpu7 in win7
Processes and threads
随机推荐
Basic workflow of CPU
Codeforces Round #784 (Div. 4) (A - H)题解
Looking for a job, writing a resume to an interview, this set of information is enough!
TypeScript(1)
Rhcsa second day operation
[if you want to do a good job, you must first use its tools] Guide for downloading and using paper editing and document management (endnote, latex, jabref, overflow) resources
Reverse a linked list < difficulty coefficient >
Store consumption SMS notification template
Huashu "deep learning" and code implementation: 01 Linear Algebra: basic concepts + code implementation basic operations
OCR识别PDF文件
Traversée de l'arbre L2 - 006
Leangoo brain map - shared multi person collaborative mind mapping tool
Day 3 of learning rhcsa
JDBC JDBC
基于多态的职工管理系统源码与一些理解
Slave should be able to synchronize with the master in tests/integration/replication-psync. tcl
The input of El input input box is invalid, and error in data(): "referenceerror: El is not defined“
Fashion MNIST 数据集分类训练
Specific field information of MySQL export table (detailed operation of Navicat client)
php+mysql對下拉框搜索的內容修改