简体   繁体   English

ValueError:未知度量函数:余弦

[英]ValueError: Unknown metric function: cosine

i have been getting valueError issue.我一直在收到 valueError 问题。 Currently using python3.9.11., keras2.8.目前使用python3.9.11.、keras2.8。

        if loss_init=="r2":
        parallel_model.compile(loss=custom_r2_loss, optimizer=opt,  metrics=['mse','mae', 'mape', 'cosine','acc', custom_r2_loss])
    elif loss_init =="wmae":
        parallel_model.compile(loss=custom_wmae_loss, optimizer=opt,  metrics=['mse','mae', 'mape', 'cosine','acc', custom_wmae_loss])
    else:
        parallel_model.compile(loss=loss_init, optimizer=opt,  metrics=['mse','mae', 'mape', 'cosine','acc']) 
    

and it gives this error: ValueError: Unknown metric function: cosine.它给出了这个错误:ValueError:未知度量函数:余弦。 Please ensure this object is passed to the custom_objects argument.请确保将此对象传递给custom_objects参数。 See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.有关详细信息,请参阅https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object

Here is the full traceback: ValueError: in user code:这是完整的回溯:ValueError:在用户代码中:

File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/engine/training.py", line 1021, in train_function  *
    return step_function(self, iterator)
File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/engine/training.py", line 1010, in step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/engine/training.py", line 1000, in run_step  **
    outputs = model.train_step(data)
File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/engine/training.py", line 864, in train_step
    return self.compute_metrics(x, y, y_pred, sample_weight)
File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/engine/training.py", line 957, in compute_metrics
    self.compiled_metrics.update_state(y, y_pred, sample_weight)
File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/engine/compile_utils.py", line 438, in update_state
    self.build(y_pred, y_true)
File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/engine/compile_utils.py", line 358, in build
    self._metrics = tf.__internal__.nest.map_structure_up_to(y_pred, self._get_metric_objects,
File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/engine/compile_utils.py", line 484, in _get_metric_objects
    return [self._get_metric_object(m, y_t, y_p) for m in metrics]
File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/engine/compile_utils.py", line 484, in <listcomp>
    return [self._get_metric_object(m, y_t, y_p) for m in metrics]
File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/engine/compile_utils.py", line 503, in _get_metric_object
    metric_obj = metrics_mod.get(metric)
File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/metrics.py", line 4262, in get
    return deserialize(str(identifier))
File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/metrics.py", line 4218, in deserialize
    return deserialize_keras_object(
File "/Users/neslihanyuksel/opt/anaconda3/envs/hipokrat/lib/python3.9/site-packages/keras/utils/generic_utils.py", line 709, in deserialize_keras_object
    raise ValueError(

ValueError: Unknown metric function: cosine. Please ensure this object is passed to the `custom_objects` argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.




ValueError: Unknown metric function: cosine. Please ensure this object is passed to the `custom_objects` argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.

full code is https://github.com/lrsoenksen/CL_RNA_SynthBio/blob/master/1_DL_CNN_2D_toehold_V1.ipynb完整代码是https://github.com/lrsoenksen/CL_RNA_SynthBio/blob/master/1_DL_CNN_2D_toehold_V1.ipynb

Replacing cosine with cosine_similarity will help.cosine_similarity替换cosine会有所帮助。 keras.metrics.CosineSimilarity computes the cosine similarity between the labels and predictions. keras.metrics.CosineSimilarity计算标签和预测之间的余弦相似度。

parallel_model.compile(loss=custom_r2_loss, optimizer=opt,  metrics=['mse','mae', 'mape', 'cosine_similarity','acc', custom_r2_loss])

You can find the reference here .您可以在此处找到参考。 Thank you!谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:未知度量 function:TP_count - ValueError: Unknown metric function : TP_count ValueError:在 Keras 中使用自定义指标时的未知指标函数 - ValueError: Unknown metric function when using custom metric in Keras ValueError:未知指标 function:Keras 中的二进制精度错误,即使不使用任何自定义指标也是如此 - ValueError: Unknown metric function:binary_precision error in Keras even when not using any custom metric XGBoostError:未知的度量函数映射 - XGBoostError: Unknown metric function mape ValueError:使用sklearn TSNE时,度量&#39;余弦&#39;对算法&#39;ball_tree&#39;无效 - ValueError: Metric 'cosine' not valid for algorithm 'ball_tree' when using sklearn TSNE Keras ValueError:未知激活函数:<lambda> - Keras ValueError: Unknown activation function:<lambda> ValueError: 未知激活 function:swish_activation - ValueError: Unknown activation function:swish_activation ValueError:未知的激活函数:my_custom_activation_function - ValueError: Unknown activation function: my_custom_activation_function ValueError:指标应该是可调用的,已接收 - ValueError: Metric should be a callable, received ValueError:即使使用最新的Keras / Theano,无效的参数&#39;metric&#39;也会传递给K.function - ValueError: Invalid argument 'metric' passed to K.function even with newest Keras/Theano
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM