问题描述
我发现了两个主要来源。
- A tutorial,未按照规则书进行(我希望避免)
- Keras' documentation(我更希望避免出现意外)
我更喜欢遵循Keras的文档来避免内存泄漏,因为某些try custom approaches与Keras在一起的人就是这种情况。
但是Keras在文档中显示的是关于分类的。这不是我的情况。
因此,我尝试查看Keras的源代码。正好在文件中:/lib/python3.7/site-packages/tensorflow_core/python/keras/metrics.py
。这一点对我都没有帮助,因为大多数指标(有些例外是分类指标)都是通过包装程序完成的,如下所示:
@keras_export('keras.metrics.MeanSquaredError')
class MeanSquaredError(MeanMetricWrapper):
"""Computes the mean squared error between `y_true` and `y_pred`.
For example,if `y_true` is [0.,0.,1.,1.],and `y_pred` is [1.,0.]
the mean squared error is 3/4 (0.75).
Usage:
```python
m = tf.keras.metrics.MeanSquaredError()
m.update_state([0.,[1.,0.])
print('Final result: ',m.result().numpy()) # Final result: 0.75
```
Usage with tf.keras API:
```python
model = tf.keras.Model(inputs,outputs)
model.compile('sgd',metrics=[tf.keras.metrics.MeanSquaredError()])
```
"""
def __init__(self,name='mean_squared_error',dtype=None):
super(MeanSquaredError,self).__init__(
mean_squared_error,name,dtype=dtype)
如您所见,只有构造函数方法,我需要的udpate_state
方法没有很好的启发。
在哪里可以找到它?
python 3.7.7
tensorflow 2.1.0
keras应用程序1.0.8
keras预处理1.1.0
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)