tensorflow2.0 - tensorflow 我们可以对 Conv2D 或 Dense 等层进行子类化吗?
问题描述
我知道可以像这样在 tensorflow 2 中创建自定义层:
class CustomDense(tf.keras.layers.Layer):
def __init__(self,unit,activation):
super(CustomDense, self).__init__(name='my_layer')
self.unit=unit
self.activation=activation
def build(self, input_shape):
self.kernel = self.add_weight(shape=(input_shape[1],self.unit),trainable=Truename='kernel')
self.bias = self.add_weight(shape=(self.unit,),name='bias')
def call(self,inputs):
x=tf.matmul(inputs,self.kernel) + self.bias
output=self.activation(x)
return output
但是是否可以创建一个自定义层,其父类是现有层,如 Dense 或 Conv2D?
class CustomDense(tf.keras.layers.Dense):
解决方案
推荐阅读
- git - GWT 模块的 Maven 安装将行尾从 LF 更改为 CRLF
- amazon-web-services - 添加 cfn-signal 后 cfn-init 停止工作
- excel-formula - Excel 公式仅在所有值都匹配时才从查找中获取唯一值
- angular - 错误加上自定义表单控件组件
- ios - Firebase Analytics 何时跟踪我的用户?
- javascript - 调试 React Hooks 重新渲染问题
- javascript - 在javascript中对对象进行函数剥离克隆的最佳方法是什么?
- cordova - 在 AWS Device Farm 中,如果摄像头变黑,这意味着什么?
- azure - 如何从 Eventhub 中删除事件
- java - 程序抛出 NullPointerException