我按照这里的描述设置了appletensorflow。我尝试了安装程序脚本和conda版本,都有相同的问题。下面是测试tensorflow的cifar10脚本,它显示tensorflow无法识别gpu。系统监视器还显示使用cpu而不是gpu。
import tensorflow as tf
print(tf.__version__)
tf.compat.v1.disable_eager_execution()
print(tf.config.list_physical_devices())
from tensorflow.python.client import device_lib
print([x.name for x in device_lib.list_local_devices() if x.device_type == 'GPU'])
from tensorflow.python.compiler.mlcompute import mlcompute
print("is_apple_mlc_enabled %s" % mlcompute.is_apple_mlc_enabled())
print("is_tf_compiled_with_apple_mlc %s" % mlcompute.is_tf_compiled_with_apple_mlc())
from tensorflow.keras import datasets, layers, models
(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()
train_images, test_images = train_images / 255.0, test_images / 255.0
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer',
'dog', 'frog', 'horse', 'ship', 'truck']
model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10))
model.summary()
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
history = model.fit(train_images, train_labels, epochs=10,
validation_data=(test_images, test_labels))
如何让tensorflow使用gpu而不是cpu?我做错什么了?我也意识到,安装有依赖性问题,他们可能是原因?
(venv) ~ pip check
tensorflow-macos 0.1a3 has requirement gast==0.3.3, but you have gast 0.4.0.
tensorflow-macos 0.1a3 has requirement grpcio~=1.32.0, but you have grpcio 1.33.2.
tensorflow-macos 0.1a3 has requirement numpy~=1.19.2, but you have numpy 1.18.5.
tensorflow-macos 0.1a3 has requirement protobuf~=3.13.0, but you have protobuf 3.15.8.
tensorflow-macos 0.1a3 has requirement tensorflow-estimator~=2.3.0, but you have tensorflow-estimator 2.4.0.
当做
暂无答案!
目前还没有任何答案,快来回答吧!