Классная идея, это редактировать :)

у манипулировать активациями предыдущего слоя с помощью пользовательского слоя keras. Нижний слой просто умножает число на активацию предыдущего уровня.

class myLayer(Layer):

def __init__(self, **kwargs):
    super(myLayer, self).__init__(**kwargs)

def build(self, input_shape):
    self.output_dim = input_shape[0][1]
    super(myLayer, self).build(input_shape)

def call(self, inputs, **kwargs):
    if not isinstance(inputs, list):
        raise ValueError('This layer should be called on a list of inputs.')

    mainInput = inputs[0]
    nInput = inputs[1]

    changed = tf.multiply(mainInput,nInput)

    forTest  = changed
    forTrain = inputs[0]

    return K.in_train_phase(forTrain, forTest)

def compute_output_shape(self, input_shape):
    print(input_shape)
    return (input_shape[0][0], self.output_dim)

Я создаю модель как

inputTensor = Input((5,))
out = Dense(units, input_shape=(5,),activation='relu')(inputTensor)

n = K.placeholder(shape=(1,))
auxInput = Input(tensor=n)
out = myLayer()([out, auxInput])

out = Dense(units, activation='relu')(out)
out = Dense(3, activation='softmax')(out)
model = Model(inputs=[inputTensor, auxInput], outputs=out)   
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics='acc'])

Я получаю эту ошибку при попытке использовать

model.fit(X_train, Y_train, epochs=epochs, verbose=1)

ошибка

InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_3' with dtype float and shape [1]

И когда я пытаюсь дать значение заполнителю, как

model.fit([X_train, np.array([3])], Y_train, epochs=epochs, verbose=1)

Я получил:

ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 1 arrays but instead got the following list of 2 arrays:

Как мне инициализировать этот заполнитель? Моя цель - использовать model.evaluate для проверки влияния различных значений модели на вывод. Благодарю.

Ответы на вопрос(2)

Ваш ответ на вопрос