keras-team / keras-contrib

Keras community contributions
MIT License
1.58k stars 650 forks source link

CRF' object has no attribute 'viterbi_decoding' #538

Open xiongyujia opened 4 years ago

xiongyujia commented 4 years ago

I met this error, but I find viterbi_decoding in crf.py ~/anaconda3/lib/python3.6/site-packages/keras/engine/training.py in compile(self, optimizer, loss, metrics, loss_weights, sample_weight_mode, weighted_metrics, target_tensors, **kwargs) 220 skip_target_masks=[l is None for l in self.loss_functions], 221 sample_weights=self.sample_weights, --> 222 masks=masks) 223 224 # Compute total loss.

~/anaconda3/lib/python3.6/site-packages/keras/engine/training.py in _handle_metrics(self, outputs, targets, skip_target_masks, sample_weights, masks) 869 870 self._handle_per_output_metrics( --> 871 self._per_output_metrics[i], target, output, output_mask) 872 self._handle_per_output_metrics( 873 self._per_output_weighted_metrics[i],

~/anaconda3/lib/python3.6/site-packages/keras/engine/training.py in _handle_per_output_metrics(self, metrics_dict, y_true, y_pred, mask, weights) 840 with K.name_scope(metric_name): 841 training_utils.call_metric_function( --> 842 metric_fn, y_true, y_pred, weights=weights, mask=mask) 843 844 def _handle_metrics(self,

~/anaconda3/lib/python3.6/site-packages/keras/engine/training_utils.py in call_metric_function(metric_fn, y_true, y_pred, weights, mask) 1031 1032 if y_pred is not None: -> 1033 update_ops = metric_fn.update_state(y_true, y_pred, sample_weight=weights) 1034 with K.control_dependencies(update_ops): # For TF 1035 metric_fn.result()

~/anaconda3/lib/python3.6/site-packages/keras/utils/metrics_utils.py in decorated(metric_obj, *args, *kwargs) 40 """Decorated function with add_update().""" 41 ---> 42 update_op = update_state_fn(args, **kwargs) 43 metric_obj.add_update(update_op) 44 return update_op

~/anaconda3/lib/python3.6/site-packages/keras/metrics.py in update_state(self, y_true, y_pred, sample_weight) 316 y_pred, y_true = losses_utils.squeeze_or_expand_dimensions(y_pred, y_true) 317 --> 318 matches = self._fn(y_true, y_pred, **self._fn_kwargs) 319 return super(MeanMetricWrapper, self).update_state( 320 matches, sample_weight=sample_weight)

~/anaconda3/lib/python3.6/site-packages/keras_contrib/metrics/crf_accuracies.py in crf_viterbi_accuracy(y_true, y_pred) 22 X = crf._inbound_nodes[idx].input_tensors[0] 23 mask = crf._inbound_nodes[idx].input_masks[0] ---> 24 y_pred = crf.viterbi_decoding(X, mask) 25 return _get_accuracy(y_true, y_pred, mask, crf.sparse_target) 26

AttributeError: 'CRF' object has no attribute 'viterbi_decoding'