python3.8 安装tensorflow2.6问题

import tensorflow as tf

loss_obj_scc = tf.keras.losses.SparseCategoricalCrossentropy()

使用如下方法直接报出如下问题: 原因是keras版本是2.8版本,可能与tf2.6不兼容,

pip install keras==2.6.0 即可解决

# 2022-03-27 22:41:02.116859: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
# To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
# 2022-03-27 22:41:02.338609: E tensorflow/core/lib/monitoring/collection_registry.cc:77] Cannot register 2 metrics with the same name: /tensorflow/api/keras/optimizers
# Traceback (most recent call last):
#   File "C:/Users/yinchen/PycharmProjects/pythonExercise/tensorflow2exercise.py", line 8, in 
#     loss_obj_scc = tf.keras.losses.SparseCategoricalCrossentropy(
#   File "C:\anaconda\envs\python38base\lib\site-packages\tensorflow\python\util\lazy_loader.py", line 62, in __getattr__
#     module = self._load()
# ......
#   File "C:\anaconda\envs\python38base\lib\site-packages\tensorflow\python\eager\monitoring.py", line 135, in __init__
#     self._metric = self._metric_methods[self._label_length].create(*args)
# tensorflow.python.framework.errors_impl.AlreadyExistsError: Another metric with the same name already exists.
#
# Process finished with exit code 1

你可能感兴趣的:(tensorflow-gpu,tensorflow)