23 mEvaluator(pEvaluator), mFullyMeshedTopology(pFullyMeshedTopology), mTypes(pObjectTypes),
30 throw std::runtime_error(
"Please specifiy parameter valid_test_set_db_filename when starting this node.");
33 throw std::runtime_error(
"Please specifiy parameter invalid_test_set_db_filename when starting this node.");
36 throw std::runtime_error(
"Please specifiy parameter write_valid_test_sets_filename when starting this node.");
39 throw std::runtime_error(
"Please specifiy parameter write_invalid_test_sets_filename when starting this node.");
43 throw std::runtime_error(
"Please specify parameter object_missing_in_test_set_probability when starting this node.");
51 mSceneId = pExamplesList[0]->mIdentifier;
56 std::vector<boost::shared_ptr<TestSet>> randomTestSets =
generateRandomSets(pExamplesList, pTestSetCount);
91 throw std::runtime_error(
"In TestSetGenerator::validateSets(): Error when evaluating fully meshed topology: has false positives, should have none");
94 throw std::runtime_error(
"In TestSetGenerator::validateSets(): Error when evaluating fully meshed topology: found invalid test sets when those should not have been initialized yet.");
96 double maxProbability = 0;
97 double minProbability = 2;
98 unsigned int zeroSets = 0;
101 double probability = testSet->getFullyMeshedProbability();
102 if (probability > maxProbability) maxProbability = probability;
103 if (probability == 0) zeroSets++;
104 else if (probability < minProbability) minProbability = probability;
107 std::vector<boost::shared_ptr<TestSet>> validTestSets;
108 std::vector<boost::shared_ptr<TestSet>> invalidTestSets;
110 for (
unsigned int i = 0; i < pTestSets.size(); i++)
113 validTestSets.push_back(pTestSets[i]);
114 else invalidTestSets.push_back(pTestSets[i]);
118 mPrintHelper.
addLine(
"Maximum probability: " + boost::lexical_cast<std::string>(maxProbability));
119 if (minProbability == 2)
120 minProbability = std::numeric_limits<double>::quiet_NaN();
121 mPrintHelper.
addLine(
"Minimum probability greater than zero: " + boost::lexical_cast<std::string>(minProbability));
122 mPrintHelper.
addLine(
"Recognition threshold: " + boost::lexical_cast<std::string>(recognitionThreshold));
123 mPrintHelper.
addLine(
"Found " + boost::lexical_cast<std::string>(validTestSets.size()) +
" valid and " + boost::lexical_cast<std::string>(invalidTestSets.size()) +
" invalid test sets.");
124 mPrintHelper.
addLine(boost::lexical_cast<std::string>(zeroSets) +
" test sets have probability 0.");
127 mEvaluator->setRecognitionThreshold(recognitionThreshold);
135 ISM::PosePtr newPose;
136 pObject->pose->convertPoseIntoFrame(pReference->pose, newPose);
137 pObject->pose = newPose;
146 std::vector<boost::shared_ptr<TestSet>>
testSets;
148 ISM::TableHelperPtr localTableHelper(
new ISM::TableHelper(pFilename));
149 std::vector<std::string> patternNames = localTableHelper->getRecordedPatternNames();
150 if (
std::find(patternNames.begin(), patternNames.end(),
mSceneId) == patternNames.end())
151 ROS_INFO_STREAM(
"In TestSetGenerator::loadTestSetsFromFile(" << pFilename +
"): scene id " <<
mSceneId <<
" is not a valid pattern in the database.");
153 std::vector<ISM::ObjectSetPtr> loadedTestSets;
154 loadedTestSets = localTableHelper->getRecordedPattern(
mSceneId)->objectSets;
156 for (ISM::ObjectSetPtr loadedTestSet: loadedTestSets)
159 for (ISM::ObjectPtr
object: loadedTestSet->objects)
160 testSet->mObjectSet->insert(
object);
161 testSets.push_back(testSet);
168 catch (soci::soci_error& e)
170 throw std::runtime_error(
"In TestSetGenerator::loadTestSetsFromFile(): soci error while trying to write to database file.\nProbably the file path does not exist.");
177 if (!pTestSets.empty())
181 ISM::TableHelperPtr localTableHelper(
new ISM::TableHelper(pFilename));
182 localTableHelper->createTablesIfNecessary();
183 localTableHelper->insertRecordedPattern(
mSceneId);
185 localTableHelper->insertRecordedObjectSet(testSet->mObjectSet,
mSceneId);
187 catch (soci::soci_error& e)
189 throw std::runtime_error(
"In TestSetGenerator::writeTestSetsToFile(): soci error while trying to write to database file " + pFilename
190 +
"\nProbably the file path does not exist.");
199 return pCompleteTestSets;
201 ROS_INFO_STREAM(
"Simulating occlusion by removing random object observations from test sets.");
203 unsigned int removed = 0;
205 std::random_device rd;
208 boost::uniform_int<> dist(0,RAND_MAX);
209 boost::variate_generator<boost::mt19937,boost::uniform_int<>> gen(eng,dist);
211 if (mObjectMissingInTestSetProbability < 0 || mObjectMissingInTestSetProbability > 1)
212 throw std::runtime_error(
"parameter object_missing_in_test_set_probability should be in interval [0,1].");
221 while (i < testSet->mObjectSet->objects.size())
229 testSet->mObjectSet->objects.erase(testSet->mObjectSet->objects.begin() + i);
235 return pCompleteTestSets;
std::string mInvalidTestSetDbFilename
std::vector< boost::shared_ptr< TestSet > > mValidTestSets
std::vector< boost::shared_ptr< TestSet > > simulateOcclusion(std::vector< boost::shared_ptr< TestSet >> pCompleteTestSets)
std::string mWriteInvalidTestSetsFilename
boost::shared_ptr< SceneModel::Topology > mFullyMeshedTopology
bool find(const std::vector< double > &in, double toFind)
void setPoseOfObjectRelativeToReference(ISM::ObjectPtr pObject, ISM::ObjectPtr pReference)
void generateTestSets(std::vector< boost::shared_ptr< ISM::ObjectSet >> pExamplesList, unsigned int pTestSetCount)
void addLine(const std::string &pLine)
std::string mWriteValidTestSetsFilename
void validateSets(std::vector< boost::shared_ptr< TestSet >> pTestSets)
std::string mValidTestSetDbFilename
TestSetGenerator(boost::shared_ptr< AbstractTopologyEvaluator > pEvaluator, boost::shared_ptr< SceneModel::Topology > pFullyMeshedTopology, const std::vector< std::string > &pObjectTypes)
void writeTestSetsToFile(const std::string &pFilename, const std::vector< boost::shared_ptr< TestSet >> &pTestSets)
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
boost::shared_ptr< AbstractTopologyEvaluator > mEvaluator
std::vector< boost::shared_ptr< TestSet > > loadTestSetsFromFile(const std::string &pFilename)
std::vector< boost::shared_ptr< TestSet > > mInvalidTestSets
virtual std::vector< boost::shared_ptr< TestSet > > generateRandomSets(std::vector< boost::shared_ptr< ISM::ObjectSet >> pExamplesList, unsigned int pTestSetCount)=0
double mObjectMissingInTestSetProbability