前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Check failed: shape[i] >= 0 (-1 vs. 0)错误

Check failed: shape[i] >= 0 (-1 vs. 0)错误

作者头像
Tyan
发布2017-12-28 16:59:31
1.3K0
发布2017-12-28 16:59:31
举报
文章被收录于专栏:SnailTyan

在使用Caffe模型进行图像分类时,通常使用的图像大小为224 * 224,如果改变输入图像的大小,有时候会碰到Check failed: shape[i] >= 0 (-1 vs. 0)错误。

  • 背景

使用ResNet-50进行图像分类训练,输入图像的大小为160 *160

  • 错误
代码语言:javascript
复制
I1013 10:53:03.395526 76959 net.cpp:129] Top shape: 16 2048 5 5 (819200)
I1013 10:53:03.395531 76959 net.cpp:137] Memory required for data: 1889075264
I1013 10:53:03.395539 76959 layer_factory.hpp:77] Creating layer res5c_relu
I1013 10:53:03.395553 76959 net.cpp:84] Creating Layer res5c_relu
I1013 10:53:03.395567 76959 net.cpp:406] res5c_relu <- res5c
I1013 10:53:03.395594 76959 net.cpp:367] res5c_relu -> res5c (in-place)
I1013 10:53:03.395841 76959 net.cpp:122] Setting up res5c_relu
I1013 10:53:03.395855 76959 net.cpp:129] Top shape: 16 2048 5 5 (819200)
I1013 10:53:03.395861 76959 net.cpp:137] Memory required for data: 1892352064
I1013 10:53:03.395869 76959 layer_factory.hpp:77] Creating layer pool5
I1013 10:53:03.395900 76959 net.cpp:84] Creating Layer pool5
I1013 10:53:03.395908 76959 net.cpp:406] pool5 <- res5c
I1013 10:53:03.395931 76959 net.cpp:380] pool5 -> pool5
F1013 10:53:03.396807 76959 blob.cpp:32] Check failed: shape[i] >= 0 (-1 vs. 0)
*** Check failure stack trace: ***
    @     0x7fa7eef89e6d  (unknown)
    @     0x7fa7eef8bced  (unknown)
    @     0x7fa7eef89a5c  (unknown)
    @     0x7fa7eef8c63e  (unknown)
    @     0x7fa7f6141829  caffe::Blob<>::Reshape()
    @     0x7fa7f6141581  caffe::Blob<>::Reshape()
    @     0x7fa7f6200958  caffe::PoolingLayer<>::Reshape()
    @     0x7fa7f61b14d8  caffe::CuDNNPoolingLayer<>::Reshape()
    @     0x7fa7f6167d29  caffe::Layer<>::SetUp()
    @     0x7fa7f6240213  caffe::Net<>::Init()
    @     0x7fa7f623e7ea  caffe::Net<>::Net()
    @     0x7fa7f62711e1  caffe::Solver<>::InitTrainNet()
    @     0x7fa7f6270a75  caffe::Solver<>::Init()
    @     0x7fa7f62705a7  caffe::Solver<>::Solver()
    @     0x7fa7f627dc66  caffe::SGDSolver<>::SGDSolver()
    @     0x7fa7f6287ab1  caffe::Creator_SGDSolver<>()
    @           0x4215f5  caffe::SolverRegistry<>::CreateSolver()
    @           0x41bdce  train()
    @           0x41e167  main
    @     0x7fa7e20eeb35  __libc_start_main
    @           0x41aa69  (unknown)
  • 解决方案

错误日志中可以看出问题出在pool5层,它的输入为Top shape: 16 2048 5 5 (819200),即16 * 2048 * 5 * 516batch_size2048channel数量,即kernel个数,feature map大小为5 * 5,在prototxt中找到pool5层,如下:

代码语言:javascript
复制
layer {
    bottom: "res5c"
    top: "pool5"
    name: "pool5"
    type: "Pooling"
    pooling_param {
        kernel_size: 7
        stride: 1
        pool: AVE
    }
}

kernel size为7,比5大,因此将7改为5,重新训练,没问题。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-10-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档