Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#3420·caffe

Is this a BUG in blob->offset(n) ?

Author: cookyecatCreated Dec 6, 2015Updated Jun 24, 2026
Labelsbug

Say the input shape is 10 * 192 * 32 * 32. Then:

bottom[0]->offset(0)   will be 0.
bottom[0]->offset(1)   will be 196608.
bottom[0]->offset(2)   will be 393216.
...
bottom[0]->offset(9)   will be 1769472.
bottom[0]->offset(10)  will be 1966080.

There isn't bottom[0]->offset(11) .

The last one in a batch is in offset(9) because we start at zero. So, I think there shouldn't be offset(10). If we read bottom[0]->cpu_data()[1966080], the code will exit without any error prompt.

In the file blob.hpp, offset() is defined as:

  inline int offset(const int n, const int c = 0, const int h = 0,
      const int w = 0) const {
    CHECK_GE(n, 0);
    CHECK_LE(n, num());
    CHECK_GE(channels(), 0);
    CHECK_LE(c, channels());
    CHECK_GE(height(), 0);
    CHECK_LE(h, height());
    CHECK_GE(width(), 0);
    CHECK_LE(w, width());
    return ((n * channels() + c) * height() + h) * width() + w;
  }

is CHECK_LE(n, num() - 1) better? I'm not sure if what I've found is a problem.

Source: BVLC/caffe

View original on GitHubView discussion on GitHub