New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the discretize function. Design changes as discussed. #703
Changes from 9 commits
b38b688
6e1740b
5bab953
b506eea
f788f97
49c25fe
9399cd3
0abec2c
987f079
f041da4
08bd550
2f8f3c7
e9987d9
72eb1ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,8 @@ set(DIRS | |
decision_stump | ||
det | ||
emst | ||
fastmks | ||
edge_boxes | ||
# fastmks | ||
gmm | ||
hmm | ||
hoeffding_trees | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
cmake_minimum_required(VERSION 2.8) | ||
|
||
# Define the files we need to compile. | ||
# Anything not in this list will not be compiled into mlpack. | ||
set(SOURCES | ||
feature_extraction.hpp | ||
feature_extraction_impl.hpp | ||
) | ||
|
||
# Add directory name to sources. | ||
set(DIR_SRCS) | ||
foreach(file ${SOURCES}) | ||
set(DIR_SRCS ${DIR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/${file}) | ||
endforeach() | ||
# Append sources (with directory name) to list of all mlpack sources (used at | ||
# the parent scope). | ||
set(MLPACK_SRCS ${MLPACK_SRCS} ${DIR_SRCS} PARENT_SCOPE) | ||
|
||
add_cli_executable(edge_boxes) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* @file decision_stump.hpp | ||
* @author | ||
* | ||
* Definition of decision stumps. | ||
*/ | ||
#include <mlpack/core.hpp> | ||
#include "feature_extraction.hpp" | ||
|
||
using namespace mlpack; | ||
using namespace mlpack::structured_tree; | ||
using namespace std; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
CLI::ParseCommandLine(argc, argv); | ||
/* | ||
:param options: | ||
num_images: number of images in the dataset. | ||
rgbd: 0 for RGB, 1 for RGB + depth | ||
shrink: amount to shrink channels | ||
n_orient: number of orientations per gradient scale | ||
grd_smooth_rad: radius for image gradient smoothing | ||
grd_norm_rad: radius for gradient normalization | ||
reg_smooth_rad: radius for reg channel smoothing | ||
ss_smooth_rad: radius for sim channel smoothing | ||
p_size: size of image patches | ||
g_size: size of ground truth patches | ||
n_cell: number of self similarity cells | ||
|
||
n_pos: number of positive patches per tree | ||
n_neg: number of negative patches per tree | ||
fraction: fraction of features to use to train each tree | ||
n_tree: number of trees in forest to train | ||
n_class: number of classes (clusters) for binary splits | ||
min_count: minimum number of data points to allow split | ||
min_child: minimum number of data points allowed at child nodes | ||
max_depth: maximum depth of tree | ||
split: options include 'gini', 'entropy' and 'twoing' | ||
discretize: optional function mapping structured to class labels | ||
|
||
stride: stride at which to compute edges | ||
sharpen: sharpening amount (can only decrease after training) | ||
n_tree_eval: number of trees to evaluate per location | ||
nms: if true apply non-maximum suppression to edges | ||
*/ | ||
|
||
FeatureParameters params = FeatureParameters(); | ||
|
||
params.NumImages(2); | ||
params.RowSize(321); | ||
params.ColSize(481); | ||
params.RGBD(0); | ||
params.Shrink(2); | ||
params.NumOrient(4); | ||
params.GrdSmoothRad(0); | ||
params.GrdNormRad(4); | ||
params.RegSmoothRad(2); | ||
params.SSSmoothRad(8); | ||
params.Fraction(0.25); | ||
params.PSize(32); | ||
params.GSize(16); | ||
params.NumCell(5); | ||
params.NumPos(10000); | ||
params.NumNeg(10000); | ||
params.NumCell(5); | ||
params.NumTree(8); | ||
StructuredForests <arma::mat, arma::cube> SF(params); | ||
// arma::uvec x(2); | ||
//SF.GetFeatureDimension(x); | ||
|
||
arma::mat segmentations, boundaries, images; | ||
data::Load("/home/nilay/example/small_images.csv", images); | ||
data::Load("/home/nilay/example/small_boundary_1.csv", boundaries); | ||
data::Load("/home/nilay/example/small_segmentation_1.csv", segmentations); | ||
|
||
SF.PrepareData(images, boundaries, segmentations); | ||
cout << "PrepareData done." << endl; | ||
return 0; | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* @file feature_extraction.hpp | ||
* @author Nilay Jain | ||
* | ||
* Feature Extraction for the edge_boxes algorithm. | ||
*/ | ||
#ifndef MLPACK_METHODS_EDGE_BOXES_STRUCTURED_TREE_HPP | ||
#define MLPACK_METHODS_EDGE_BOXES_STRUCTURED_TREE_HPP | ||
//#define INF 999999.9999 | ||
//#define EPS 1E-20 | ||
#include <mlpack/core.hpp> | ||
#include "feature_parameters.hpp" | ||
namespace mlpack { | ||
namespace structured_tree { | ||
|
||
template <typename MatType = arma::mat, typename CubeType = arma::cube> | ||
class StructuredForests | ||
{ | ||
private: | ||
FeatureParameters params; | ||
static constexpr double eps = 1e-20; | ||
|
||
public: | ||
|
||
|
||
StructuredForests(FeatureParameters F); | ||
/* MatType LoadData(MatType const &images, MatType const &boundaries,\ | ||
MatType const &segmentations);*/ | ||
|
||
void PrepareData(const MatType& Images, const MatType& Boundaries,\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you remove the ""? |
||
const MatType& Segmentations); | ||
|
||
void GetFeatureDimension(arma::vec& FtrDim); | ||
|
||
void DistanceTransform1D(const arma::vec& f, const size_t n,\ | ||
const double inf, arma::vec& d); | ||
|
||
void DistanceTransform2D(MatType &Im, const double inf); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that Variable, reference, and pointer names begin with a lower case letter. Take a look at: https://github.com/mlpack/mlpack/wiki/DesignGuidelines#naming-conventions for more informations. |
||
|
||
void DistanceTransformImage(const MatType& Im, double on, MatType& Out); | ||
|
||
void GetFeatures(const MatType &Image, arma::umat &loc,\ | ||
CubeType& RegFtr, CubeType& SSFtr,\ | ||
const arma::vec& table); | ||
|
||
void CopyMakeBorder(const CubeType& InImage, size_t top, | ||
size_t left, size_t bottom, size_t right, | ||
CubeType& OutImage); | ||
|
||
void GetShrunkChannels(const CubeType& InImage, CubeType ®_ch,\ | ||
CubeType &ss_ch, const arma::vec& table); | ||
|
||
void RGB2LUV(const CubeType& InImage, CubeType& OutImage,\ | ||
const arma::vec& table); | ||
|
||
void BilinearInterpolation(const MatType& src, | ||
size_t height, size_t width, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you forgot const?const size_t height, const size_t width? |
||
MatType& dst); | ||
|
||
void SepFilter2D(CubeType &InOutImage, const arma::vec& kernel, const size_t radius); | ||
|
||
void ConvTriangle(CubeType &InImage, const size_t radius); | ||
|
||
void Gradient(const CubeType& InImage, | ||
MatType& Magnitude, | ||
MatType& Orientation); | ||
|
||
void MaxAndLoc(CubeType &mag, arma::umat &Location, MatType& MaxVal) const; | ||
|
||
void Histogram(const MatType& Magnitude, | ||
const MatType& Orientation, | ||
size_t downscale, size_t interp, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you forgot const?const size_t downscale, const size_t interp? |
||
CubeType& HistArr); | ||
|
||
void ViewAsWindows(const CubeType& channels, const arma::umat& loc, | ||
CubeType& features); | ||
|
||
void GetRegFtr(const CubeType& channels, const arma::umat& loc, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use the doxygen style to cite the paper. Here is an example: https://github.com/mlpack/mlpack/blob/master/src/mlpack/methods/ann/layer/dropout_layer.hpp |
||
CubeType& RegFtr); | ||
|
||
void GetSSFtr(const CubeType& channels, const arma::umat& loc, | ||
CubeType SSFtr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering, why I don't see any similarity features, turns out we missed a reference here. |
||
|
||
void Rearrange(const CubeType& channels, CubeType& ch); | ||
|
||
void PDist(const CubeType& features, const arma::uvec& grid_pos, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not use an underscore for parameter names. |
||
CubeType& Output); | ||
|
||
size_t IndexMin(arma::vec& k); | ||
|
||
size_t Discretize(const MatType& labels, const size_t nClass,\ | ||
const size_t nSample, arma::vec& DiscreteLabels); | ||
}; | ||
|
||
|
||
} //namespace structured_tree | ||
} // namespace mlpack | ||
#include "feature_extraction_impl.hpp" | ||
#endif | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update 👍
In c++, when you declare an object, it will call the default constructor, so you can just write(Maybe you already know this)
FeatureParameters params;
In theory, initialize the object by using constructor is better than using copy assignment, but compiler should be able to optimize it, so it is just a preference of taste now(I guess)