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

學無先后,達者為師

網站首頁 編程語言 正文

關于keras中的Reshape用法_python

作者:煙火笑風塵 ? 更新時間: 2022-09-08 編程語言

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

欄目分類
最近更新