Accuracy is not working in the compile method for TensorFlow Keras Sequential
Hi @airvzxf, Apologies for the delay. 
 I tried replicating the issue in Colab using Tensorflow 2.12 with a similar dataset, when using the syntax `metrics=[accuracy, Precision()]` I get 0.0 accuracy. Kindly refer to the gist [here](https://colab.sandbox.google.com/gist/synandi/e4a3e2670dae347f5995bc9a032f3544/60338_2-12.ipynb) and check the screenshot below
 
![image](https://user-images.githubusercontent.com/98147397/234824297-516cc85a-8669-4bec-b04e-608dac9e53e3.png)

when using the syntax `metrics=['accuracy', Precision()]` I get the following values
![image](https://user-images.githubusercontent.com/98147397/234824603-e25ae043-7f4e-491e-a16b-1405534a5dc4.png)

In the syntax `metrics=[accuracy, Precision()]`, the term "accuracy" is considered as a Python object that is used to calculate the accuracy metric during model training and evaluation. Whereas, in the syntax metrics=['accuracy', Precision()], the term "accuracy" is a string that represents a pre-defined metric function in TensorFlow.
 
 Please find the screenshot below, where it gives a warning in Colab that accuracy is not defined when using `metrics=[accuracy, Precision()]` .
 
![image](https://user-images.githubusercontent.com/98147397/234822722-1683c490-d226-490d-95c9-c2a969a79b78.png)

It is recommended to use `metrics=['accuracy', Precision()]`. There is no metric named accuracy in tensorflow. To import accuracy please use `from tensorflow.keras.metrics import Accuracy` instead of `from tensorflow.python.keras.metrics import accuracy`.

I was able to replicate the AttributeError in tf-nightly. Please find the gist [here](https://colab.sandbox.google.com/gist/synandi/1e2e75f1b81f2d80a5c14f20bfeace7b/60338_nightly.ipynb). 
Could you please import  keras from `tensorflow.keras` instead of `tensorflow.python.keras`.
Anything under `tf.python.*` is private, intended for development only, rather than for public use.
Importing from `tensorflow.python` or any other modules (including import tensorflow_core...) is not supported, and can break unannounced.So, it is suggested not to use anything with `tf.python.*`. Thank you for the research and responses. It speaks highly of the humility that Tensorflow has and the desire to improve.

---

> Could you please import keras from tensorflow.keras instead of tensorflow.python.keras.

I can't do it (`from tensorflow.keras import xxx`) because Python not recognize this way, during these two weeks I was experimenting and the best way to import is this:

```python
from tensorflow import keras
from keras import activations
from keras import backend
from keras import callbacks
from keras import layers
from keras import losses
from keras import metrics
from keras import models
from keras import utils
```

> In the syntax metrics=[accuracy, Precision()], the term "accuracy" is considered as a Python object that is used to calculate the accuracy metric during model training and evaluation. Whereas, in the syntax metrics=['accuracy', Precision()], the term "accuracy" is a string that represents a pre-defined metric function in TensorFlow.

I modified the two versions and these are the final versions of the code. The [Bug-TensorFlow-Keras-Sequential-compile-metrics.ipynb](https://colab.research.google.com/drive/1sle0JaEl-hdRCKeMQCUdY43nNWnYY4mB), right now, has editor permissions. The original [training data is in Dropbox](https://www.dropbox.com/s/gv3k8kcenwqdfxa/tic-tac-toe-records-train.csv?dl=0) and you could download, it requests to log in or sign in, they are not necessary, you can click on cancel or “x” icon.

Did you expect these changes in the follow code? Please don't hesitate to tell me if you want to change the code in other way.

Without quotes:

```python
model = models.Sequential()
model.add(layers.Dense(512, activation=activations.relu, input_shape=train_set_x.shape[1:]))
model.add(layers.Dense(512, activation=activations.relu))
model.add(layers.Dense(train_set_y.shape[1], activation=activations.softmax))
model.compile(
    optimizer=optimizers.Adam(),
    loss=losses.CategoricalCrossentropy(),
    metrics=[metrics.Accuracy(), metrics.Precision()]
)
```

With quotes:

```python
model = models.Sequential()
model.add(layers.Dense(512, activation=activations.relu, input_shape=train_set_x.shape[1:]))
model.add(layers.Dense(512, activation=activations.relu))
model.add(layers.Dense(train_set_y.shape[1], activation=activations.softmax))
model.compile(
    optimizer=optimizers.Adam(),
    loss=losses.CategoricalCrossentropy(),
    metrics=['accuracy', metrics.Precision()]
)
```

With these changes, I got these graphs.

**Without quotes.**

Execute 01:

![without quotes 01](https://user-images.githubusercontent.com/831380/234926914-45b21898-cf3b-4b85-8ae2-414aee342028.png)

Execute 02:

![without quotes 02](https://user-images.githubusercontent.com/831380/234929012-421d3eed-8117-46f8-be14-f687d98e20ea.png)

Execute 03:

![without quotes 03](https://user-images.githubusercontent.com/831380/234929046-0e134c3a-b752-4399-8301-1b745a5406e5.png)

**With quotes.**

Execute 01:

![with quotes 01](https://user-images.githubusercontent.com/831380/234929117-d26c9c58-1d58-452e-afdb-d588ef163810.png)

Execute 02:

![with quotes 02](https://user-images.githubusercontent.com/831380/234929161-b130374d-0d01-46db-8644-0dbf0cc41ce0.png)

Execute 03:

![with quotes 03](https://user-images.githubusercontent.com/831380/234929189-930f5d50-924b-4e3f-8a65-981ab1000e08.png)

---

**NOTES:**

I tagged this issue as a possible bug, but it looks like it is not a bug regarding your explanation, when the metrics is in between quotes, it takes some internal metric which is unknown, and it is fine. I tried to expose that the result is different from quotes and using directly the class. Just for the people who are expected some result but at the end this result will be change if you use quotes in the metrics or directly the class. I consider important because if I am using the metrics to evaluate which model is the best, using Tuner Keras or creating manual models. At the end this could affect my decision since I am seeing something that maybe is not related to the reality that I am thinking. From the documentation of [compile](https://www.tensorflow.org/api_docs/python/tf/keras/Sequential?version=nightly#compile) for metrics, it explains about the string "accuracy" usage as below.

> _List of metrics to be evaluated by the model during training and testing. Each of this can be a string (name of a built-in function), function or a [tf.keras.metrics.Metric](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/Metric) instance. See [tf.keras.metrics](https://www.tensorflow.org/api_docs/python/tf/keras/metrics). Typically you will use metrics=['accuracy']. A function is any callable with the signature result = fn(y_true,y_pred). To specify different metrics for different outputs of a multi-output model, you could also pass a dictionary, such as metrics={'output_a':'accuracy', 'output_b':['accuracy', 'mse']}. You can also pass a list to specify a metric or a list of metrics for each output, such as metrics=[['accuracy'], ['accuracy', 'mse']] or metrics=['accuracy', ['accuracy', 'mse']]. When you pass the strings 'accuracy' or 'acc', we convert this to one of [tf.keras.metrics.BinaryAccuracy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/BinaryAccuracy), [tf.keras.metrics.CategoricalAccuracy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/CategoricalAccuracy), [tf.keras.metrics.SparseCategoricalAccuracy](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/SparseCategoricalAccuracy) based on the shapes of the targets and of the model output. We do a similar conversion for the strings 'crossentropy' and 'ce' as well. The metrics passed here are evaluated without sample weighting; if you would like sample weighting to apply, you can specify your metrics via the weighted_metrics argument instead._

Let me know if this explains your confusion about the metric. Thanks! Yes, it explains the confusion. Furthermore, it makes sense. I'll close this issue. Thank you for all. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60338">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60338">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

No

### Source

source

### Tensorflow Version

tf v2.12.0-rc1-12-g0db597d0d75 2.12.0

### Custom Code

Yes

### OS Platform and Distribution

Arch Linux | BUILD_ID: rolling | Linux kernel 6.2.10

### Mobile device

_No response_

### Python version

Python 3.10.10

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

cuda 12.1.0-3 | cudnn 8.8.0.121-1

### GPU model and memory

GPU: NVIDIA GeForce GTX 1080 | Memory: 8388608 kBytes

### Current Behaviour?

I expect the same result if I used the metric with quotes and if I used without quotes. For me, it means there is something wrong at code level, maybe I am wrong.

The word accuracy with quotes, I got these values:

```python
self.__model.compile(
    optimizer=Adam(),
    loss=categorical_crossentropy,
    metrics=['accuracy', Precision()]
)
```
![Figure_2_with_quotes](https://user-images.githubusercontent.com/831380/232268485-e99d2947-47b5-4657-858a-72a253497c84.png)


The word accuracy without quotes, I got these values:

```python
from tensorflow.python.keras.metrics import accuracy, Precision
self.__model.compile(
    optimizer=Adam(),
    loss=categorical_crossentropy,
    metrics=[accuracy, Precision()]
)
```

![Figure_2_without_quotes](https://user-images.githubusercontent.com/831380/232268342-6ce45fef-c389-4ff3-9632-6e9fa78c8303.png)

---

Note:

I can't reproduce my example in TF Nightly (v1.12.1-92737-g0ae43a3fd1f 2.13.0-dev20230415) because it throws an error: `AttributeError: module 'tensorflow.python.distribute.input_lib' has no attribute 'DistributedDatasetInterface'. Did you mean: 'DistributedDatasetSpec'?`

### Standalone code to reproduce the issue

```shell
As, I show in this Jupyter Notebook. With the same data, if I change the metrics in the compile method with quotes `'accuracy'` or without quotes `accuracy`, it shows different results.

I repeat three times these steps in the Jupyter notebook, to avoid any fluctuation.

Bug-TensorFlow-Keras-Sequential-compile-metrics.ipynb
https://colab.research.google.com/drive/1sle0JaEl-hdRCKeMQCUdY43nNWnYY4mB
```


### Relevant log output

```shell
Without quotes:

{'loss': [1808.695068359375, 202.96279907226562, 54.72672653198242], 'accuracy': [0.5349747538566589, 0.4256841242313385, 0.16613984107971191], 'precision_9': [0.2498059868812561, 0.24983149766921997, 0.2497267723083496], 'val_loss': [443.4054870605469, 110.1395034790039, 11.466686248779297], 'val_accuracy': [0.532325029373169, 0.38062500953674316, 0.001075000036507845], 'val_precision_9': [0.24899999797344208, 0.24692469835281372, 0.25175511837005615]}

{'loss': [1874.009521484375, 148.31224060058594, 2.5201101303100586], 'accuracy': [0.5312250256538391, 0.35342004895210266, 0.0018018229166045785], 'precision_11': [0.25014790892601013, 0.249727264046669, 0.2505243122577667], 'val_loss': [175.01815795898438, 16.236042022705078, 1.3863223791122437], 'val_accuracy': [0.44843751192092896, 0.018687499687075615, 0.0], 'val_precision_11': [0.24866242706775665, 0.2497398555278778, 0.0]}

{'loss': [1835.9310302734375, 164.72079467773438, 33.215553283691406], 'accuracy': [0.5334452986717224, 0.38880130648612976, 0.09400103986263275], 'precision_13': [0.25037264823913574, 0.2497129887342453, 0.25012683868408203], 'val_loss': [331.0498046875, 54.01085662841797, 2.3827459812164307], 'val_accuracy': [0.4865500032901764, 0.18593749403953552, 0.0], 'val_precision_13': [0.24895000457763672, 0.2504253089427948, 0.2584269642829895]}


With quotes:

{'loss': [2104.91552734375, 218.6924591064453, 41.532161712646484], 'accuracy': [0.24953334033489227, 0.25047290325164795, 0.2501385509967804], 'precision_10': [0.24953436851501465, 0.2504711151123047, 0.25022196769714355], 'val_loss': [299.38861083984375, 87.65056610107422, 1.386319637298584], 'val_accuracy': [0.24914999306201935, 0.2533999979496002, 0.24940000474452972], 'val_precision_10': [0.24914999306201935, 0.25342532992362976, 0.0]}

{'loss': [1932.6285400390625, 215.28610229492188, 62.687828063964844], 'accuracy': [0.25043436884880066, 0.24967291951179504, 0.24986353516578674], 'precision_12': [0.25043463706970215, 0.2496640384197235, 0.24984458088874817], 'val_loss': [281.5032653808594, 66.43962860107422, 21.2304744720459], 'val_accuracy': [0.2502000033855438, 0.25029999017715454, 0.25209999084472656], 'val_precision_12': [0.2502000033855438, 0.2503626048564911, 0.25167566537857056]}

{'loss': [1990.3583984375, 205.70851135253906, 56.19692611694336], 'accuracy': [0.2503645718097687, 0.24988020956516266, 0.24988438189029694], 'precision_14': [0.25036510825157166, 0.2498749941587448, 0.24987071752548218], 'val_loss': [414.74072265625, 72.6060562133789, 28.769975662231445], 'val_accuracy': [0.24705000221729279, 0.25224998593330383, 0.24639999866485596], 'val_precision_14': [0.24705000221729279, 0.2522878348827362, 0.24636809527873993]}
```
</details>