gpt4 book ai didi

keras - 值错误 : Found two metrics with the same name: recall

转载 作者:行者123 更新时间:2023-12-05 06:14:24 26 4
gpt4 key购买 nike

我正在训练一个检测模型,其中训练和测试数据是 3D NumPy 数组。当开始训练这个模型时发现了这种类型的错误。代码链接如下

Training_model.py

detection.py

perform_learning.py

model.fit_generator(generator=training_generator,
validation_data=validation_generator,
use_multiprocessing=True,
workers=6,
epochs=epochs,
callbacks=[checkpoint, tensorboard])

追溯(最近的调用最后):文件“/content/SpineFinder-master/train_detection_model.py”,第 25 行,位于洗牌=真)

文件“/content/SpineFinder-master/learning_functions/perform_learning.py”,第 57 行,在 perform_learning回调=[检查点,张量板])

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/deprecation.py”,第 324 行,在 new_func返回 func(*args, **kwargs)

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py”,第 1479 行,在 fit_generator 中initial_epoch=initial_epoch)

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py”,第 66 行,在 _method_wrapper 中返回方法(self, *args, **kwargs)

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py”,第 848 行,适合tmp_logs = train_function(迭代器)

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py”,第 580 行,在 call结果 = self._call(*args, **kwds)

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py”,第 627 行,在 _call 中self._initialize(args, kwds, add_initializers_to=initializers)

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py”,第 506 行,在 _initialize 中*args, **kwds))

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py”,第 2446 行,在 _get_concrete_function_internal_garbage_collectedgraph_function,_,_=self._maybe_define_function(args, kwargs)

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py”,第 2777 行,在 _maybe_define_function 中graph_function = self._create_graph_function(args, kwargs)

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py”,第 2667 行,在 _create_graph_function 中capture_by_value=self._capture_by_value),

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py”,第 981 行,在 func_graph_from_py_funcfunc_outputs = python_func(*func_args, **func_kwargs)

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py”,第 441 行,wrapped_fn返回 weak_wrapped_fn()。包装(*args, **kwds)

文件“/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py”,第 968 行,在包装器中提高 e.ag_error_metadata.to_exception(e)

ValueError: 在用户代码中:

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:571 train_function *outputs = self.distribute_strategy.run(/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:951 运行 **返回 self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)

/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2290 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)

/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2649 _call_for_each_replica
return fn(*args, **kwargs)

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:543 train_step **
self.compiled_metrics.update_state(y, y_pred, sample_weight)

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:391 update_state
self._build(y_pred, y_true)

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:333 _build
self._set_metric_names()

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:353 _set_metric_names
m._name))

ValueError:找到两个同名的指标:recall

最佳答案

错误源于 detection.py 中的以下内容:

    recall_background = km.binary_recall(label=0)
recall_vertebrae = km.binary_recall(label=1)

根据[1]和[2],km.binary_recall()实例化keras.metrics.recall()类。但是,如果没有 name kwarg,两行都使用相同的名称 recall。因此,为了避免这种情况,我的理解是您必须像这样指定 name kwarg:

    recall_background = km.binary_recall(name="recall_background", label=0)
recall_vertebrae = km.binary_recall(name="recall_vertebrae", label=1)

[1] - https://github.com/netrack/keras-metrics/blob/master/keras_metrics/\_\_init__.py#L34

[2] - https://github.com/netrack/keras-metrics/blob/master/keras_metrics/metrics.py#L150

关于keras - 值错误 : Found two metrics with the same name: recall,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62905851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com