well02
well02

Reputation: 11

TypeError: Reduce.update_state() got multiple values for argument 'sample_weight'

I am creating a basic deep learning model and tried to compile it with tf.keras.metrics.Mean() but I keep getting this error and I am not sure how to fix it. I realized that tensorflow documentations for these metrics is supposed to use the "add_metric" function but I do not really understand how to use that function.

Here is a simple code to reproduce that error:

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

model = Sequential()

model.add(Dense(4, input_shape=(1,)))
model.add(Dense(1, ))
model.compile(optimizer='Adam', loss='binary_crossentropy', metrics=[tf.keras.metrics.Mean()])

model.fit([1], [0])

If anyone knows how to use the Mean() metrics, please let me know. Thanks!

Upvotes: 1

Views: 626

Answers (1)

user11530462
user11530462

Reputation:

Passing MAE instead of tf.keras.metrics.Mean() to metrics will solve the issue.

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

model = Sequential()
    
model.add(Dense(4, input_shape=(1,)))
model.add(Dense(1, ))
model.compile(optimizer='Adam', loss='binary_crossentropy', metrics=['MAE'])
    
model.fit([1], [0])

Upvotes: 1

Related Questions