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

formatted RSKNN and RSClassifier, added multithreading to KNNAnnotator and RFAnnotator #13

Open
wants to merge 2 commits into
base: noetic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 70 additions & 68 deletions src/KnnAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,100 +26,102 @@ class KnnAnnotator : public DrawingAnnotator
{
private:

cv::Mat color;
cv::Mat color;

//set_mode should be GT(groundTruth) or CL (classify)....
std::string mode;
//set_mode should be GT(groundTruth) or CL (classify)....
std::string mode;

//the value of k-neighbors in the knn-classifier
int default_k;
//the value of k-neighbors in the knn-classifier
int default_k;

//feature_use should be VFH, CVFH, CNN, VGG16 .....
std::string feature_use;
//feature_use should be VFH, CVFH, CNN, VGG16 .....
std::string feature_use;

//the name of train matrix and its labels in path rs_resources/objects_dataset/extractedFeat/
std::string trainKNN_matrix;
std::string trainKNNLabel_matrix;
//the name of train matrix and its labels in path rs_resources/objects_dataset/extractedFeat/
std::string trainKNN_matrix;
std::string trainKNNLabel_matrix;

//vector to hold split trained_model_name
std::vector<std::string> split_model;
//vector to hold split trained_model_name
std::vector<std::string> split_model;

//the name of actual_class_label map file in path rs_resources/objects_dataset/extractedFeat/
std::string classNrMapping;
//the name of actual_class_label map file in path rs_resources/objects_dataset/extractedFeat/
std::string classNrMapping;

//vector to hold classes name
std::vector<std::string> model_labels;
//vector to hold classes name
std::vector<std::string> model_labels;

RSKNN *knnObject;
RSKNN *knnObject;

public:

KnnAnnotator(): DrawingAnnotator(__func__)
{}
KnnAnnotator(): DrawingAnnotator(__func__)
{}



TyErrorId initialize(AnnotatorContext &ctx)
{
ctx.extractValue("set_mode", mode);
outInfo("set_mode:" << mode << std::endl);
TyErrorId initialize(AnnotatorContext &ctx)
{
ctx.extractValue("set_mode", mode);
outInfo("set_mode:" << mode << std::endl);

ctx.extractValue("default_k", default_k);
outInfo("Value of k-neighbors: " << default_k);
ctx.extractValue("default_k", default_k);
outInfo("Value of k-neighbors: " << default_k);

ctx.extractValue("training_data", trainKNN_matrix);
outInfo("training_data:" << trainKNN_matrix);
ctx.extractValue("training_data", trainKNN_matrix);
outInfo("training_data:" << trainKNN_matrix);

ctx.extractValue("class_label_mapping", classNrMapping);
outInfo("class_label_mapping:" << classNrMapping );
ctx.extractValue("class_label_mapping", classNrMapping);
outInfo("class_label_mapping:" << classNrMapping );



ctx.extractValue("feature_descriptor_type", feature_use);
outInfo("feature descriptor set: "<<feature_use);
ctx.extractValue("feature_descriptor_type", feature_use);
outInfo("feature descriptor set: "<<feature_use);

knnObject = new RSKNN(default_k);
knnObject->loadModelFile(trainKNN_matrix);
knnObject->setLabels(classNrMapping, model_labels);
knnObject = new RSKNN(default_k);
knnObject->loadModelFile(trainKNN_matrix);
knnObject->setLabels(classNrMapping, model_labels);

return UIMA_ERR_NONE;
}

TyErrorId destroy()
{
outInfo("destroy");
return UIMA_ERR_NONE;
}

TyErrorId processWithLock(CAS &tcas, ResultSpecification const &res_spec)
{
outInfo("RSKNNAnnotator is running:");
rs::SceneCas cas(tcas);
rs::Scene scene = cas.getScene();
cas.get(VIEW_COLOR_IMAGE_HD, color);
std::vector<rs::ObjectHypothesis> clusters;
scene.identifiables.filter(clusters);
outInfo("Feature to use: "<<feature_use);
if(feature_use == "VFH" || feature_use == "CVFH") {
outInfo("Calculation starts with : " << mode << "::" << feature_use);
knnObject->processPCLFeatureKNN(mode, feature_use, clusters, color, model_labels, tcas);
}
else if(feature_use == "BVLC_REF" || feature_use == "VGG16") {
outInfo("Calculation starts with : " << mode << "::" << feature_use);
knnObject->processCaffeFeatureKNN(mode, feature_use, clusters, color, model_labels, tcas);
return UIMA_ERR_NONE;
}
else {
outError("Please sellect the correct value of parameter(feature_use): VFH, CVFH, BVLC_REF, VGG16");

TyErrorId destroy()
{
outInfo("destroy");
return UIMA_ERR_NONE;
}

outInfo("calculation is done with RSKNN" << std::endl);
return UIMA_ERR_NONE;
}
TyErrorId processWithLock(CAS &tcas, ResultSpecification const &res_spec)
{
rs::StopWatch clock;
outInfo("RSKNNAnnotator is running:");
rs::SceneCas cas(tcas);
rs::Scene scene = cas.getScene();
cas.get(VIEW_COLOR_IMAGE_HD, color);
std::vector<rs::ObjectHypothesis> clusters;
scene.identifiables.filter(clusters);
outInfo("Feature to use: "<<feature_use);
if(feature_use == "VFH" || feature_use == "CVFH") {
outInfo("Calculation starts with : " << mode << "::" << feature_use);
knnObject->processPCLFeatureKNN(mode, feature_use, clusters, color, model_labels, tcas);
}
else if(feature_use == "BVLC_REF" || feature_use == "VGG16") {
outInfo("Calculation starts with : " << mode << "::" << feature_use);
knnObject->processCaffeFeatureKNN(mode, feature_use, clusters, color, model_labels, tcas);
}
else {
outError("Please sellect the correct value of parameter(feature_use): VFH, CVFH, BVLC_REF, VGG16");
}

outInfo("calculation is done with RSKNN" << std::endl);
outInfo("took: " << clock.getTime() << " ms. with the Cluster size of : " << clusters.size());
return UIMA_ERR_NONE;
}

void drawImageWithLock(cv::Mat &disp)
{
disp = color.clone();
}
void drawImageWithLock(cv::Mat &disp)
{
disp = color.clone();
}

};

Expand Down
139 changes: 70 additions & 69 deletions src/RfAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,102 +25,103 @@ class RfAnnotator : public DrawingAnnotator
{
private:

cv::Mat color;
cv::Mat color;

//set_mode should be GT(groundTruth) or CF (classify) ...........
std::string set_mode;
//set_mode should be GT(groundTruth) or CF (classify) ...........
std::string set_mode;

//dataset_use should be IAI (kitchen data from IAI) or WU (data from Washington University) or both...
std::string dataset_use;
//dataset_use should be IAI (kitchen data from IAI) or WU (data from Washington University) or both...
std::string dataset_use;

//feature_use should be VFH, CVFH, CNN, VGG16 .....
std::string feature_use;
//feature_use should be VFH, CVFH, CNN, VGG16 .....
std::string feature_use;

//the name of trained model ifle in folder rs_addons/trainedData/
std::string trained_model_name;
//the name of trained model ifle in folder rs_addons/trainedData/
std::string trained_model_name;

//vector to hold split trained_model_name
std::vector<std::string> split_model;
//vector to hold split trained_model_name
std::vector<std::string> split_model;

//the name of actual_class_label map file in path rs_resources/objects_dataset/extractedFeat/
std::string actual_class_label;
//the name of actual_class_label map file in path rs_resources/objects_dataset/extractedFeat/
std::string actual_class_label;

//vector to hold classes name
std::vector<std::string> model_labels;
//vector to hold classes name
std::vector<std::string> model_labels;

public:

RfAnnotator(): DrawingAnnotator(__func__)
{}
RfAnnotator(): DrawingAnnotator(__func__)
{}

RSClassifier* rfObject= new RSRF;
RSClassifier* rfObject= new RSRF;

TyErrorId initialize(AnnotatorContext &ctx)
{
outInfo("initialize");
ctx.extractValue("set_mode", set_mode);
ctx.extractValue("trained_model_name", trained_model_name);
ctx.extractValue("actual_class_label", actual_class_label);

outInfo("Name of the loaded files for RF are:"<<std::endl);

outInfo("set_mode:"<<set_mode<<std::endl);
outInfo("trained_model_name:"<<trained_model_name<<std::endl);
outInfo("actual_class_label:"<<actual_class_label<<std::endl);

rfObject->setLabels(actual_class_label, model_labels);
TyErrorId initialize(AnnotatorContext &ctx)
{
outInfo("initialize");
ctx.extractValue("set_mode", set_mode);
ctx.extractValue("trained_model_name", trained_model_name);
ctx.extractValue("actual_class_label", actual_class_label);

boost::split(split_model, trained_model_name, boost::is_any_of("_"));
outInfo("Name of the loaded files for RF are:"<<std::endl);

dataset_use= split_model[0];
outInfo("dataset_use:"<<dataset_use<<std::endl);
outInfo("set_mode:"<<set_mode<<std::endl);
outInfo("trained_model_name:"<<trained_model_name<<std::endl);
outInfo("actual_class_label:"<<actual_class_label<<std::endl);

feature_use= split_model[1];
outInfo("feature_use:"<<feature_use<<std::endl);
rfObject->setLabels(actual_class_label, model_labels);

return UIMA_ERR_NONE;
}
boost::split(split_model, trained_model_name, boost::is_any_of("_"));

TyErrorId destroy()
{
outInfo("destroy");
return UIMA_ERR_NONE;
}
dataset_use= split_model[0];
outInfo("dataset_use:"<<dataset_use<<std::endl);

TyErrorId processWithLock(CAS &tcas, ResultSpecification const &res_spec)
{
outInfo("RSRFAnnotator is running:");
rs::SceneCas cas(tcas);
rs::Scene scene = cas.getScene();
cas.get(VIEW_COLOR_IMAGE_HD, color);
std::vector<rs::ObjectHypothesis> clusters;
scene.identifiables.filter(clusters);
feature_use= split_model[1];
outInfo("feature_use:"<<feature_use<<std::endl);

return UIMA_ERR_NONE;
}

if(feature_use == "VFH" || feature_use == "CVFH")
TyErrorId destroy()
{
outInfo("Calculation starts with : " << set_mode << "::" << dataset_use << "::" << feature_use);
rfObject->processPCLFeature(trained_model_name,set_mode,feature_use,clusters, rfObject, color,model_labels, tcas);
outInfo("destroy");
return UIMA_ERR_NONE;
}
else if(feature_use == "CNN" || feature_use == "VGG16")

TyErrorId processWithLock(CAS &tcas, ResultSpecification const &res_spec)
{
outInfo("Calculation starts with : " << set_mode << "::" << dataset_use << "::" << feature_use);
rfObject->processCaffeFeature(trained_model_name,set_mode,feature_use,clusters, rfObject, color, model_labels, tcas);
rs::StopWatch clock;
outInfo("RSRFAnnotator is running:");
rs::SceneCas cas(tcas);
rs::Scene scene = cas.getScene();
cas.get(VIEW_COLOR_IMAGE_HD, color);
std::vector<rs::ObjectHypothesis> clusters;
scene.identifiables.filter(clusters);

if(feature_use == "VFH" || feature_use == "CVFH")
{
outInfo("Calculation starts with : " << set_mode << "::" << dataset_use << "::" << feature_use);
rfObject->processPCLFeature(trained_model_name,set_mode,feature_use,clusters, rfObject, color,model_labels, tcas);
}
else if(feature_use == "CNN" || feature_use == "VGG16")
{
outInfo("Calculation starts with : " << set_mode << "::" << dataset_use << "::" << feature_use);
rfObject->processCaffeFeature(trained_model_name,set_mode,feature_use,clusters, rfObject, color, model_labels, tcas);
}
else
{
outError("Please sellect the correct value of parameter(feature_use): VFH, CVFH, CNN, VGG16");
}

outInfo("calculation is done with RSRF"<<std::endl);
outInfo("took: " << clock.getTime() << " ms. with the Cluster size of : " << clusters.size());
return UIMA_ERR_NONE;
}
else

void drawImageWithLock(cv::Mat &disp)
{
outError("Please sellect the correct value of parameter(feature_use): VFH, CVFH, CNN, VGG16");
disp = color.clone();
}

outInfo("calculation is done with RSRF"<<std::endl);
return UIMA_ERR_NONE;
}

void drawImageWithLock(cv::Mat &disp)
{
disp = color.clone();
}

};

// This macro exports an entry point that is used to create the annotator.
Expand Down
Loading