Skip to content

Commit

Permalink
Merge pull request BVLC#1 from cheeyos/lane
Browse files Browse the repository at this point in the history
Lane
  • Loading branch information
twangcat committed Dec 1, 2014
2 parents d771232 + 8dd7595 commit ab15e8c
Show file tree
Hide file tree
Showing 36 changed files with 6,279 additions and 277 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ distribute/*
python/caffe/proto/

# Editor temporaries
*.swp
*.sw?
*~

# IPython notebook checkpoints
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,12 @@ LIBRARIES += pthread \
glog gflags protobuf leveldb snappy \
lmdb \
boost_system \
python2.7 \
boost_python \
boost_numpy \
hdf5_hl hdf5 \
opencv_core opencv_highgui opencv_imgproc
PYTHON_LIBRARIES := boost_python python2.7
PYTHON_LIBRARIES := boost_python boost_numpy python2.7 opencv_core opencv_highgui opencv_imgproc
WARNINGS := -Wall -Wno-sign-compare

##############################
Expand Down
76 changes: 74 additions & 2 deletions include/caffe/data_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <string>
#include <utility>
#include <vector>

#include "boost/scoped_ptr.hpp"
#include "hdf5.h"
#include "leveldb/db.h"
Expand All @@ -17,7 +16,10 @@
#include "caffe/internal_thread.hpp"
#include "caffe/layer.hpp"
#include "caffe/proto/caffe.pb.h"

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/imgproc/imgproc.hpp>
namespace caffe {

#define HDF5_DATA_DATASET_NAME "data"
Expand Down Expand Up @@ -272,6 +274,76 @@ class ImageDataLayer : public BasePrefetchingDataLayer<Dtype> {
int lines_id_;
};


/**
* @brief Provides data to the Net from video files.
*
* TODO(dox): thorough documentation for Forward and proto params.
*/
template <typename Dtype>
class VideoDataLayer : public BasePrefetchingDataLayer<Dtype> {
public:
explicit VideoDataLayer(const LayerParameter& param)
: BasePrefetchingDataLayer<Dtype>(param) {}
virtual ~VideoDataLayer();
virtual void DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);

virtual inline LayerParameter_LayerType type() const {
return LayerParameter_LayerType_VIDEO_DATA;
}
virtual inline int ExactNumBottomBlobs() const { return 0; }
virtual inline int ExactNumTopBlobs() const { return 1; }

protected:
shared_ptr<Caffe::RNG> prefetch_rng_;
virtual void ShuffleBatches();
virtual void InternalThreadEntry();
bool ReadVideoFrameToDatum(const string& filename, size_t id,
size_t persp, const int height, const int width, Datum* datum);
void setPerspective();
//inline bool ReadVideoBatchToDatum(const string& filename, std::vector<size_t> frameIds,
// std::vector<size_t>trans, Datum* datum) {
// return ReadVideoBatchToDatum(filename, frameIds, trans, 0, 0, datum);
//}

vector<std::pair<std::string, std::pair<std::vector<size_t>, std::vector<size_t> > > > lines_;
int lines_id_;
std::vector<cv::Mat> mTransforms;
cv::VideoCapture* cap;
};


/**
* @brief Provides multilane labels to the Net.
*
* TODO(dox): thorough documentation for Forward and proto params.
*/
template <typename Dtype>
class MultilaneLabelLayer : public BasePrefetchingDataLayer<Dtype> {
public:
explicit MultilaneLabelLayer(const LayerParameter& param)
: BasePrefetchingDataLayer<Dtype>(param) {}
virtual ~MultilaneLabelLayer();
virtual void DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);

virtual inline LayerParameter_LayerType type() const {
return LayerParameter_LayerType_VIDEO_DATA;
}
virtual inline int ExactNumBottomBlobs() const { return 0; }
virtual inline int ExactNumTopBlobs() const { return 1; }

protected:
shared_ptr<Caffe::RNG> prefetch_rng_;
virtual void ShuffleBatches();
virtual void InternalThreadEntry();
//boost::numpy::ndarray ReadLabelBatch(const string& filename, std::vector<size_t> &frame_ids, std::vector<size_t> trans, const int height, const int width);

vector<std::pair<std::string, std::pair<std::vector<int>, std::vector<int> > > > lines_;
int lines_id_;
};

/**
* @brief Provides data to the Net from memory.
*
Expand Down
3 changes: 3 additions & 0 deletions include/caffe/util/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ inline bool ReadImageToDatum(const string& filename, const int label,
return ReadImageToDatum(filename, label, 0, 0, datum);
}




leveldb::Options GetLevelDBOptions();

template <typename Dtype>
Expand Down
Loading

0 comments on commit ab15e8c

Please sign in to comment.