繁体   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