Я создал свой собственный слой, используя подклассы слоев с использованием приведенного ниже кода
class MyLayermean(Layer):
def __init__(self, units,input_dim): # define weight, biases dimension
super(MyLayermean,self).__init__()
self.w= self.add_weight(shape=(input_dim,units),
initializer='random_normal'
)
self.b= self.add_weight(shape=(units,),
initializer='zeros')
self.sum_activation = tf.Variable(initial_value= tf.zeros((units,)),
trainable= False)
self.number_call = tf.Variable(intial_value=0,
trianable= False)
def call(self, inputs):
activations = tf.matmul(inputs,self.w) +self.b
self.sum_activation.assign_add(tf.reduce_sum(activations,axis=0))
self.number_call.assign_add(inputs.shape[0])
return activations, self.sum_activation / tf.cast(self.number_call,tf.float32)
Но когда я создаю объект этого класса, я получаю сообщение об ошибке dense_layer = MyLayermean(3,5)
/ Журналы ошибок:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-24-4423456e28b2> in <module>()
----> 1 dense_layer = MyLayermean(3,5)
1 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variables.py in __call__(cls, *args, **kwargs)
259 return cls._variable_v1_call(*args, **kwargs)
260 elif cls is Variable:
--> 261 return cls._variable_v2_call(*args, **kwargs)
262 else:
263 return super(VariableMetaclass, cls).__call__(*args, **kwargs)
TypeError: _variable_v2_call() got an unexpected keyword argument 'intial_value'