关于keras中的Reshape用法
作者:烟火笑风尘 时间:2021-11-08 00:04:12
keras中的Reshape
keras自带
from keras.layers import Reshape
layer_1 = Reshape((height, width, chns))( layer1)
tensorflow中的reshape函数
from keras import backend as K
K.reshape( layer1,(-1,2,4,8) )
keras自大的Reshape层不需要写batch的维度,但是tensorflow的reshape需要完整的维度。
keras.layers.Reshape方法
from keras.models import Sequential
from keras.layers import Reshape
model = Sequential()
# 改变数据形状为3行4列
# 模型的第1层必须指定输入的维度,注意不需要指定batch的大小
model.add(Reshape((3, 4), input_shape=(12, )))
# 改变数据形状为6行2列
model.add(Reshape((6, 2)))
# 改变数据形状为 第2,3维为(2,2),根据数据元素数量自动确定第1维大小为3
model.add(Reshape((-1, 2, 2)))
# 改变数据形状为 第1,2维为(2,2),根据数据元素数量自动确定第3维大小为3
model.add(Reshape((2, 2, -1)))
model.summary()
context_shape = K.int_shape(context) #(None, 7, 7, 32)
#改变第二维是32,根据数据元素数量自动确定第1维大小为none?
context = keras.layers.Reshape((-1, context_shape[-1]))(context) #Tensor shape=(None, None, 32), dtype=float32
来源:https://blog.csdn.net/moshiyaofei/article/details/87888451
标签:keras,Reshape


猜你喜欢
Python pyecharts实时画图自定义可视化经纬度热力图
2023-12-24 10:14:21

使用卷积神经网络(CNN)做人脸识别的示例代码
2023-12-31 06:25:05

python 递归深度优先搜索与广度优先搜索算法模拟实现
2022-10-03 12:51:59

Sql server中的char、varchar、text和nchar、nvarchar、ntext的区别
2011-08-14 09:43:44
Asp实现伪静态的方法
2007-09-29 21:27:00
Python 比较文本相似性的方法(difflib,Levenshtein)
2022-01-29 00:19:17
Python+Socket实现基于TCP协议的客户与服务端中文自动回复聊天功能示例
2023-07-18 20:11:01

golang 结构体初始化时赋值格式介绍
2024-04-26 17:26:11

Python环境搭建过程从安装到Hello World
2023-03-03 07:41:36

python使用自定义user-agent抓取网页的方法
2021-12-27 03:09:56
详解webpack进阶之loader篇
2024-05-11 09:43:50
python使用在线API查询IP对应的地理位置信息实例
2021-12-10 23:59:16
SQLserver删除某数据库中所有表实现思路
2024-01-25 21:06:40
在 git 中取消 __pycache__ 文件的方法
2022-09-14 20:00:17

复制链接到剪贴板,兼容Firefox Chrome IE
2008-12-16 13:23:00
pycharm设置鼠标悬停查看方法设置
2022-12-25 16:04:31

使用GitHub和Python实现持续部署的方法
2022-07-16 22:54:35

Asp模板制作方法详解
2007-10-11 19:05:00
python实现循环语句1到100累和
2023-05-15 15:39:38
Python高光谱遥感影像处理问题详细分析讲解
2023-10-04 04:03:37