-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathblob.cpp
82 lines (70 loc) · 1.26 KB
/
blob.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "blob.h"
Blob::Blob()
{
this->num_ = 0;
this->channel_ = 0;
this->height_ = 0;
this->width_ = 0;
this->counts_ = 0;
data_ = NULL;
}
void Blob::reshape(int num, int channel, int height, int width)
{
this->num_ = num;
this->channel_ = channel;
this->height_ = height;
this->width_ = width;
this->counts_ = this->num_ * this->channel_ * this->height_ * this->width_;
if (data_ != NULL)
{
free(data_);
}
data_ = (float*)malloc(sizeof(float) * counts_);
}
//½«Êý¾Ý´æ·Å½øblob
void Blob::set_data(float* data)
{
caffe_copy(this->counts_, data, this->data_);
}
void Blob::release()
{
if (data_ != NULL)
{
free(data_);
data_ = NULL;
}
}
float* Blob::cpu_data()
{
return data_;
}
int Blob::shape(int index)
{
switch (index)
{
case 0:
return this->num_;
break;
case 1:
return this->channel_;
break;
case 2:
return this->height_;
break;
case 3:
return this->width_;
break;
}
}
int Blob::count(int start_axis, int end_axis)
{
int count = 1;
for (int i = start_axis; i < end_axis; ++i) {
count *= shape(i);
}
return count;
}
int Blob::offset(int n, int c, int h, int w)
{
return ((n * this->channel_ + c) * this->height_ + h) * this->width_ + w;
}