【发布时间】:2019-04-29 19:18:11
【问题描述】:
我已经安装了 Tensorflow 2.0
print(tf.__version__)
2.0.0-alpha0
虽然我可以使用 to_categorical 方法,但我无法导入它。
import tensorflow as tf
tf.keras.utils.to_categorical(np.arange(4), num_classes = 4)
array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]], dtype=float32)
但是当我尝试时:
from tf.keras.utils import to_categorical
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-243-c8bac54e2863> in <module>()
----> 1 from tf.keras.utils import to_categorical
ModuleNotFoundError: No module named 'tf'
【问题讨论】:
-
你也安装了 keras 吗? keras.io/#installation
标签: python-3.x tensorflow tensorflow2.0 keras-2