- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
所以我试图用多个数据集来污染我的 CNN 并且当我添加足够的数据时(例如当我将多个集合作为一个集合添加或当我尝试添加具有超过一百万个样本的集合时)它会接缝抛出一个 ResourceExhaustedError
。
至于说明here ,我尝试添加
from keras.backend.tensorflow_backend import set_session
import tensorflow as tf
config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.3
set_session(tf.Session(config=config))
我的代码,但这并没有什么不同。我在打印出 config.gpu_options.per_process_gpu_memory_fraction
后看到 0.3,这样部分接缝就可以了。
我什至加入了一个 config.gpu_options.allow_growth = True
以确保很好,但它并不想做任何事情,而是尝试一次使用所有内存,结果却发现它还不够。
我试图用来训练这个 CNN 的计算机有 4 个 GTX1080 Ti,每个都有 12GB 的专用内存。
编辑:很抱歉没有说明我是如何加载数据的,老实说我没有意识到有不止一种方法。在我学习的时候,他们总是有示例加载已经内置的数据集,我花了一段时间才意识到如何加载一个自提供的数据集。
我这样做的方式是创建两个 numpy 数组。一个具有路径或每个图像,另一个具有相应的标签。这是最基本的例子:
data_dir = "folder_name"
# There is a folder for every form and in that folder is every line of that form
for filename in glob.glob(os.path.join(data_dir, '*', '*')):
# the format for file names are: "{author id}-{form id}-{line number}.png"
# filename is a path to the file so .split('\\')[-1] get's the raw file name without the path and .split('-')[0] get's the author id
authors.append(filename.split('\\')[-1].split('-')[0])
files.append(filename)
#keras requires numpy arrays
img_files = np.asarray(files)
img_targets = np.asarray(authors)
最佳答案
您确定您没有使用巨大的 batch_size
吗?
“添加数据”:老实说,我不知道那是什么意思,如果你能用代码准确描述你在这里做什么,那将会有所帮助。
样本数量应该不会对 GPU 内存造成任何问题。导致问题的是大batch_size
。
加载庞大的数据集可能会导致 CPU RAM 问题,这与 keras/tensorflow 无关。 numpy 数组太大的问题。 (您可以通过“不创建任何模型”简单地加载数据来测试这一点)
如果这是您的问题,您应该使用生成器
逐渐加载批处理。同样,由于您的问题中绝对没有代码,因此我们无能为力。
但这是简单地为图像创建生成器的两种形式:
ImageDataGenerator
及其 flow_from_directory()
方法,explained here yield
的循环循环生成器的简单示例:
def imageBatchGenerator(imageFiles, imageLabels, batch_size):
while True:
batches = len(imageFiles) // batch_size
if len(imageFiles) % batch_size > 0:
batches += 1
for b in range(batches):
start = b * batch_size
end = (b+1) * batch_size
images = loadTheseImagesIntoNumpy(imageFiles[start:end])
labels = imageLabels[start:end]
yield images,labels
Warning: even with generators, you must make sure your batch size is not too big!
使用它:
model.fit_generator(imageBatchGenerator(files,labels,batchSize), steps_per_epoch = theNumberOfBatches, epochs= ....)
您应该能够决定哪些层由哪个 GPU 处理,这“可以”优化您的 RAM 使用。
示例,创建模型时:
with tf.device('/gpu:0'):
createLayersThatGoIntoGPU0
with tf.device('/gpu:1'):
createLayersThatGoIntoGPU1
#you will probably need to go back to a previous GPU, as you must define your layers in a proper sequence
with tf.device('/cpu:0'):
createMoreLayersForGPU0
#and so on
我不确定这会不会更好,但也值得一试。
在此处查看更多详细信息:https://keras.io/getting-started/faq/#how-can-i-run-a-keras-model-on-multiple-gpus
关于python - Keras 与 TensorFlow : Use memory as it's needed [ResourceExhaustedError],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51034355/
我想知道,如果我的函数没有相似的名称,我是否需要使用命名空间? 另外我无法掌握从特定文件夹导入所有命名空间的方法... 最佳答案 I'm wondering, that if my functions
我运行 2to3 -f all -f idioms -f buffer -f set_literal -f ws_comma foo.py 输出: RefactoringTool: No change
我对 RoR 还是很陌生,我正在尝试使用 button_to delete 按钮删除一个对象。但是,使用我编写的代码,当我尝试将它获取到 destroy 方法的/needs/:id 时,它会将我带到/
当我运行代码时,我在 DEBUG Console 中发现了这个错误如下图所示错误: Restarted application in 2,804ms. [38;5;248m════════ Excep
我有一个实现 __dir__ 方法的类。但是,我并不完全确定 dir API 的一些细节。 A:__dir__ 是否真的需要返回一个列表?我的实现是使用 set 来避免两次列出属性,我需要在返回之前将
我正在尝试执行对非官方 Instagram API python 库的调用,在我修复了几个需要依赖项的错误之后,我被困在了这个错误上。 File "C:\Users\Pablo\Desktop\tx
我正在使用 SingleChildScrollView 和 Column 来显示滑动条和 gridview。 如果我在我的专栏中使用一些其他小部件,如文本、图像,应用程序显示正常。但是我的swiper
我正在尝试卸载 zsh 插件 (macos),我修改了 .zshrc 文件并从 中删除了 macos >plugin 列表,并删除路径 ~/.oh-my-zsh/plugins 中的 macos 文件
我正在尝试卸载 zsh 插件 (macos),我修改了 .zshrc 文件并从 中删除了 macos >plugin 列表,并删除路径 ~/.oh-my-zsh/plugins 中的 macos 文件
Exception caught by rendering library ═════════════════════════════════ RenderBox was not laid out:
我对 Python 很陌生。我正在试用 threading模块。我遇到了 Event对象。 事件对象有wait set clear职能。我了解等待、设置和清除正在做什么。但是我不太明白为什么会有一个单
我需要在 SQL Server 的 sql 查询中转义 [ select * from sometable where name like '[something]'; 我实际上正在寻找某个东西之前的
我的要求是这样的: 我在数据库和时区中保存以毫秒为单位的时间。例如,以毫秒为单位的时间是 1223123123232长时区是 Asia/Calcutta 。我必须将其转换为 Africa/Asmara
我的表中有两个整数列,其中第一列填充了一些随机数,第二列为空。现在是否可以将第一列按升序排序,同时按降序排序并显示为第二列?我有下表的示例。 初始表: col1 col2 5 7 3 9
我正在使用 Instruments 检查我的应用程序的内存泄漏并向我展示: NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ChangeAcc
我有课 class Person { // some other fields for this object std::vector relatives; } 然后是一个返回 Person
在下面的代码中,为什么需要 .page-wrap:after? 理论上,如果没有这个,粘性页脚不应该工作吗?为什么不呢? * { margin: 0; } html, body { heigh
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
我看过维基百科的图数据库,还是不明白。 什么是“无索引邻接”? 可不可以理解为“不是把主键存到其他表的行,而是直接存这些行的物理位置” 最佳答案 当您的数据可以表示为图形( map 上的路线、一些树等
我是 AngularJS 的新手,但我真的很喜欢 AngularJS 的工作方式,所以我想将它部署为我的 Google 云端点后端的客户端。然后我立即遇到两个问题: 1、放在哪里myCallback
我是一名优秀的程序员,十分优秀!