Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Google Colab内存不足

Google Colab内存不足
EN

Stack Overflow用户
提问于 2021-07-11 17:45:47
回答 1查看 1.5K关注 0票数 0

我尝试在Google Colab Pro GPU (内存:25 me,磁盘:147 me)上使用更快的RCNN运行TF对象检测模型的演示,但失败了,并给出以下错误:

代码语言:javascript
运行
AI代码解释
复制
Tensorflow/core/common_runtime/bfc_allocator.cc:456] Allocator (GPU_0_bfc) ran out of memory trying to allocate 7.18GiB (rounded to 7707033600)requested by op MultiLevelMatMulCropAndResize/MultiLevelRoIAlign/AvgPool-0-TransposeNHWCToNCHW-LayoutOptimizer
If the cause is memory fragmentation maybe the environment variable 'TF_GPU_ALLOCATOR=cuda_malloc_async' will improve the situation. 

然后它会给我这些统计数据:

代码语言:javascript
运行
AI代码解释
复制
I tensorflow/core/common_runtime/bfc_allocator.cc:1058] Sum Total of in-use chunks: 7.46GiB
I tensorflow/core/common_runtime/bfc_allocator.cc:1060] total_region_allocated_bytes_: 15034482688 memory_limit_: 16183459840 available bytes: 1148977152 curr_region_allocation_bytes_: 8589934592
I tensorflow/core/common_runtime/bfc_allocator.cc:1066] Stats: 
Limit:                     16183459840
InUse:                      8013051904
MaxInUse:                   8081602560
NumAllocs:                        6801
MaxAllocSize:               7707033600
Reserved:                            0
PeakReserved:                        0
LargestFreeBlock:                    0

代码语言:javascript
运行
AI代码解释
复制
tensorflow.python.framework.errors_impl.ResourceExhaustedError:  OOM when allocating tensor with shape[2400,1024,28,28] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
     [[{{node MultiLevelMatMulCropAndResize/MultiLevelRoIAlign/AvgPool-0-TransposeNHWCToNCHW-LayoutOptimizer}}]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.
 [Op:__inference__dummy_computation_fn_32982]

我真的不明白为什么在25 7GB的系统上只分配7 7GB的内存就会用完?我怎么才能修复它?以下是我用于此任务的配置文件:

代码语言:javascript
运行
AI代码解释
复制
# Faster R-CNN with Resnet-50 (v1)
# Trained on COCO, initialized from Imagenet classification checkpoint

# Achieves -- mAP on COCO14 minival dataset.

# This config is TPU compatible.

model {
  faster_rcnn {
    num_classes: 7
    image_resizer {
      keep_aspect_ratio_resizer {
        min_dimension: 640
        max_dimension: 640
        pad_to_max_dimension: true
      }
    }
    feature_extractor {
      type: 'faster_rcnn_resnet50_keras'
      batch_norm_trainable: true
    }
    first_stage_anchor_generator {
      grid_anchor_generator {
        scales: [0.25, 0.5, 1.0, 2.0]
        aspect_ratios: [0.5, 1.0, 2.0]
        height_stride: 16
        width_stride: 16
      }
    }
    first_stage_box_predictor_conv_hyperparams {
      op: CONV
      regularizer {
        l2_regularizer {
          weight: 0.0
        }
      }
      initializer {
        truncated_normal_initializer {
          stddev: 0.01
        }
      }
    }
    first_stage_nms_score_threshold: 0.0
    first_stage_nms_iou_threshold: 0.7
    first_stage_max_proposals: 300
    first_stage_localization_loss_weight: 2.0
    first_stage_objectness_loss_weight: 1.0
    initial_crop_size: 14
    maxpool_kernel_size: 2
    maxpool_stride: 2
    second_stage_box_predictor {
      mask_rcnn_box_predictor {
        use_dropout: false
        dropout_keep_probability: 1.0
        fc_hyperparams {
          op: FC
          regularizer {
            l2_regularizer {
              weight: 0.0
            }
          }
          initializer {
            variance_scaling_initializer {
              factor: 1.0
              uniform: true
              mode: FAN_AVG
            }
          }
        }
        share_box_across_classes: true
      }
    }
    second_stage_post_processing {
      batch_non_max_suppression {
        score_threshold: 0.0
        iou_threshold: 0.6
        max_detections_per_class: 100
        max_total_detections: 300
      }
      score_converter: SOFTMAX
    }
    second_stage_localization_loss_weight: 2.0
    second_stage_classification_loss_weight: 1.0
    use_static_shapes: true
    use_matmul_crop_and_resize: true
    clip_anchors_to_image: true
    use_static_balanced_label_sampler: true
    use_matmul_gather_in_matcher: true
  }
}

train_config: {
  batch_size: 8
  sync_replicas: true
  startup_delay_steps: 0
  replicas_to_aggregate: 8
  num_steps: 25000
  optimizer {
    momentum_optimizer: {
      learning_rate: {
        cosine_decay_learning_rate {
          learning_rate_base: .04
          total_steps: 25000
          warmup_learning_rate: .013333
          warmup_steps: 2000
        }
      }
      momentum_optimizer_value: 0.9
    }
    use_moving_average: false
  }
  fine_tune_checkpoint_version: V2
  fine_tune_checkpoint: "faster_rcnn_resnet50_v1_640x640_coco17_tpu-8/checkpoint/ckpt-0"
  fine_tune_checkpoint_type: "detection"
  data_augmentation_options {
    random_horizontal_flip {
    }
  }

  max_number_of_boxes: 100
  unpad_groundtruth_tensors: false
  use_bfloat16: true  # works only on TPUs
}

train_input_reader: {
  label_map_path: "label_map.pbtxt"
  tf_record_input_reader {
    input_path: "train.record"
  }
}

eval_config: {
  metrics_set: "coco_detection_metrics"
  use_moving_averages: false
  batch_size: 1;
}

eval_input_reader: {
  label_map_path: "label_map.pbtxt"
  shuffle: false
  num_epochs: 1
  tf_record_input_reader {
    input_path: "test.record"
  }
}
EN

回答 1

Stack Overflow用户

发布于 2021-07-11 18:55:11

我意识到这是图像在样本大小中占用太多内存的问题,根据https://github.com/tensorflow/models/issues/1817,所以我将批处理大小改为2,它起作用了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68338674

复制
相关文章
在文件每一行开头增加字符串
首先,使用vim 打开某txt文件,输入冒号,并输入%s/^/,之后输入要添加的字符串即可
DoubleV
2022/03/25
1.2K0
js 2个空数组相加会得到一个空字符串
虽然是一个很简单的题目,但是答案区的大佬们总能给出各种奇奇怪怪的回答,其中就有一个是这样回答的:
IT工作者
2022/05/13
1.1K0
python 字符串开头结尾匹配
filename = 'spam.txt' filename.endswith('.txt') True filename.startswith('file:') False url = 'http://www.python.org' url.startswith('http:') True 或者正则 import re url = 'http://www.python.org' re.match('http:|https:|ftp:', url) <_sre.SRE_Mat
用户5760343
2022/01/10
1.7K0
为什么浏览器的用户代理字符串以 Mozilla 开头?
为什么浏览器的用户代理字符串(user-agent string)以 Mozilla 开头? 最早流行的浏览器是 NCSA Mosaic,它称自己为 NCSA_Mosaic/2.0 (Windows
前端教程
2018/03/29
1.4K0
为什么浏览器的用户代理字符串以 Mozilla 开头?
python字符串匹配开头_对python 匹配字符串开头和结尾的方法详解
1、你需要通过指定的文本模式去检查字符串的开头或者结尾,比如文件名后缀,URL Scheme 等等。检 查 字 符 串 开 头 或 结 尾 的 一 个 简 单 方 法 是 使 用str.startswith() 或 者 是str.endswith()方法。比如:
全栈程序员站长
2022/09/13
2.9K0
为什么我不建议你用去 “ ! = null " 做判空?
最终,项目中会存在大量判空代码,多么丑陋繁冗!如何避免这种情况?我们是否滥用了判空呢?
用户9239674
2022/01/22
1K0
python 匹配字符串开头和结尾
1.你需要通过指定的文本模式去检查字符串的开头或者结尾,比如文件名后缀,URL Scheme 等等。检 查 字 符 串 开 头 或 结 尾 的 一 个 简 单 方 法 是 使 用str.startswith() 或 者 是str.endswith()方法。比如:
全栈程序员站长
2022/09/16
1.3K0
Python字符串开头或末尾匹配
当你需要通过指定的文本模式去检查字符串的开头或者结尾的时候,比如文件名后缀,URL Scheme等等。
后场技术
2020/09/03
1.8K0
Qml变量名为什么不能大写开头?
大写开头一般都为对象如Item,Rectangle。而小写或下划线开头的则是变量名字或对象实例。如何使用大写开头的变量则会被解释器认为是对象,从而发生错误。 ---- 对象大写开头 例: Item对象 Item { } ---- 变量下划线,小写开头 例: item对象实例,isEnable变量名字 Item { id: item property bool isEnable: true }
Qt君
2019/07/16
1.1K0
解惑 | 为什么我根据时间戳获得的offset为空呢?
最近有一个需求,要查询某一时间戳对应的offset值,于是就想到了使用 ./bin/kafka-run-class.sh kafka.tools.GetOffsetShell --time <timestamp> ,但是我在测试的时候,发现有的时间戳会获取不到offset,是空。但是明明指定的时间戳有上报数据,肯定有对应的 offset 的。于是就谷歌,找到了这篇帖子:
create17
2020/09/24
2.8K0
Python判断字符串是否以字母开头
直接上代码吧 import re rule = re.compile('^[a-zA-z]{1}.*$') str='123' if rule.match(str) is None: print(str+'不以字母开头') else: print(str+'以字母开头') str2='a12' if rule.match(str2) is None: print(str2+'不以字母开头') else: print(str2+'以字母开头')
week
2020/03/12
3K0
为什么阿里禁止 boolean 类型变量使用 is 开头?
平时工作中大家经常使用到 boolean 以及 Boolean 类型的数据,前者是基本数据类型,后者是包装类,为什么不推荐使用 isXXX 来命名呢?到底是用基本类型的数据好呢还是用包装类好呢?
JavaFish
2022/01/17
1.8K0
为什么阿里禁止 boolean 类型变量使用 is 开头?
Dart字符串判空
NullPointerExp是无数java程序员都想消除的问题,OC里,nil对象调方法返回的是nil(这种做法,仁者见仁,智者见智);kotlin和swift通过optional机制,通过编程过程中强化Nullable概念,来避免NPE。
DSoon
2018/12/10
14.7K4
什么?字符串为空?
当字符串为null,undefined,NaN,0,false,""这几个时,if(value)的结果都为false,if(!value)包含了我们常见的空值情况,如果你想要简便的方式,便可以使用它
说故事的五公子
2020/07/21
1.7K0
java 判断字符串是不是以数字开头
目录 1 代码 1 代码 //判断字符串是不是以数字开头 public static boolean isStartWithNumber(String str) { Pattern pattern = Pattern.compile("[0-9]*"); Matcher isNum = pattern.matcher(str.charAt(0)+""); if (!isNum.matches()) { return fa
一写代码就开心
2022/07/09
1.4K0
我曾得到的最佳编程建议
我曾得到的最佳编程建议   这是一个有关于我得到的一些专业性编程建议的故事,以及它如何影响了我的职业生涯。我真心觉得此建议真可谓是字字珠玑,所以我想分享给大家。  建议   还是在1996年,我刚
用户1289394
2018/02/27
7760
我曾得到的最佳编程建议
[781]python去除字符串中开头|结尾|所有字母、数字
参考:https://blog.csdn.net/qq_25792799/article/details/80322889 https://blog.csdn.net/qq_40771567/article/details/86561158 https://www.cnblogs.com/pyse/p/9847812.html http://dy.163.com/v2/article/detail/DMA5CHFN0511RVML.html
周小董
2020/04/08
2.9K0
scrapy框架| 我的第一个Scrapy爬虫
今天咱们就来写一篇简单的、轻松的文章,当然也是我们开始正式去使用Scrapy来写我们的第一个爬虫,我会通过这个爬虫来给大家一一讲解每一句话是啥意思,当然阅读这篇文章之前,我希望大家先去阅读Python|初识scrapy爬虫 ,阅读完后再来看这篇文章。废话不多说了,看下面吧!
Python进击者
2019/06/21
3880
java判断字符串为空
if(s == null ||"".equals(s)); 方法二: 比较字符串长度, 效率高, 是我知道的最好一个方法:
斯文的程序
2019/11/07
2.7K0
【说站】python有哪些is开头的字符串方法
以上就是python is开头的字符串方法,希望对大家有所帮助。更多Python学习指路:python基础教程
很酷的站长
2022/11/24
6410

相似问题

C语言入门

65

尝试使用C语言入门

96

C语言http媒体流入门

11

Windows下JNI和C语言入门

44

新语言入门

20
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档