Skip to content
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

Closed
wants to merge 14 commits into from
5 changes: 3 additions & 2 deletions src/mlpack/core/arma_extend/fn_index_min_max.hpp
@@ -1,4 +1,5 @@
#if (ARMA_VERSION_MAJOR < 7 && ARMA_VERSION_MINOR < 200)
#if (ARMA_VERSION_MAJOR < 7\
|| (ARMA_VERSION_MAJOR == 7 && ARMA_VERSION_MINOR < 200))
template<typename T1>
inline
typename arma_not_cx<typename T1::elem_type>::result
Expand Down Expand Up @@ -319,4 +320,4 @@ Base<elem_type,derived>::index_max() const

return index;
}
#endif
#endif
2 changes: 1 addition & 1 deletion src/mlpack/methods/CMakeLists.txt
Expand Up @@ -24,7 +24,7 @@ set(DIRS
det
emst
edge_boxes
fastmks
# fastmks
gmm
hmm
hoeffding_trees
Expand Down
4 changes: 3 additions & 1 deletion src/mlpack/methods/edge_boxes/edge_boxes_main.cpp
Expand Up @@ -11,8 +11,9 @@ using namespace mlpack;
using namespace mlpack::structured_tree;
using namespace std;

int main()
int main(int argc, char** argv)
{
CLI::ParseCommandLine(argc, argv);
/*
:param options:
num_images: number of images in the dataset.
Expand Down Expand Up @@ -79,3 +80,4 @@ int main()
}



63 changes: 60 additions & 3 deletions src/mlpack/methods/edge_boxes/feature_extraction_impl.hpp
Expand Up @@ -24,8 +24,53 @@ StructuredForests(FeatureParameters F)
params = F;
}

/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do not need the codes again, I think we can remove it, git will record the codes we removed before, when we need them again, we can use git to check it out

template<typename MatType, typename CubeType>
MatType StructuredForests<MatType, CubeType>::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can remove useless codes, let git help us memorize the codes we written

LoadData(MatType const &Images, MatType const &boundaries,\
MatType const &segmentations)
{
const size_t num_Images = this->params.num_Images;
const size_t rowSize = this->params.RowSize();
const size_t colSize = this->params.ColSize();
MatType input_data(num_Images * rowSize * 5, colSize);
// we store the input data as follows:
// Images (3), boundaries (1), segmentations (1).
size_t loop_iter = num_Images * 5;
size_t row_idx = 0;
size_t col_i = 0, col_s = 0, col_b = 0;
for(size_t i = 0; i < loop_iter; ++i)
{
if (i % 5 == 4)
{
input_data.submat(row_idx, 0, row_idx + rowSize - 1,\
colSize - 1) = MatType(segmentations.colptr(col_s),\
colSize, rowSize).t();
++col_s;
}
else if (i % 5 == 3)
{
input_data.submat(row_idx, 0, row_idx + rowSize - 1,\
colSize - 1) = MatType(boundaries.colptr(col_b),\
colSize, rowSize).t();
++col_b;
}
else
{
input_data.submat(row_idx, 0, row_idx + rowSize - 1,\
colSize - 1) = MatType(Images.colptr(col_i),
colSize, rowSize).t();
++col_i;
}
row_idx += rowSize;
}
return input_data;
}

*/

/**
* Get Dimensions of Features
* Get DImensions of Features
* @param FtrDim Output vector that contains the result
*/
template<typename MatType, typename CubeType>
Expand Down Expand Up @@ -804,7 +849,7 @@ PrepareData(const MatType& Images, const MatType& Boundaries,\
const size_t nFtrDim = FtrDim(0) + FtrDim(1);
const size_t nSmpFtrDim = (size_t)(nFtrDim * fraction);


size_t time=0;
for(size_t i = 0; i < numTree; ++i)
{
//Implement the logic for if data already exists.
Expand Down Expand Up @@ -892,7 +937,11 @@ PrepareData(const MatType& Images, const MatType& Boundaries,\
}

CubeType SSFtr, RegFtr;
Timer::Start("get_features");

this->GetFeatures(Img, loc, RegFtr, SSFtr, table);
Timer::Stop("get_features");

//randomly sample 70 values each from reg_ftr and ss_ftr.
/*
CubeType ftr(140, 1000, 13);
Expand All @@ -907,7 +956,7 @@ PrepareData(const MatType& Images, const MatType& Boundaries,\
// have to do this or we can overload the CopyMakeBorder to support MatType.
s.slice(0) = segs;
CubeType in_segs;
this->CopyMakeBorder(s, gRad, gRad, gRad,
this->CopyMakeBorder(s, gRad, gRad, gRad,\
gRad, in_segs);

for(size_t i = 0; i < loc.n_rows; ++i)
Expand Down Expand Up @@ -935,6 +984,7 @@ Discretize(const MatType& labels, const size_t nClass,\
// lbls : 20000 * 256.
// nSample: number of samples for clustering structured labels 256
// nClass: number of classes (clusters) for binary splits. 2
Timer::Start("other_discretize");

arma::uvec lis1(nSample);
for (size_t i = 0; i < lis1.n_elem; ++i)
Expand Down Expand Up @@ -967,14 +1017,21 @@ Discretize(const MatType& labels, const size_t nClass,\
// so most representative label is: labels.row(ind).

// apply pca
Timer::Stop("other_discretize");
Timer::Start("pca_timer");
MatType coeff, transformedData;
arma::vec eigVal;
mlpack::pca::PCA p;
p.Apply(zs.t(), transformedData, eigVal, coeff);
// we take only first row in transformedData (256 * 20000) as dim = 1.
Timer::Stop("pca_timer");
Timer::Start("other_discretize");
//std::cout << Timer::Get("pca_timer") << std::endl;
DiscreteLabels = arma::conv_to<arma::vec>::from(transformedData.row(0).t() > 0);
Timer::Stop("other_discretize");
}
return ind;

}
} // namespace structured_tree
} // namespace mlpack
Expand Down
4 changes: 2 additions & 2 deletions src/mlpack/tests/CMakeLists.txt
Expand Up @@ -18,7 +18,7 @@ add_executable(mlpack_test
distribution_test.cpp
emst_test.cpp
edge_boxes_test.cpp
fastmks_test.cpp
# fastmks_test.cpp
feedforward_network_test.cpp
gmm_test.cpp
hmm_test.cpp
Expand Down Expand Up @@ -64,7 +64,7 @@ add_executable(mlpack_test
sgd_test.cpp
serialization.hpp
serialization.cpp
serialization_test.cpp
# serialization_test.cpp
softmax_regression_test.cpp
sort_policy_test.cpp
sparse_autoencoder_test.cpp
Expand Down