forked from BVLC/caffe
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Russell91/cpp
Make apollo interface easier to use with C++
- Loading branch information
Showing
7 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import caffe_pb2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <opencv2/core/core.hpp> | ||
|
||
#include <vector> | ||
|
||
#include "caffe/data_layers.hpp" | ||
#include "caffe/layer.hpp" | ||
#include "caffe/util/io.hpp" | ||
|
||
namespace caffe { | ||
|
||
template <typename Dtype> | ||
void MatDataLayer<Dtype>::DataLayerSetUp(const vector<Blob<Dtype>*>& bottom, | ||
const vector<Blob<Dtype>*>& top) { } | ||
|
||
template <typename Dtype> | ||
void MatDataLayer<Dtype>::AddMatVector(const vector<cv::Mat>& mat_vector) { | ||
// reshape layers | ||
batch_size_ = mat_vector.size(); | ||
channels_ = mat_vector[0].channels(); | ||
height_ = mat_vector[0].rows; | ||
width_ = mat_vector[0].cols; | ||
size_ = channels_ * height_ * width_; | ||
CHECK_GT(batch_size_ * size_, 0) << | ||
"batch_size, channels, height, and width must be positive"; | ||
added_data_.Reshape(batch_size_, channels_, height_, width_); | ||
// TODO: is this necessary | ||
added_data_.cpu_data(); | ||
|
||
// Apply data transformations (mirror, scale, crop...) | ||
data_transformer()->Transform(mat_vector, &added_data_); | ||
Dtype* top_data = added_data_.mutable_cpu_data(); | ||
Reset(top_data); | ||
} | ||
|
||
template <typename Dtype> | ||
void MatDataLayer<Dtype>::Reset(Dtype* data) { | ||
CHECK(data); | ||
data_ = data; | ||
} | ||
|
||
template <typename Dtype> | ||
void MatDataLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, | ||
const vector<Blob<Dtype>*>& top) { | ||
CHECK(data_) << "MatDataLayer needs to be initalized by calling Reset"; | ||
top[0]->Reshape(batch_size_, channels_, height_, width_); | ||
top[0]->set_cpu_data(data_); | ||
} | ||
|
||
INSTANTIATE_CLASS(MatDataLayer); | ||
REGISTER_LAYER_CLASS(MatData); | ||
|
||
} // namespace caffe |