Adam优化器在Keras(TensorFlow2)中返回错误

当我用2个参数调用Adam时,我得到的消息是我用3个我不理解的参数来调用它。

def f_compile_model_regression(model):

    model.compile(

    loss = {'prediction1' : tf.keras.metrics.MeanAbsoluteError(),'prediction2' : tf.keras.metrics.MeanAbsoluteError()},metrics = {'prediction1' : [tf.keras.metrics.MeanAbsoluteError()],'prediction2' : [tf.keras.metrics.MeanAbsoluteError()]},optimizer= Adam(lr= 0.001,decay= (0.001/200) )

    )

    return(model)

model = f_compile_model_regression(model)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-226-3b8e0f95fd47> in <module>
----> 1 model = f_compile_model_regression(model)

<ipython-input-225-5eb529d4b59c> in f_compile_model_regression(model)
      8     metrics = {'prediction1' : [tf.keras.metrics.MeanAbsoluteError()],9 
---> 10     optimizer= Adam(lr= 0.001,decay= (0.001/200) )
     11 
     12     )

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\training\tracking\base.py in _method_wrapper(self,*args,**kwargs)
    454     self._self_setattr_tracking = False  # pylint: disable=protected-access
    455     try:
--> 456       result = method(self,**kwargs)
    457     finally:
    458       self._self_setattr_tracking = previous_value  # pylint: disable=protected-access

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\engine\training.py in compile(self,optimizer,loss,metrics,loss_weights,sample_weight_mode,weighted_metrics,**kwargs)
    367 
    368       # Creates the model loss and weighted metrics sub-graphs.
--> 369       self._compile_weights_loss_and_weighted_metrics()
    370 
    371       # Functions for train,test and predict will

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\training\tracking\base.py in _method_wrapper(self,**kwargs)
    457     finally:
    458       self._self_setattr_tracking = previous_value  # pylint: disable=protected-access

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\engine\training.py in _compile_weights_loss_and_weighted_metrics(self,sample_weights)
   1398       #                   loss_weight_2 * output_2_loss_fn(...) +
   1399       #                   layer losses.
-> 1400       self.total_loss = self._prepare_total_loss(masks)
   1401 
   1402   def _prepare_skip_target_masks(self):

~\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\keras\engine\training.py in _prepare_total_loss(self,masks)
   1458 
   1459           if hasattr(loss_fn,'reduction'):
-> 1460             per_sample_losses = loss_fn.call(y_true,y_pred)
   1461             weighted_losses = losses_utils.compute_weighted_loss(
   1462                 per_sample_losses,TypeError: call() takes 2 positional arguments but 3 were given

您如何解释该错误消息以及我该怎么办?

iCMS 回答:Adam优化器在Keras(TensorFlow2)中返回错误

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2215497.html

大家都在问