69 #include "cyber/common/log.h" 73 namespace perception {
84 template <
typename Dtype>
88 explicit Blob(
bool use_cuda_host_malloc)
96 const bool use_cuda_host_malloc =
false);
97 explicit Blob(
const std::vector<int>&
shape,
98 const bool use_cuda_host_malloc =
false);
104 void Reshape(
const int num,
const int channels,
const int height,
120 void Reshape(
const std::vector<int>& shape);
123 std::ostringstream stream;
124 for (
int i = 0; i <
shape_.size(); ++i) {
125 stream <<
shape_[i] <<
" ";
127 stream <<
"(" <<
count_ <<
")";
153 inline int count(
int start_axis,
int end_axis)
const {
154 CHECK_LE(start_axis, end_axis);
155 CHECK_GE(start_axis, 0);
156 CHECK_GE(end_axis, 0);
160 for (
int i = start_axis; i < end_axis; ++i) {
171 inline int count(
int start_axis)
const {
198 <<
"axis " << axis_index <<
" out of range for " <<
num_axes()
201 <<
"axis " << axis_index <<
" out of range for " <<
num_axes()
203 if (axis_index < 0) {
219 <<
"Cannot use legacy accessors on Blobs with > 4 axes.";
231 inline int offset(
const int n,
const int c = 0,
const int h = 0,
232 const int w = 0)
const {
239 CHECK_GE(
width(), 0);
240 CHECK_LE(w,
width());
244 inline int offset(
const std::vector<int>& indices)
const {
245 CHECK_LE(indices.size(),
num_axes());
247 for (
int i = 0; i <
num_axes(); ++i) {
249 if (indices.size() > i) {
250 CHECK_GE(indices[i], 0);
251 CHECK_LT(indices[i],
shape(i));
252 offset += indices[i];
267 inline Dtype
data_at(
const int n,
const int c,
const int h,
272 inline Dtype
data_at(
const std::vector<int>& index)
const {
276 inline const std::shared_ptr<SyncedMemory>&
data()
const {
304 std::shared_ptr<SyncedMemory>
data_;
312 template <
typename Dtype>
314 template <
typename Dtype>
Dtype * mutable_cpu_data()
Dtype data_at(const std::vector< int > &index) const
Definition: blob.h:272
int channels() const
Deprecated legacy shape accessor channels: use shape(1) instead.
Definition: blob.h:212
int shape(int index) const
Returns the dimension of the index-th axis (or the negative index-th axis from the end...
Definition: blob.h:139
Dtype data_at(const int n, const int c, const int h, const int w) const
Definition: blob.h:267
void set_head_gpu()
Definition: blob.h:288
int offset(const int n, const int c=0, const int h=0, const int w=0) const
Definition: blob.h:231
SyncedHead
Definition: syncedmem.h:101
void ReshapeLike(const Blob &other)
int count() const
Definition: blob.h:143
int num() const
Deprecated legacy shape accessor num: use shape(0) instead.
Definition: blob.h:210
int height() const
Deprecated legacy shape accessor height: use shape(2) instead.
Definition: blob.h:214
void set_cpu_data(Dtype *data)
int CanonicalAxisIndex(int axis_index) const
create RoI Blob.
Definition: blob.h:196
std::string shape_string() const
Definition: blob.h:122
A wrapper around SyncedMemory holders serving as the basic computational unit for images...
Definition: blob.h:85
void Reshape(const int num, const int channels, const int height, const int width)
Deprecated; use Reshape(const std::vector<int>& shape).
Blob(bool use_cuda_host_malloc)
Definition: blob.h:88
std::vector< int > shape_
Definition: blob.h:306
void set_gpu_data(Dtype *data)
int count(int start_axis, int end_axis) const
Compute the volume of a slice; i.e., the product of dimensions among a range of axes.
Definition: blob.h:153
const Dtype * gpu_data() const
std::shared_ptr< const Blob< Dtype > > BlobConstPtr
Definition: blob.h:315
int count_
Definition: blob.h:307
Dtype * mutable_gpu_data()
int count(int start_axis) const
Compute the volume of a slice spanning from a particular first axis to the final axis.
Definition: blob.h:171
int LegacyShape(int index) const
Definition: blob.h:217
const int kMaxBlobAxes
Definition: blob.h:76
const Dtype * cpu_data() const
void CopyFrom(const Blob< Dtype > &source, bool reshape=false)
Copy from a source Blob.
std::shared_ptr< SyncedMemory > shape_data_
Definition: blob.h:305
std::shared_ptr< SyncedMemory > data_
Definition: blob.h:304
std::shared_ptr< Blob< Dtype > > BlobPtr
Definition: blob.h:313
int offset(const std::vector< int > &indices) const
Definition: blob.h:244
const std::shared_ptr< SyncedMemory > & data() const
Definition: blob.h:276
void operator=(const Blob &)=delete
int width() const
Deprecated legacy shape accessor width: use shape(3) instead.
Definition: blob.h:216
void ShareData(const Blob &other)
Set the data_ std::shared_ptr to point to the SyncedMemory holding the data_ of Blob other – useful ...
void set_head_cpu()
Definition: blob.h:289
const int * gpu_shape() const
SyncedMemory::SyncedHead head() const
Definition: blob.h:290
const std::vector< int > & shape() const
Definition: blob.h:130
int num_axes() const
Definition: blob.h:142
int capacity_
Definition: blob.h:308
Blob()
Definition: blob.h:87
bool use_cuda_host_malloc_
Definition: blob.h:309