我在Google Colab上使用tensorflow 2.5時似乎遇到了問題。我認為CUDA版本和/或CuDNN版本之間存在一些不兼容。我將如何解決這些問題呢?
我檢查了colab使用的CUDA版本。它是11.2,在tf2.5中應該是可以的。這就意味著問題出在CuDNN上,對嗎?
重現代碼:
! pip install tensorflow==2.5.0
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.datasets import cifar10
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
x_train = x_train.astype("float32") / 255.0。
x_test = x_test.astype("float32") / 255.0。
def my_model()。
inputs = keras.Input(shape=(32, 32, 3)
x = layers.Conv2D(32, 3) (inputs)
x = layers.BatchNormalization()(x)
x = keras.activations.relu(x)
x = layers.MaxPooling2D()(x)
x = layers.Conv2D(64, 3) (x)
x = layers.BatchNormalization()(x)
x = keras.activations.relu(x)
x = layers.MaxPooling2D()(x)
x = layers.Conv2D(128, 3) (x)
x = layers.BatchNormalization()(x)
x = keras.activations.relu(x)
x = layers.Flatten()(x)
x = layers.Dense(64, activation="relu")(x)
outputs = layers.Dense(10)(x)
model = keras.Model(inputs=inputs, outputs=outputs)
return model
model = my_model()
model.compile(
loss=keras.loss.SparseCategoricalCrossentropy(from_logits=True)。
optimizer=keras.optimizers.Adam(learning_rate=3e-4) 。
metrics=["準確性"]。
)
model.fit(x_train, y_train, batch_size=64, epochs=10, verbose= 2)
model.evaluation(x_test, y_test, batch_size=64, verbose= 2)
我已經試過這個答案,但我得到了同樣的錯誤。
這個答案也建議我使用tf.config.experimental.set_memory_growth(gpu, True),但同樣--這不起作用--我得到了同樣的錯誤。
我對使用 我對使用 GPU 很感興趣。我知道,在沒有硬體加速的情況下,一切都很正常。
uj5u.com熱心網友回復: 在這個檔案中,Google警告我們不要使用tf.config.experimental.set_memory_growth(gpu, True)>感興趣。
!pip命令安裝/降級TensorFlow版本。
他們寫道:Colab從源代碼構建TensorFlow以確保與我們的
加速器的兼容性。通過pip從PyPI獲取的TensorFlow的版本
可能會出現性能問題,或者根本無法作業。
這意味著如果我們安裝任何其他的TensorFlow,該版本可能與他們提供的GPU/TPU配置不兼容。因此,只需使用TensorFlow 2.6(這是最新的版本),它與2.5版本是如此的相似。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/332765.html
標籤:
