Я хотел бы построить убыток, который придает индивидуальный вес каждому образцу и работает не только во время обучения. Он также должен работать для проверки и набора тестов.
Что я пробовал до сих пор:
def MMSE2(targets, preds,sample_weight):
#some calculations...
return loss
input_dim = Input(shape = (dim, ),name='rating_in')
weights_tensor = Input(shape=(dim,),name='weights')
encoder,decoder = AddLayers(neurons,setup['AFunction'],
setup['BatchNorm'],setup['Dropout'],setup['Layers'],dim,setup['Noise'])
encoded = encoder(input_dim)
decoded = decoder(encoded)
autoencoder = Model([input_dim,weights_tensor], decoded)
autoencoder.add_loss(MMSE2(input_dim,decoded,weights_tensor))
autoencoder.compile(optimizer='adam')
history = autoencoder.fit(x=[helper.trainx,helper.trainy,helper.trainm],
validation_data= [helper.valx,helper.valy,helper.valm],
epochs = setup['Epochs'], batch_size = setup['BatchSize'])
Работает без данных проверки.
Ошибка с данными проверки:
File "<ipython-input-11-fe466c688bcd>", line 3, in <module>
epochs = setup['Epochs'], batch_size = setup['BatchSize'])
File "C:\Users\Admin\Anaconda3\envs\tf21\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 819, in fit
use_multiprocessing=use_multiprocessing)
File "C:\Users\Admin\Anaconda3\envs\tf21\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 235, in fit
use_multiprocessing=use_multiprocessing)
File "C:\Users\Admin\Anaconda3\envs\tf21\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 614, in _process_training_inputs
distribution_strategy=distribution_strategy)
File "C:\Users\Admin\Anaconda3\envs\tf21\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 646, in _process_inputs
x, y, sample_weight=sample_weights)
File "C:\Users\Admin\Anaconda3\envs\tf21\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 2383, in _standardize_user_data
batch_size=batch_size)
File "C:\Users\Admin\Anaconda3\envs\tf21\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 2410, in _standardize_tensors
exception_prefix='input')
File "C:\Users\Admin\Anaconda3\envs\tf21\lib\site-packages\tensorflow_core\python\keras\engine\training_utils.py", line 539, in standardize_input_data
str(data)[:200] + '...')
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 2 array(s), for inputs ['rating_in', 'weights']
but instead got the following list of 1 arrays: [array([[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 5....