keras中的Reshape

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

keras中的Reshape

烟火笑风尘   2022-09-28 我要评论

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

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们