关于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
0
投稿

猜你喜欢

  • 基于SQL Server的C/S数据库应用系统

    2009-01-21 14:44:00
  • XMLHTTPRequest的属性和方法简介

    2007-12-18 18:42:00
  • php面向对象全攻略 (十二) 抽象方法和抽象类

    2023-11-18 20:44:18
  • 不能使用“;文件已在使用中 Microsoft JET Database Engine

    2012-12-04 20:34:36
  • python之当你发现QTimer不能用时的解决方法

    2021-05-18 04:49:37
  • Python正则表达式教程之一:基础篇

    2023-11-13 19:46:02
  • Django使用Mysql数据库已经存在的数据表方法

    2023-07-21 15:24:59
  • 详解python多线程、锁、event事件机制的简单使用

    2022-03-16 19:48:25
  • go语言题解LeetCode1275找出井字棋的获胜者示例

    2023-07-22 12:30:41
  • 如何恢复/修复MS SQL数据库的MDF文件

    2007-10-30 13:52:00
  • asp动态页面生成html页面

    2008-10-24 09:03:00
  • python list.sort()根据多个关键字排序的方法实现

    2021-05-22 03:16:09
  • Python实现字符串匹配的KMP算法

    2021-02-10 05:03:45
  • bootstrap自定义样式之bootstrap实现侧边导航栏功能

    2023-09-06 20:41:36
  • PyQt QListWidget修改列表项item的行高方法

    2022-02-08 08:33:35
  • Python基于Django实现验证码登录功能

    2023-06-25 03:21:13
  • python如何修改装饰器中参数

    2021-08-18 15:28:27
  • 分享13个非常有用的Python代码片段

    2022-02-17 00:00:37
  • python实现简单的井字棋游戏(gui界面)

    2023-03-06 23:16:01
  • python geopandas读取、创建shapefile文件的方法

    2022-09-23 16:57:19
  • asp之家 网络编程 m.aspxhome.com