Python如何使用tensorflow-cpu
Python how to use tensorflow-cpu
我成功安装了 tensorflow-cpu 作为 pip install tensorflow-cpu
但是,在尝试导入包时,我在第一行收到此错误。
import tensorflow-cpu as tf
import numpy as np
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense
l0 = Dense(units=1, input_shape=[1])
model = Sequential([l0])
model.compile(optimizer='sgd', loss='mean_squared_error')
xs = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float)
ys = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float)
model.fit(xs, ys, epochs=500)
ERROR Line 1: No module named tensorflow.
我该如何解决这个问题?
我没有更新的 GPU 或 NVIDIA 软件包,我的笔记本电脑不支持,因此建议使用 cpu 版本。
无论您安装的是哪种tensorflow风格(CPU或GPU),您总是像tensorflow一样导入tensorflow,如下所示:
import tensorflow as tf
我成功安装了 tensorflow-cpu 作为 pip install tensorflow-cpu
但是,在尝试导入包时,我在第一行收到此错误。
import tensorflow-cpu as tf
import numpy as np
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense
l0 = Dense(units=1, input_shape=[1])
model = Sequential([l0])
model.compile(optimizer='sgd', loss='mean_squared_error')
xs = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float)
ys = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float)
model.fit(xs, ys, epochs=500)
ERROR Line 1: No module named tensorflow.
我该如何解决这个问题?
我没有更新的 GPU 或 NVIDIA 软件包,我的笔记本电脑不支持,因此建议使用 cpu 版本。
无论您安装的是哪种tensorflow风格(CPU或GPU),您总是像tensorflow一样导入tensorflow,如下所示:
import tensorflow as tf