summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f9f52b9)
raw | patch | inline | side by side (parent: f9f52b9)
author | Yangqing Jia <jiayq84@gmail.com> | |
Wed, 25 Sep 2013 03:08:56 +0000 (20:08 -0700) | ||
committer | Yangqing Jia <jiayq84@gmail.com> | |
Wed, 25 Sep 2013 03:08:56 +0000 (20:08 -0700) |
src/caffe/layers/data_layer.cpp | patch | blob | history | |
src/caffe/net.hpp | [new file with mode: 0644] | patch | blob |
src/caffe/proto/caffe.proto | patch | blob | history | |
src/caffe/test/test_data_layer.cpp | patch | blob | history |
index 3cd76d124cb7c7cef07890a858535d4217bb2289..c4bb8cc5311bdef05b86e84a5aad0ca45075882a 100644 (file)
// Copyright 2013 Yangqing Jia
+#include <stdint.h>
+#include <string>
#include <vector>
#include <leveldb/db.h>
#include "caffe/layer.hpp"
#include "caffe/vision_layers.hpp"
+using std::string;
+
namespace caffe {
template <typename Dtype>
// Read a data point, and use it to initialize the top blob.
Datum datum;
datum.ParseFromString(iter_->value().ToString());
- const BlobProto& blob = datum.blob();
// image
(*top)[0]->Reshape(
- this->layer_param_.batchsize(), blob.channels(), blob.height(),
- blob.width());
+ this->layer_param_.batchsize(), datum.channels(), datum.height(),
+ datum.width());
// label
(*top)[1]->Reshape(this->layer_param_.batchsize(), 1, 1, 1);
// datum size
- datum_size_ = blob.data_size();
+ datum_size_ = datum.data().size();
}
template <typename Dtype>
for (int i = 0; i < this->layer_param_.batchsize(); ++i) {
// get a blob
datum.ParseFromString(iter_->value().ToString());
- const BlobProto& blob = datum.blob();
+ const string& data = datum.data();
for (int j = 0; j < datum_size_; ++j) {
- top_data[i * datum_size_ + j] = blob.data(j);
+ top_data[i * datum_size_ + j] = (uint8_t)data[j];
}
top_label[i] = datum.label();
// go to the next iter
diff --git a/src/caffe/net.hpp b/src/caffe/net.hpp
--- /dev/null
+++ b/src/caffe/net.hpp
@@ -0,0 +1,53 @@
+// Copyright 2013 Yangqing Jia
+
+#ifndef CAFFE_LAYER_H_
+#define CAFFE_LAYER_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "caffe/blob.hpp"
+#include "caffe/common.hpp"
+#include "caffe/proto/caffe.pb.h"
+
+using std::map;
+using std::vector;
+using std::string;
+
+namespace caffe {
+
+template <typename Dtype>
+class Net {
+ public:
+ explicit Net(const NetParameter& param);
+ ~Net();
+ void Forward(const vector<Blob<Dtype*>> & bottom,
+ vector<Blob<Dtype*>* top);
+ Dtype Backward(const vector<Blob<Dtype*>> & bottom,
+ vector<Blob<Dtype*>* top);
+
+ // For an already initialized net, CopyTrainedLayersFrom() copies the already
+ // trained layers from another net parameter instance.
+ void CopyTrainedLayersFrom(const NetParameter& param);
+ // Writes the net to a proto.
+ void ToProto(NetParameter* param, bool write_diff = false);
+
+ protected:
+ // Individual layers in the net
+ vector<shared_ptr<Layer<Dtype> > > layers_;
+ vector<shared_ptr<Layer<Dtype> > > layer_names_;
+ // bottom_vecs stores the vectors containing the input for each layer
+ vector<vector<Blob<Dtype>*> > bottom_vecs_;
+ // top_vecs stores the vectors containing the output for each layer
+ vector<vector<Blob<Dtype>* > top_vecs_;
+ // blobs stores the blobs that store intermediate results between the
+ // layers.
+ vector<shared_ptr<Blob<Dtype> > blobs_;
+ vector<shared_ptr<Blob<Dtype> > blob_names_;
+};
+
+
+} // namespace caffe
+
+#endif // CAFFE_LAYER_H_
index cb8c7c4b7e4d8943a4591ad1147d5bd16d6196c3..8f7e0c3328622a41c0d625ddb21863c1b65379ec 100644 (file)
}
message Datum {
- optional BlobProto blob = 1;
- optional int32 label = 2;
+ optional int32 channels = 1;
+ optional int32 height = 2;
+ optional int32 width = 3;
+ // the actual image data, in bytes
+ optional bytes data = 4;
+ optional int32 label = 5;
}
message FillerParameter {
index a080bc266009ccb4af2e7eee2520e70c5c3d7aa0..ce0d24e549953fd41765141d57a61a8a442a40f4 100644 (file)
// Copyright 2013 Yangqing Jia
-#include <cstring>
#include <cuda_runtime.h>
#include <leveldb/db.h>
+#include <string>
+
#include "gtest/gtest.h"
#include "caffe/blob.hpp"
#include "caffe/common.hpp"
#include "caffe/proto/caffe.pb.h"
#include "caffe/test/test_caffe_main.hpp"
+using std::string;
+
namespace caffe {
extern cudaDeviceProp CAFFE_TEST_CUDA_PROP;
for (int i = 0; i < 5; ++i) {
Datum datum;
datum.set_label(i);
- BlobProto* blob = datum.mutable_blob();
- blob->set_num(1);
- blob->set_channels(2);
- blob->set_height(3);
- blob->set_width(4);
+ datum.set_channels(2);
+ datum.set_height(3);
+ datum.set_width(4);
+ std::string* data = datum.mutable_data();
for (int j = 0; j < 24; ++j) {
- blob->add_data(i);
+ data->push_back((uint8_t)i);
}
stringstream ss;
ss << i;