Skip to content

Commit

Permalink
added data layer for jittering, tiling layer for per pix softmax, tes…
Browse files Browse the repository at this point in the history
…ts, example networks and visualizations. will remove legacy code later
  • Loading branch information
cheeyos committed Dec 17, 2014
1 parent 9368c19 commit c27a408
Show file tree
Hide file tree
Showing 26 changed files with 3,634 additions and 99 deletions.
145 changes: 72 additions & 73 deletions examples/filter_visualization_driving.ipynb

Large diffs are not rendered by default.

696 changes: 696 additions & 0 deletions examples/filter_visualization_driving_softmax.ipynb

Large diffs are not rendered by default.

67 changes: 66 additions & 1 deletion include/caffe/data_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class BasePrefetchingDataLayer :
Blob<Dtype> prefetch_label_;
};


template <typename Dtype>
class DataLayer : public BasePrefetchingDataLayer<Dtype> {
public:
Expand Down Expand Up @@ -127,6 +128,69 @@ class DataLayer : public BasePrefetchingDataLayer<Dtype> {
MDB_val mdb_key_, mdb_value_;
};

template <typename Dtype>
class DrivingDataLayer :
public BaseDataLayer<Dtype>, public InternalThread {
public:
explicit DrivingDataLayer(const LayerParameter& param)
: BaseDataLayer<Dtype>(param) {}

virtual ~DrivingDataLayer();
virtual void DataLayerSetUp(
const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);
void LayerSetUp(
const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);

virtual inline LayerParameter_LayerType type() const {
return LayerParameter_LayerType_DRIVING_DATA;
}

virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);
virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);

virtual inline int ExactNumBottomBlobs() const { return 0; }
virtual inline int MinTopBlobs() const { return 1; }
virtual inline int MaxTopBlobs() const { return 1000; }

virtual void CreatePrefetchThread();
virtual void JoinPrefetchThread();

protected:
virtual void InternalThreadEntry();

// Assume network has tiling layer.
bool ReadBoundingBoxLabelToDatum(
const DrivingData& data, Datum* datum,
const int h_off, const int w_off);

// Use channels for the resolution of tiled convolution.
bool ReadBoundingBoxLabelToDatumLegacy(
const DrivingData& data, Datum* datum,
const int h_off, const int w_off);

unsigned int Rand();

vector<Blob<Dtype>*> prefetch_datas_;
vector<Blob<Dtype>*> prefetch_labels_;

shared_ptr<Caffe::RNG> rng_;

// LEVELDB
shared_ptr<leveldb::DB> db_;
shared_ptr<leveldb::Iterator> iter_;
// LMDB
MDB_env* mdb_env_;
MDB_dbi mdb_dbi_;
MDB_txn* mdb_txn_;
MDB_cursor* mdb_cursor_;
MDB_val mdb_key_, mdb_value_;
};


/**
* @brief Provides data to the Net generated by a Filler.
*
Expand Down Expand Up @@ -354,7 +418,8 @@ class MemoryDataLayer : public BaseDataLayer<Dtype> {
public:
explicit MemoryDataLayer(const LayerParameter& param)
: BaseDataLayer<Dtype>(param), has_new_data_(false) {}
virtual void DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,
virtual void DataLayerSetUp(
const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);

virtual inline LayerParameter_LayerType type() const {
Expand Down
44 changes: 44 additions & 0 deletions include/caffe/vision_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,50 @@ class CuDNNPoolingLayer : public PoolingLayer<Dtype> {
};
#endif

/**
* @brief for transforming a C x H x W blob into a
* C/t^2 x H*t x W*t blob where t is the tile dimension, and each pixel in
* the input is turned into a txt grid from the channels in row major order.
*
*/
template <typename Dtype>
class TilingLayer : public Layer<Dtype> {
public:
explicit TilingLayer(const LayerParameter& param)
: Layer<Dtype>(param) {}
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);
virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);

virtual inline LayerParameter_LayerType type() const {
return LayerParameter_LayerType_TILING;
}

virtual inline int ExactNumBottomBlobs() const { return 1; }
virtual inline int MinTopBlobs() const { return 1; }
// MAX POOL layers can output an extra top blob for the mask;
// others can only output the pooled inputs.
virtual inline int MaxTopBlobs() const { return 1; }

protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);
virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, vector<Blob<Dtype>*>* bottom);
virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, vector<Blob<Dtype>*>* bottom);

int input_channels_, output_channels_;
int input_width_, input_height_;
int output_width_, output_height_;
int count_per_input_map_, count_per_output_map_;
int tile_dim_, tile_dim_sq_;
};


} // namespace caffe

#endif // CAFFE_VISION_LAYERS_HPP_
Loading

0 comments on commit c27a408

Please sign in to comment.