当前位置:网站首页>tf.keras.layers.InputLayer函数
tf.keras.layers.InputLayer函数
2022-04-22 06:57:00 【不负韶华ღ】
函数原型
tf.keras.layers.InputLayer(input_shape=None,
batch_size=None,
dtype=None,
input_tensor=None,
sparse=None,
name=None,
ragged=None,
type_spec=None,
**kwargs
)
函数使用
输入层一般用作线性模型的第一层,通过指定参数input_tensor包装现有的张量或者指定参数input_shape创建新的占位符张量。
tf.compat.v1.disable_eager_execution()
a = tf.compat.v1.placeholder("float", (None, 32))
model = tf.keras.Sequential([
tf.keras.layers.InputLayer(input_tensor=a),
tf.keras.layers.Dense(64)
])
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense (Dense) (None, 64) 2112
=================================================================
Total params: 2,112
Trainable params: 2,112
Non-trainable params: 0
_________________________________________________________________
首先创建了一个占位符张量a,形状为(None, 32)。然后通过指定input_tensor=a包裹张量a作为输入张量。最终输出张量形状为(None, 64)。
model = tf.keras.Sequential([
tf.keras.layers.InputLayer(input_shape=32),
tf.keras.layers.Dense(64)
])
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense (Dense) (None, 64) 2112
=================================================================
Total params: 2,112
Trainable params: 2,112
Non-trainable params: 0
_________________________________________________________________
指定指定参数input_shape=32,创建一个占位符张量tensor作为输入张量,形状为(None, 32)。经过一个Dense层,最终输出张量形状也为(None, 64)。
值得注意的是,如果同时指定input_shape和input_tensor,那么input_shape参数会失效,也就是根据现有的张量创建输入层。
还可以在其他层上指定input_shape参数来省略该层。
model = tf.keras.Sequential([
tf.keras.layers.Dense(64, input_shape=(None, 32))
])
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense (Dense) (None, None, 64) 2112
=================================================================
Total params: 2,112
Trainable params: 2,112
Non-trainable params: 0
_________________________________________________________________
通过在Dense层上指定input_shape=(None, 32),相当于创建一个张量形状为(None, None, 32)的输入层。通过Dense层后,最终形状为(None, None, 64)。
tf.keras.layers.InputLayer函数和tf.keras.Input函数区别:
tf.keras.Input函数返回的是一个张量Tensor,tf.keras.layers.InputLayer函数是一个layer对象。官网的建议是使用tf.keras.Input函数来创建一个InputLayer输入层,而不是直接使用tf.keras.layers.InputLayer来定义输入层。
版权声明
本文为[不负韶华ღ]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_49346755/article/details/124264071
边栏推荐
猜你喜欢

Primary test: ordinary vs excellent

综合光接入设备4路百兆隔离以太网络+16路E1专网业务2M综合业务光端机

OpenFeign之响应处理

氧化镁MgO晶体基片|钛酸锶SrTiO3晶体基片|铌酸锂LiNbO3晶体基片;直径10mm

LeetCode_118. 杨辉三角_动态规划_int**的学习

网络原理二(上)

OpenFeign的参数传递之数组和集合类型

Differences between routing modes

Web problem location: F12, how to find the corresponding interface

REINFORCE
随机推荐
Shrio study notes (I)
TP5 多条件where查询(使用PHP变量)
HLS / Chisel 实践CORDIC高性能计算复数平方根
服务雪崩效应
FileNotFoundError: [Errno 2] No such file or directory
jmeter_ Mysql database connection
4E1 + 2-way Gigabit isolation network + 4-way 100m physical isolation network PDH optical transceiver
VS Code 设置换行
【速领】电子工程师入门必备计算工具-方波电路辅助设计表格
adb 高级部分命令
Why do I value document naming so much?
动态顺序表+OJ
微信小程序页面路由
REINFORCE
氧化镁MgO晶体基片|钛酸锶SrTiO3晶体基片|铌酸锂LiNbO3晶体基片;直径10mm
加载视图卡顿
Redis入门必读
Android interview
通过OpenFeign传递对象类型参数
Web automation: 5.2 selenium mouse operation principle: actionchains delay call