簡體   English   中英

獲取卷積算法失敗。 這可能是因為 cuDNN 初始化失敗,

[英]Failed to get convolution algorithm. This is probably because cuDNN failed to initialize,

在 Tensorflow/Keras 中運行來自https://github.com/pierluigiferrari/ssd_keras的代碼時,使用估算器:ssd300_evaluation。 我收到了這個錯誤。

獲取卷積算法失敗。 這可能是因為 cuDNN 初始化失敗,所以嘗試查看上面是否打印了警告日志消息。

這與未解決的問題非常相似: Google Colab Error : Failed to get convolution algorithm.這可能是因為cuDNN未能初始化

對於我正在運行的問題:

蟒蛇:3.6.4。

Tensorflow 版本:1.12.0。

Keras 版本:2.2.4。

CUDA:V10.0。

cuDNN:V7.4.1.5。

NVIDIA GeForce GTX 1080。

我也跑了:

import tensorflow as tf
with tf.device('/gpu:0'):
      a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
      b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
      c = tf.matmul(a, b)
with tf.Session() as sess:
print (sess.run(c))

沒有錯誤或問題。

極簡主義的例子是:

 from keras import backend as K
 from keras.models import load_model
 from keras.optimizers import Adam
 from scipy.misc import imread
 import numpy as np
 from matplotlib import pyplot as plt

 from models.keras_ssd300 import ssd_300
 from keras_loss_function.keras_ssd_loss import SSDLoss
 from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes
 from keras_layers.keras_layer_DecodeDetections import DecodeDetections
 from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast
 from keras_layers.keras_layer_L2Normalization import L2Normalization
 from data_generator.object_detection_2d_data_generator import DataGenerator
 from eval_utils.average_precision_evaluator import Evaluator
 import tensorflow as tf
 %matplotlib inline
 import keras
 keras.__version__



 # Set a few configuration parameters.
 img_height = 300
 img_width = 300
 n_classes = 20
 model_mode = 'inference'


 K.clear_session() # Clear previous models from memory.

 model = ssd_300(image_size=(img_height, img_width, 3),
            n_classes=n_classes,
            mode=model_mode,
            l2_regularization=0.0005,
            scales=[0.1, 0.2, 0.37, 0.54, 0.71, 0.88, 1.05], # The scales 
 for MS COCO [0.07, 0.15, 0.33, 0.51, 0.69, 0.87, 1.05]
            aspect_ratios_per_layer=[[1.0, 2.0, 0.5],
                                     [1.0, 2.0, 0.5, 3.0, 1.0/3.0],
                                     [1.0, 2.0, 0.5, 3.0, 1.0/3.0],
                                     [1.0, 2.0, 0.5, 3.0, 1.0/3.0],
                                     [1.0, 2.0, 0.5],
                                     [1.0, 2.0, 0.5]],
            two_boxes_for_ar1=True,
            steps=[8, 16, 32, 64, 100, 300],
            offsets=[0.5, 0.5, 0.5, 0.5, 0.5, 0.5],
            clip_boxes=False,
            variances=[0.1, 0.1, 0.2, 0.2],
            normalize_coords=True,
            subtract_mean=[123, 117, 104],
            swap_channels=[2, 1, 0],
            confidence_thresh=0.01,
            iou_threshold=0.45,
            top_k=200,
            nms_max_output_size=400)

 # 2: Load the trained weights into the model.

 # TODO: Set the path of the trained weights.
 weights_path = 'C:/Users/USAgData/TF SSD 
 Keras/weights/VGG_VOC0712Plus_SSD_300x300_iter_240000.h5'

 model.load_weights(weights_path, by_name=True)

 # 3: Compile the model so that Keras won't complain the next time you load it.

 adam = Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)

 ssd_loss = SSDLoss(neg_pos_ratio=3, alpha=1.0)

 model.compile(optimizer=adam, loss=ssd_loss.compute_loss)


dataset = DataGenerator()

# TODO: Set the paths to the dataset here.
dir= "C:/Users/USAgData/TF SSD Keras/VOC/VOCtest_06-Nov-2007/VOCdevkit/VOC2007/"
Pascal_VOC_dataset_images_dir = dir+ 'JPEGImages'
Pascal_VOC_dataset_annotations_dir = dir + 'Annotations/'
Pascal_VOC_dataset_image_set_filename = dir+'ImageSets/Main/test.txt'

# The XML parser needs to now what object class names to look for and in which order to map them to integers.
classes = ['background',
           'aeroplane', 'bicycle', 'bird', 'boat',
           'bottle', 'bus', 'car', 'cat',
           'chair', 'cow', 'diningtable', 'dog',
           'horse', 'motorbike', 'person', 'pottedplant',
           'sheep', 'sofa', 'train', 'tvmonitor']

dataset.parse_xml(images_dirs=[Pascal_VOC_dataset_images_dir],
                  image_set_filenames=[Pascal_VOC_dataset_image_set_filename],
                  annotations_dirs=[Pascal_VOC_dataset_annotations_dir],
                  classes=classes,
                  include_classes='all',
                  exclude_truncated=False,
                  exclude_difficult=False,
                  ret=False)



evaluator = Evaluator(model=model,
                      n_classes=n_classes,
                      data_generator=dataset,
                      model_mode=model_mode)



results = evaluator(img_height=img_height,
                    img_width=img_width,
                    batch_size=8,
                    data_generator_mode='resize',
                    round_confidences=False,
                    matching_iou_threshold=0.5,
                    border_pixels='include',
                    sorting_algorithm='quicksort',
                    average_precision_mode='sample',
                    num_recall_points=11,
                    ignore_neutral_boxes=True,
                    return_precisions=True,
                    return_recalls=True,
                    return_average_precisions=True,
                    verbose=True)

我出於三種不同的原因看到了此錯誤消息,並使用了不同的解決方案:

1.你有緩存問題

我經常通過關閉 python 進程、刪除~/.nv目錄(在 linux 上, rm -rf ~/.nv )並重新啟動 Python 進程來解決此錯誤。 我不完全知道為什么會這樣。 它可能至少部分與第二個選項有關:

2. 你的內存不足

如果圖形卡 RAM 用完,該錯誤也會出現。 使用 nvidia GPU,您可以使用nvidia-smi檢查顯卡內存使用情況。 這將為您提供正在使用的 GPU RAM 量(例如6025MiB / 6086MiB如果您幾乎達到極限)以及正在使用 GPU RAM 的進程列表。

如果您的 RAM 用完,您將需要重新啟動該進程(這將釋放 RAM),然后采用較少內存密集型的方法。 幾個選項是:

  • 減少批量大小
  • 使用更簡單的模型
  • 使用更少的數據
  • 限制 TensorFlow GPU 內存比例:例如,以下內容將確保 TensorFlow 使用 <= 90% 的 RAM:
import keras
import tensorflow as tf

config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.9  # 0.6 sometimes works better for folks
keras.backend.tensorflow_backend.set_session(tf.Session(config=config))

如果不與上述項目一起使用,這可能會減慢您的模型評估速度,大概是因為必須交換進出大數據集以適應您分配的少量內存。

第二種選擇是讓 TensorFlow 開始時僅使用最少量的內存,然后根據需要分配更多內存(在此處記錄):

os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'

3. 您的 CUDA、TensorFlow、NVIDIA 驅動程序等版本不兼容。

如果你從來沒有使用過類似的模型,你沒有用完 VRAM並且你的緩存是干凈的,我會回去使用最好的安裝指南設置 CUDA + TensorFlow - 我在以下方面取得了最大的成功https://www.tensorflow.org/install/gpu 上的說明,而不是 NVIDIA / CUDA 站點上的說明。 Lambda Stack也是一個不錯的方法。

我遇到了同樣的問題,因此我解決了它:

os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'

或者

physical_devices = tf.config.experimental.list_physical_devices('GPU')
if len(physical_devices) > 0:
   tf.config.experimental.set_memory_growth(physical_devices[0], True)

我遇到了這個錯誤,我通過從我的系統中卸載所有 CUDA 和 cuDNN 版本來修復它。 然后我安裝了CUDA Toolkit 9.0 (沒有任何補丁)和cuDNN v7.4.1 for CUDA 9.0

Keras 包含在上面的 TensorFlow 2.0 中。 所以

  • 刪除import keras
  • from keras.module.module import class語句替換為 --> from tensorflow.keras.module.module import class
  • 也許您的 GPU 內存已滿。 所以在 GPU 選項中使用 allow growth = True 。 現在已棄用。 但是在導入后使用下面的代碼片段可能會解決您的問題。
import tensorflow as tf
from tensorflow.compat.v1.keras.backend import set_session
config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True  # dynamically grow the memory used on the GPU
config.log_device_placement = True  # to log device placement (on which device the operation ran)
sess = tf.compat.v1.Session(config=config)
set_session(sess)

我在使用 CuDNN v 8.0.4 的 Tensorflow 2.4 和 Cuda 11.0 也遇到了同樣的問題。 我已經浪費了將近 2 到 3 天的時間來解決這個問題。 問題只是驅動程序不匹配。 我正在安裝 Cuda 11.0 Update 1,我認為這是更新 1,所以可能運行良好,但那是那里的罪魁禍首。 我卸載了 Cuda 11.0 Update 1 並在沒有更新的情況下安裝了它。 以下是適用於 RTX 2060 6GB GPU 上的 TensorFlow 2.4 的驅動程序列表。

此處提到了所需的硬件和軟件要求列表

我也不得不這樣做

import tensorflow as tf
physical_devices = tf.config.list_physical_devices('GPU') 
tf.config.experimental.set_memory_growth(physical_devices[0], True)

為了避免這個錯誤

2020-12-23 21:54:14.971709: I tensorflow/stream_executor/stream.cc:1404] [stream=000001E69C1DA210,impl=000001E6A9F88E20] did not wait for [stream=000001E69C1DA180,impl=000001E6A9F88730]
2020-12-23 21:54:15.211338: F tensorflow/core/common_runtime/gpu/gpu_util.cc:340] CPU->GPU Memcpy failed
[I 21:54:16.071 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
kernel 8b907ea5-33f1-4b2a-96cc-4a7a4c885d74 restarted
kernel 8b907ea5-33f1-4b2a-96cc-4a7a4c885d74 restarted

這些是我得到的一些錯誤樣本

類型 1

UnpicklingError: invalid load key, 'H'.

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-2-f049ceaad66a> in <module>

類型 2


InternalError: Blas GEMM launch failed : a.shape=(15, 768), b.shape=(768, 768), m=15, n=768, k=768 [Op:MatMul]

During handling of the above exception, another exception occurred:

類型 3

failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED
2020-12-23 21:31:04.534375: E tensorflow/stream_executor/cuda/cuda_blas.cc:226] failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED
2020-12-23 21:31:04.534683: E tensorflow/stream_executor/cuda/cuda_blas.cc:226] failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED
2020-12-23 21:31:04.534923: E tensorflow/stream_executor/cuda/cuda_blas.cc:226] failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED
2020-12-23 21:31:04.539327: E tensorflow/stream_executor/cuda/cuda_dnn.cc:336] Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED
2020-12-23 21:31:04.539523: E tensorflow/stream_executor/cuda/cuda_dnn.cc:336] Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED
2020-12-23 21:31:04.539665: W tensorflow/core/framework/op_kernel.cc:1763] OP_REQUIRES failed at conv_ops_fused_impl.h:697 : Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.

問題在於較新版本的 tensorflow 1.10.x 以及帶有 cudnn 7.0.5 和 cuda 9.0 的版本不兼容。 最簡單的解決方法是將 tensorflow 降級到 1.8.0

pip install --upgrade tensorflow-gpu==1.8.0

這是對https://stackoverflow.com/a/56511889/2037998第 2 點的跟進。

2. 你的內存不足

我使用以下代碼來限制 GPU RAM 的使用:

import tensorflow as tf

gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
  # Restrict TensorFlow to only allocate 1*X GB of memory on the first GPU
  try:
    tf.config.experimental.set_virtual_device_configuration(
        gpus[0],
        [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=(1024*4))])
    logical_gpus = tf.config.experimental.list_logical_devices('GPU')
    print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
  except RuntimeError as e:
    # Virtual devices must be set before GPUs have been initialized
    print(e)

此代碼示例來自:TensorFlow:使用 GPU:限制 GPU 內存增長將此代碼放在您正在使用的任何其他 TF/Keras 代碼之前。

注意:應用程序可能仍會使用比上述數字多一點的 GPU RAM。

注 2:如果系統還運行其他應用程序(如 UI),這些程序也會消耗一些 GPU RAM。 (Xorg, Firefox,... 有時高達 1GB 的 GPU RAM)

我遇到了同樣的錯誤,出現此錯誤的原因是由於 cudaa/cudnn 的版本與您的 tensorflow 版本不匹配,有兩種方法可以解決此問題:

  1. 要么你降級你的 Tensorflow 版本pip install --upgrade tensorflowgpu==1.8.0

  2. 或者您可以按照此處的步驟操作。

    提示:選擇您的 ubuntu 版本並按照步驟操作。:-)

我在 RTX 2080 上遇到了同樣的問題。然后下面的代碼對我有用。

from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession

config = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)

我遇到了同樣的問題,但在開始時添加這些代碼行解決了我的問題:

physical_devices = tf.config.experimental.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], True)

適用於 tensorflow V2。

升級到TF2.0后我遇到了這個問題。 以下開始給出錯誤:

   outputs = tf.nn.conv2d(images, filters, strides=1, padding="SAME")

我使用的是 Ubuntu 16.04.6 LTS(Azure 數據科學 VM)和 TensorFlow 2.0。 在此 TensorFlow GPU 指令頁面上按指令升級。 這為我解決了這個問題。 順便說一句,它的一堆 apt-get 更新/安裝,我執行了所有這些。

只需添加

from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession

config = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)

我有同樣的問題。 我正在使用 conda 環境,所以我的包由 conda 自動管理。 我通過限制tensorflow v2、python 3.x的內存分配解決了這個問題

physical_devices = tf.config.experimental.list_physical_devices(‘GPU’)
tf.config.experimental.set_memory_growth(physical_devices[0], True)

這解決了我的問題。 但是,這非常限制了內存。 當我同時運行

nvidia-smi

我看到它大約是700mb。 因此,為了查看更多選項,可以檢查tensorflow 網站上的代碼

gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
  # Restrict TensorFlow to only allocate 1GB of memory on the first GPU
  try:
    tf.config.experimental.set_virtual_device_configuration(
        gpus[0],
        [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1024)])
    logical_gpus = tf.config.experimental.list_logical_devices('GPU')
    print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
  except RuntimeError as e:
    # Virtual devices must be set before GPUs have been initialized
    print(e)

就我而言,上面的代碼片段完美地解決了這個問題。

注意:我沒有嘗試使用 pip 安裝 tensorflow,這與 conda 安裝的 tensorflow 有效。

Ubuntu:18.04

蟒蛇:3.8.5

張量流:2.2.0

庫德恩:7.6.5

cudatoolkit:10.1.243

正如上面 Anurag Bhalekar 已經觀察到的那樣,這可以通過一個骯臟的解決方法來解決,方法是在使用 keras 的 load_model() 加載舊模型之前在代碼中設置和運行模型。 這似乎正確初始化了 cuDNN,然后可以將其用於 load_model()。

就我而言,我使用 Spyder IDE 來運行我所有的 python 腳本。 具體來說,我在一個腳本中設置、訓練和保存 CNN。 之后,另一個腳本加載保存的模型以進行可視化。 如果我打開 Spyder 並直接運行可視化腳本來加載舊的、保存的模型,我會得到與上面提到的相同的錯誤。 我仍然能夠加載模型並對其進行修改,但是當我嘗試創建預測時,出現錯誤。

但是,如果我首先在 Spyder 實例中運行我的訓練腳本,然后在同一個 Sypder 實例中運行可視化腳本,它可以正常工作,沒有任何錯誤:

#training a model correctly initializes cuDNN
model=Sequential()
model.add(Conv2D(32,...))
model.add(Dense(num_classes,...))
model.compile(...)
model.fit() #this all works fine

然后,包括 load_model() 的以下代碼工作正常:

#this script relies on cuDNN already being initialized by the script above
from keras.models import load_model
model = load_model(modelPath) #works
model = Model(inputs=model.inputs, outputs=model.layers[1].output) #works
feature_maps = model.predict(img) #produces the error only if the first piece of code is not run

我無法弄清楚為什么會這樣或如何以不同的方式解決問題,但對我來說,在使用 load_model() 之前訓練一個小的工作 keras 模型是一種快速而骯臟的修復,不需要重新安裝 cuDNN 或其他方式.

面臨同樣的問題,我認為 GPU 無法一次加載所有數據。 我通過減少批量大小來解決它。

我在這個問題上掙扎了一個星期。 原因很傻:我用高分辨率照片進行訓練。

希望這會節省某人的時間:)

如果存在不兼容的 cuDNN 版本,也可能出現此問題,如果您使用 conda 安裝 Tensorflow,則可能會出現這種情況,因為 conda 在安裝 Tensorflow 時還會安裝 CUDA 和 cuDNN。

解決方案是使用pip安裝Tensorflow,並在沒有conda的情況下分別安裝CUDA和cuDNN,例如如果您有CUDA 10.0.130和cuDNN 7.4.1 測試配置 ,那么

pip install tensorflow-gpu==1.13.1

1) 關閉所有其他使用 GPU 的筆記本

2) TF 2.0 需要cuDNN SDK (>= 7.4.1)

將“bin”文件夾的路徑提取並添加到“環境變量/系統變量/路徑”中:“D:\\Programs\\x64\\Nvidia\\cudnn\\bin”

就我而言,當我直接從.json和.h5文件加載模型並嘗試預測某些輸入的輸出時,會遇到此錯誤。 因此,在進行此類操作之前,我嘗試在mnist上訓練一個示例模型,該模型允許cudNN進行初始化, 在此處輸入圖片說明

我有同樣的問題,但比這里發布的其他人的解決方案更簡單。 我同時安裝了 CUDA 10.0 和 10.2,但我只有 10.2 的 cuDNN,並且這個版本 [在本文發布時] 與 TensorFlow GPU 不兼容。 我剛剛為 CUDA 10.0 安裝了 cuDNN,現在一切正常!

解決方法:全新安裝TF 2.0並運行一個簡單的Minst教程,沒問題,打開另一個筆記本,嘗試運行並遇到此問題。 我存在所有筆記本並重新啟動 Jupyter 並僅打開一個筆記本,成功運行問題似乎是內存或在 GPU 上運行多個筆記本

謝謝

我和你有同樣的問題,我的配置是 tensorflow1.13.1、cuda10.0、cudnn7.6.4。 我嘗試將 cudnn 的版本更改為 7.4.2 幸運的是,我解決了問題。

在我的代碼開始時在 GPU 上啟用內存增長解決了這個問題:

import tensorflow as tf

physical_devices = tf.config.experimental.list_physical_devices('GPU')
print("Num GPUs Available: ", len(physical_devices))
tf.config.experimental.set_memory_growth(physical_devices[0], True)

可用的 GPU 數量:1

參考: https : //deeplizard.com/learn/video/OO4HD-1wRN8

在您的筆記本或代碼的開頭添加以下代碼行

import tensorflow as tf

physical_devices = tf.config.experimental.list_physical_devices('GPU')

tf.config.experimental.set_memory_growth(physical_devices[0], True)

我有一個類似的問題。 Tensorflow 抱怨說它期望某個版本的 cuDNN 但不是它找到的那個版本。 所以,我從https://developer.nvidia.com/rdp/cudnn-archive下載了它預期的版本並安裝了它。 它現在可以工作了。

如果你已經使用 Conda 安裝了 Tensorflow-gpu,那么安裝隨它一起安裝的cudnncudatoolkit並重新運行筆記本。

注意:嘗試在 conda 中僅卸載這兩個軟件包會強制卸載一系列其他軟件包。 因此,使用以下命令僅卸載這些軟件包

(1)刪除cuda

conda remove --force cudatookit

(2)去除cudnn

conda remove --force cudnn

現在運行 Tensorflow,它應該可以工作了!

沒有任何代表,我無法將其添加為對以上 Anurag 和 Obnebion 的兩個現有答案的評論,我也不能對答案進行投票,因此即使它似乎違反了指導方針,我也做出了一個新答案。 無論如何,我最初遇到了這個頁面上的其他答案的問題,並修復了它,但后來當我開始使用檢查點回調時再次遇到相同的消息。 在這一點上,只有 Anurag/Obnebion 的答案是相關的。 事實證明,我最初將模型保存為 .json,將權重分別保存為 .h5,然后使用 model_from_json 和單獨的 model.load_weights 再次獲得權重。 那行得通(我有 CUDA 10.2 和 tensorflow 2.x)。 只有當我試圖從檢查點回調切換到這個多合一的 save/load_model 時,它才會損壞。 這是我在 _save_model 方法中對 keras.callbacks.ModelCheckpoint 所做的小改動:

                            if self.save_weights_only:
                                self.model.save_weights(filepath, overwrite=True)
                            else:
                                model_json = self.model.to_json()
                                with open(filepath+'.json','w') as fb:
                                    fb.write(model_json)
                                    fb.close()
                                self.model.save_weights(filepath+'.h5', overwrite=True)
                                with open(filepath+'-hist.pickle','wb') as fb:
                                    trainhistory = {"history": self.model.history.history,"params": self.model.history.params}
                                    pickle.dump(trainhistory,fb)
                                    fb.close()
                                # self.model.save(filepath, overwrite=True)

歷史泡菜轉儲只是關於堆棧溢出的另一個問題的雜亂無章,當您從檢查點回調中提前退出時,歷史對象會發生什么。 好吧,您可以在 _save_model 方法中看到有一行將損失監視器數組從日志字典中拉出...但從未將其寫入文件! 所以我只是相應地放入了kludge。 大多數人不建議像這樣使用泡菜。 我的代碼只是一個黑客所以沒關系。

看起來圖書館需要一些熱身。 這不是生產的有效解決方案,但您至少可以繼續處理其他錯誤......

from keras.models import Sequential
import numpy as np
from keras.layers import Dense
from keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
model = Sequential()
model.add(Dense(1000,input_dim=(784),activation='relu') )  #imnput layer
model.add(Dense(222,activation='relu'))                     #hidden layer
model.add(Dense(100,activation='relu'))   
model.add(Dense(50,activation='relu'))   
model.add(Dense(10,activation='sigmoid'))   
model.compile(optimizer="adam",loss='categorical_crossentropy',metrics=["accuracy"])
x_train = np.reshape(x_train,(60000,784))/255
x_test = np.reshape(x_test,(10000,784))/255
from keras.utils import np_utils
y_train = np_utils.to_categorical(y_train) 
y_test = np_utils.to_categorical(y_test)
model.fit(x_train[:1000],y_train[:1000],epochs=1,batch_size=32)

如果您是中國人,請確保您的工作路徑不包含中文,並將您的batch_size 更改得越來越小。謝謝!

只需使用以下命令安裝帶有 GPU 的 TensorFlow: pip install tensorflow 您不需要單獨安裝 GPU。 如果單獨安裝 GPU,則很可能會與它們的版本不匹配。

但是對於 1.15 及更早的版本,CPU 和 GPU 包是分開的。

我在 AWS Ubuntu 實例上為此苦苦掙扎了一段時間。

然后,我找到了解決方案,在這種情況下非常簡單。

不要使用 pip ( pip install tensorflow-gpu ) pip install tensorflow-gpu ,而是使用conda install tensorflow-gpu ( conda install tensorflow-gpu ),以便它位於 conda 環境中,並在正確的環境中安裝 cudatoolkit 和 cudnn。

這對我有用,挽救了我的一天,希望它可以幫助其他人。

請參閱 learnermaxRL 的原始解決方案: https://github.com/tensorflow/tensorflow/issues/24828#issuecomment-453727142 : https://github.com/tensorflow/tensorflow/issues/24828#issuecomment-453727142

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM