// 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
--- /dev/null
+// 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_
}
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 {
// 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;