Я пытаюсь создать пользовательский слой в керасе, который имеет две обучаемые переменные.Я передаю эти две переменные другой функции, внутри которой они должны получить ndims и форму переменных.Но это показывает ошибку.Мой пользовательский код слоя -
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.
assert len(input_shape) >= 3
input_dim = input_shape[1:]
print(input_shape)
self.kernel1 = self.add_weight(
shape=self.output_dim[0],input_dim[0]),
name = 'kernel1',
initializer='uniform',
trainable=True)
print(self.kernel1)
self.kernel2 = self.add_weight(
shape=(self.output_dim[1],input_dim[1]),
name = 'kernel2',
initializer='uniform',
trainable=True)
print(self.kernel2)
super(MyLayer, self).build(input_shape) # Be sure to call this at
the end
def call(self, x):
print(x.shape)
mat1 =np.array(self.kernel1)
print(K.shape(mat1))
#print(mat1.ndim)
mat2 =np.array(self.kernel2)
print(K.shape(mat2))
#print(mat2.ndim)
output1 = Myoperation(x,mat1,1)
output = Myoperation(output1,mat2,2)
return output
def compute_output_shape(self, input_shape):
return (input_shape[0], self.output_dim)
внутри функции Myoperation, он должен рассчитать m2=list(np.shape(M))[1]
;Здесь M - это код mat1 или mat2enter. Ошибка -
IndexError: список индекса выходит за пределы диапазона, если мы используем mat1.shape для проверки формы, мы получаем TypeError: Ожидаемая двоичная или unicode строка, полученная
помогите пожалуйста