自定義Keras Layer

Keras的Layer其實就是一個Class, 要具備如下幾個方法:ui

(1) build(input_shape): 定義權重的地方, 若是不須要定義權重, 也要有self.built = True;input

(2) call(x): 編寫功能邏輯的地方, 實現Layer的功能邏輯;方法

(3) compute_output_shape(input_shape): 根據input_shape, 計算形狀變化的地方, 可以讓Keras推斷輸出的Tensor的Shape.call

相關文章
相關標籤/搜索