關于keras中的Reshape用法
更新時間:2022年07月15日 14:34:48 作者:煙火笑風塵
這篇文章主要介紹了關于keras中的Reshape用法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
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層不需要寫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ù)元素數(shù)量自動確定第1維大小為3 model.add(Reshape((-1, 2, 2))) # 改變數(shù)據(jù)形狀為 第1,2維為(2,2),根據(jù)數(shù)據(jù)元素數(shù)量自動確定第3維大小為3 model.add(Reshape((2, 2, -1))) model.summary()
context_shape = K.int_shape(context) #(None, 7, 7, 32) #改變第二維是32,根據(jù)數(shù)據(jù)元素數(shù)量自動確定第1維大小為none? context = keras.layers.Reshape((-1, context_shape[-1]))(context) #Tensor shape=(None, None, 32), dtype=float32
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Python手拉手教你爬取貝殼房源數(shù)據(jù)的實戰(zhàn)教程
隨著人工智能的不斷發(fā)展,機器學習這門技術也越來越重要,很多人都開啟了學習機器學習,本文就介紹了機器學習的基礎內(nèi)容,了解python爬蟲,本文給大家分享Python爬取貝殼房源數(shù)據(jù)的實戰(zhàn)教程,感興趣的朋友一起學習吧2021-05-05