forked from BVLC/caffe
-
Notifications
You must be signed in to change notification settings - Fork 43
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 BVLC#1639 from longjon/crop-layer
Crop layer for automatically aligning computations
- Loading branch information
Showing
14 changed files
with
955 additions
and
342 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,61 @@ | ||
#ifndef CAFFE_UTIL_COORDS_H_ | ||
#define CAFFE_UTIL_COORDS_H_ | ||
|
||
#include <algorithm> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace caffe { | ||
|
||
template <typename Dtype> | ||
class DiagonalAffineMap { | ||
public: | ||
explicit DiagonalAffineMap(const vector<pair<Dtype, Dtype> > coefs) | ||
: coefs_(coefs) { } | ||
static DiagonalAffineMap identity(const int nd) { | ||
return DiagonalAffineMap(vector<pair<Dtype, Dtype> >(nd, make_pair(1, 0))); | ||
} | ||
|
||
inline DiagonalAffineMap compose(const DiagonalAffineMap& other) const { | ||
CHECK_EQ(coefs_.size(), other.coefs_.size()) | ||
<< "Attempt to compose DiagonalAffineMaps of different dimensions"; | ||
DiagonalAffineMap<Dtype> out; | ||
transform(coefs_.begin(), coefs_.end(), other.coefs_.begin(), | ||
std::back_inserter(out.coefs_), &compose_coefs); | ||
return out; | ||
} | ||
inline DiagonalAffineMap inv() const { | ||
DiagonalAffineMap<Dtype> out; | ||
transform(coefs_.begin(), coefs_.end(), std::back_inserter(out.coefs_), | ||
&inv_coefs); | ||
return out; | ||
} | ||
inline vector<pair<Dtype, Dtype> > coefs() { return coefs_; } | ||
|
||
private: | ||
DiagonalAffineMap() { } | ||
static inline pair<Dtype, Dtype> compose_coefs(pair<Dtype, Dtype> left, | ||
pair<Dtype, Dtype> right) { | ||
return make_pair(left.first * right.first, | ||
left.first * right.second + left.second); | ||
} | ||
static inline pair<Dtype, Dtype> inv_coefs(pair<Dtype, Dtype> coefs) { | ||
return make_pair(1 / coefs.first, - coefs.second / coefs.first); | ||
} | ||
vector<pair<Dtype, Dtype> > coefs_; | ||
}; | ||
|
||
template <typename Dtype> | ||
DiagonalAffineMap<Dtype> FilterMap(const int kernel_h, const int kernel_w, | ||
const int stride_h, const int stride_w, const int pad_h, const int pad_w) { | ||
vector<pair<Dtype, Dtype> > coefs; | ||
coefs.push_back(make_pair(stride_h, | ||
static_cast<Dtype>(kernel_h - 1) / 2 - pad_h)); | ||
coefs.push_back(make_pair(stride_w, | ||
static_cast<Dtype>(kernel_w - 1) / 2 - pad_w)); | ||
return DiagonalAffineMap<Dtype>(coefs); | ||
} | ||
|
||
} // namespace caffe | ||
|
||
#endif // CAFFE_UTIL_COORDS_H_ |
Oops, something went wrong.