日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

關(guān)于keras中的Reshape用法_python

作者:煙火笑風(fēng)塵 ? 更新時(shí)間: 2022-09-08 編程語(yǔ)言

keras中的Reshape

keras自帶

from keras.layers import Reshape
layer_1 = Reshape((height, width, chns))( layer1)

tensorflow中的reshape函數(shù)

from keras import backend as K
K.reshape( layer1,(-1,2,4,8) )?

keras自大的Reshape層不需要寫(xiě)batch的維度,但是tensorflow的reshape需要完整的維度。

keras.layers.Reshape方法

from keras.models import Sequential
from keras.layers import Reshape

model = Sequential()
# 改變數(shù)據(jù)形狀為3行4列
# 模型的第1層必須指定輸入的維度,注意不需要指定batch的大小
model.add(Reshape((3, 4), input_shape=(12, )))
# 改變數(shù)據(jù)形狀為6行2列
model.add(Reshape((6, 2)))
# 改變數(shù)據(jù)形狀為 第2,3維為(2,2),根據(jù)數(shù)據(jù)元素?cái)?shù)量自動(dòng)確定第1維大小為3
model.add(Reshape((-1, 2, 2)))
# 改變數(shù)據(jù)形狀為 第1,2維為(2,2),根據(jù)數(shù)據(jù)元素?cái)?shù)量自動(dòng)確定第3維大小為3
model.add(Reshape((2, 2, -1)))
model.summary()
context_shape = K.int_shape(context) #(None, 7, 7, 32)
    #改變第二維是32,根據(jù)數(shù)據(jù)元素?cái)?shù)量自動(dòng)確定第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

欄目分類(lèi)
最近更新