Я пытаюсь построить модель, используя пользовательский слой Keras.Несмотря на то, что моя модель представляет собой слой Keras, я не могу использовать его, поскольку Keras считает, что это не так.
Вот мой собственный код слоя:
from keras import backend as K
from keras.layers import Layer
class MyLayer(Layer):
def __init__(self, output_dim, **kwargs):
self.output_dim = output_dim
super(MyLayer, self).__init__(**kwargs)
def build(self, input_shape):
# Create a trainable weight variable for this layer.
self.kernel = self.add_weight(name='kernel',
shape=(input_shape[1], self.output_dim),
initializer='uniform',
trainable=True)
self.out_estimate = self.add_weight(name='out_estimate',
shape=(self.output_dim,),
initializer='uniform',
trainable=True)
self.loss_input_estimate = self.add_weight(name='loss_input_estimate',
shape=(self.output_dim,),
initializer='uniform',
trainable=True)
super(MyLayer, self).build(input_shape) # Be sure to call this at the end
def call(self, x):
return loss_input_estimate
def compute_output_shape(self, input_shape):
return (input_shape[0], self.output_dim)
и здеськод модели, в который выдается ошибка:
from keras.models import Model
from keras import layers
from keras import Input
input_tensor = layers.Input(shape=(28 * 28,))
output_tensor = MyLayer(input_tensor)
model = Model(input_tensor, output_tensor)
model.summary()