Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Keras-我的损失是否是模型参数的函数?_Python_Image Processing_Tensorflow_Keras - Fatal编程技术网

Python Keras-我的损失是否是模型参数的函数?

Python Keras-我的损失是否是模型参数的函数?,python,image-processing,tensorflow,keras,Python,Image Processing,Tensorflow,Keras,我注意到,在Keras中,优化器的形式是损失函数 def loss(y_true, y_pred): //some loss function 如果我的损失函数只是模型参数的函数呢?如何将上述损失函数与优化器一起使用? 下面是一个使用Keras优化器的示例: sgd = optimizers.SGD(lr=0.001, decay=1e-6, momentum=0.9, nesterov=True) model.compile(optimizer

我注意到,在Keras中,优化器的形式是损失函数

def loss(y_true, y_pred):
    //some loss function
如果我的损失函数只是模型参数的函数呢?如何将上述损失函数与优化器一起使用? 下面是一个使用Keras优化器的示例:

sgd = optimizers.SGD(lr=0.001, decay=1e-6, 
                  momentum=0.9, nesterov=True)

model.compile(optimizer=sgd,
                  loss=custom_objective,
                  metrics=['accuracy'])

def custom_objective(model.trainable_weights()):
    //some loss function

“我如何使用梯度来更新模型”是一个非常非常开放的问题。我重新表述了这个问题,希望能有所帮助。这仍然是一个非常开放的问题——通常人们使用随机梯度下降,但有许多不同的优化者。因为你已经用Keras标记了这个问题,这里有一个到的链接。我一直在看优化器。唯一的问题是,他们使用参数y_true和y_pred的损失函数,但我的损失函数只是输出的函数。不可能是真的。我又重新措辞了这个问题。对不起,我对这件事还很陌生,所以发发慈悲吧。