Я получаю приведенную ниже ошибку при загрузке обученной модели
ValueError: Unknown metric function: {'class_name': 'SparseTopKCategoricalAccuracy', 'config': {'name': 'sparse_top_k_categorical_accuracy', 'dtype': 'float32', 'k': 5}}
Вот как модель компилируется и использует встроенную функцию
model.compile(loss='sparse_categorical_crossentropy', optimizer='rmsprop', metrics=[tf.keras.metrics.SparseTopKCategoricalAccuracy()])
model.save(dir_path+'/model_files/my_model.h5')
my_model=load_model(dir_path+'/model_files/my_model.h5')
Есть ли что-нибудь i отсутствует? Ниже представлены версии библиотеки tensorflow - 2.0.0 Keras - 2.3.1 Python - 3.6.8
Ниже приведен полный след ошибки
Traceback (most recent call last):
File "<ipython-input-563-5a9204dc1425>", line 1, in <module>
my_model=load_model(dir_path+'/model_files/my_model.h5')
File "/Users/vivekuday/anaconda3/lib/python3.6/site-packages/keras/engine/saving.py", line 492, in load_wrapper
return load_function(*args, **kwargs)
File "/Users/vivekuday/anaconda3/lib/python3.6/site-packages/keras/engine/saving.py", line 584, in load_model
model = _deserialize_model(h5dict, custom_objects, compile)
File "/Users/vivekuday/anaconda3/lib/python3.6/site-packages/keras/engine/saving.py", line 369, in _deserialize_model
sample_weight_mode=sample_weight_mode)
File "/Users/vivekuday/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 75, in symbolic_fn_wrapper
return func(*args, **kwargs)
File "/Users/vivekuday/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 211, in compile
self._cache_output_metric_attributes(metrics, weighted_metrics)
File "/Users/vivekuday/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 738, in _cache_output_metric_attributes
metrics, self.output_names, output_shapes, self.loss_functions)
File "/Users/vivekuday/anaconda3/lib/python3.6/site-packages/keras/engine/training_utils.py", line 941, in collect_per_output_metric_info
metric_name = get_metric_name(metric, is_weighted)
File "/Users/vivekuday/anaconda3/lib/python3.6/site-packages/keras/engine/training_utils.py", line 969, in get_metric_name
metric = metrics_module.get(metric)
File "/Users/vivekuday/anaconda3/lib/python3.6/site-packages/keras/metrics.py", line 1976, in get
return deserialize(config)
File "/Users/vivekuday/anaconda3/lib/python3.6/site-packages/keras/metrics.py", line 1970, in deserialize
printable_module_name='metric function')
File "/Users/vivekuday/anaconda3/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 140, in deserialize_keras_object
': ' + class_name)
ValueError: Unknown metric function: {'class_name': 'SparseTopKCategoricalAccuracy', 'config': {'name': 'sparse_top_k_categorical_accuracy', 'dtype': 'float32', 'k': 5}}