diff --git a/plugins/processing/classification/src/box-algorithms/ovpCBoxAlgorithmClassifierProcessor.cpp b/plugins/processing/classification/src/box-algorithms/ovpCBoxAlgorithmClassifierProcessor.cpp index d447ceb1fae09981f39231ea014297bb567e6c03..b03ed8b89f3131a63683cc628d533ff52e4cb91e 100644 --- a/plugins/processing/classification/src/box-algorithms/ovpCBoxAlgorithmClassifierProcessor.cpp +++ b/plugins/processing/classification/src/box-algorithms/ovpCBoxAlgorithmClassifierProcessor.cpp @@ -31,6 +31,8 @@ boolean CBoxAlgorithmClassifierProcessor::loadClassifier(const char* sFilename) return false; } + m_vStimulation.clear(); + //Now check the version, and let's display a message if the version is not good string l_sVersion; if(l_pRootNode->hasAttribute(c_sXmlVersionAttributeName)) @@ -185,8 +187,8 @@ boolean CBoxAlgorithmClassifierProcessor::uninitialize(void) m_pClassifier = NULL; } - m_oHyperplaneValuesEncoder.uninitialize(); m_oProbabilityValuesEncoder.uninitialize(); + m_oHyperplaneValuesEncoder.uninitialize(); m_oLabelsEncoder.uninitialize(); m_oStimulationDecoder.uninitialize(); @@ -206,6 +208,39 @@ boolean CBoxAlgorithmClassifierProcessor::process(void) { IBoxIO& l_rDynamicBoxContext=this->getDynamicBoxContext(); + // Check if we have a command first + for(uint32 i=0; i<l_rDynamicBoxContext.getInputChunkCount(1); i++) + { + m_oStimulationDecoder.decode(i); + if(m_oStimulationDecoder.isHeaderReceived()) + { + } + if(m_oStimulationDecoder.isBufferReceived()) + { + for(uint64 i=0;i<m_oStimulationDecoder.getOutputStimulationSet()->getStimulationCount();i++) + { + if(m_oStimulationDecoder.getOutputStimulationSet()->getStimulationIdentifier(i) == OVTK_StimulationId_TrainCompleted) + { + IBox& l_rStaticBoxContext=this->getStaticBoxContext(); + + CString l_sConfigurationFilename; + l_rStaticBoxContext.getSettingValue(0, l_sConfigurationFilename); + + this->getLogManager() << LogLevel_Trace << "Reloading classifier\n"; + if(!loadClassifier(l_sConfigurationFilename.toASCIIString())) + { + this->getLogManager() << LogLevel_Error << "Error reloading classifier\n"; + return false; + } + } + } + } + if(m_oStimulationDecoder.isEndReceived()) + { + } + } + + // Classify data for(uint32 i=0; i<l_rDynamicBoxContext.getInputChunkCount(0); i++) { const uint64 l_ui64StartTime=l_rDynamicBoxContext.getInputChunkStartTime(0, i); @@ -246,6 +281,7 @@ boolean CBoxAlgorithmClassifierProcessor::process(void) l_rDynamicBoxContext.markOutputAsReadyToSend(0, l_ui64StartTime, l_ui64EndTime); l_rDynamicBoxContext.markOutputAsReadyToSend(1, l_ui64StartTime, l_ui64EndTime); l_rDynamicBoxContext.markOutputAsReadyToSend(2, l_ui64StartTime, l_ui64EndTime); + } else { @@ -258,7 +294,7 @@ boolean CBoxAlgorithmClassifierProcessor::process(void) this->getLogManager() << LogLevel_Error << "Classification algorithm failed.\n"; return false; } - } + } if(m_oFeatureVectorDecoder.isEndReceived()) { @@ -271,42 +307,9 @@ boolean CBoxAlgorithmClassifierProcessor::process(void) l_rDynamicBoxContext.markOutputAsReadyToSend(2, l_ui64StartTime, l_ui64EndTime); } - l_rDynamicBoxContext.markInputAsDeprecated(0, i); } - // Check if we have a command - for(uint32 i=0; i<l_rDynamicBoxContext.getInputChunkCount(1); i++) - { - m_oStimulationDecoder.decode(i); - if(m_oStimulationDecoder.isHeaderReceived()) - { - } - if(m_oStimulationDecoder.isBufferReceived()) - { - for(uint64 i=0;i<m_oStimulationDecoder.getOutputStimulationSet()->getStimulationCount();i++) - { - if(m_oStimulationDecoder.getOutputStimulationSet()->getStimulationIdentifier(i) == OVTK_StimulationId_TrainCompleted) - { - IBox& l_rStaticBoxContext=this->getStaticBoxContext(); - - CString l_sConfigurationFilename; - l_rStaticBoxContext.getSettingValue(0, l_sConfigurationFilename); - - this->getLogManager() << LogLevel_Trace << "Reloading classifier\n"; - if(!loadClassifier(l_sConfigurationFilename.toASCIIString())) - { - this->getLogManager() << LogLevel_Error << "Error reloading classifier\n"; - return false; - } - } - } - } - if(m_oStimulationDecoder.isEndReceived()) - { - - } - } return true; } diff --git a/toolkit/include/toolkit/algorithms/classification/ovtkCAlgorithmClassifier.h b/toolkit/include/toolkit/algorithms/classification/ovtkCAlgorithmClassifier.h index ef6b03b8a4f606fea9494dce647fbaffd4db013a..0556a27c72e4c1a480b4eb8e9f1205e2b1412c97 100644 --- a/toolkit/include/toolkit/algorithms/classification/ovtkCAlgorithmClassifier.h +++ b/toolkit/include/toolkit/algorithms/classification/ovtkCAlgorithmClassifier.h @@ -15,8 +15,8 @@ #define OVTK_Algorithm_Classifier_InputParameterId_FeatureVector OpenViBE::CIdentifier(0x6D69BF98, 0x1EB9EE66) // Single vector to classify #define OVTK_Algorithm_Classifier_InputParameterId_FeatureVectorSet OpenViBE::CIdentifier(0x27C05927, 0x5DE9103A) // Training set #define OVTK_Algorithm_Classifier_InputParameterId_Configuration OpenViBE::CIdentifier(0xA705428E, 0x5BB1CADD) // The model +#define OVTK_Algorithm_Classifier_InputParameterId_NumberOfClasses OpenViBE::CIdentifier(0x1B95825A, 0x24F2E949) #define OVTK_Algorithm_Classifier_InputParameterId_ExtraParameter OpenViBE::CIdentifier(0x42AD6BE3, 0xF483DE3F) // Params specific to classifier type -#define OVTK_Algorithm_Classifier_InputParameterId_NumberOfClasses OpenViBE::CIdentifier(0x1B95825A, 0x24F2E949) #define OVTK_Algorithm_Classifier_OutputParameterId_Class OpenViBE::CIdentifier(0x8A39A7EA, 0xF2EE45C4) #define OVTK_Algorithm_Classifier_OutputParameterId_ClassificationValues OpenViBE::CIdentifier(0xDA77D7E4, 0x766B48EA) @@ -89,8 +89,8 @@ namespace OpenViBEToolkit rAlgorithmPrototype.addInputParameter (OVTK_Algorithm_Classifier_InputParameterId_FeatureVector, "Feature vector", OpenViBE::Kernel::ParameterType_Matrix); rAlgorithmPrototype.addInputParameter (OVTK_Algorithm_Classifier_InputParameterId_FeatureVectorSet, "Feature vector set", OpenViBE::Kernel::ParameterType_Matrix); rAlgorithmPrototype.addInputParameter (OVTK_Algorithm_Classifier_InputParameterId_Configuration, "Configuration", OpenViBE::Kernel::ParameterType_Pointer); - rAlgorithmPrototype.addInputParameter (OVTK_Algorithm_Classifier_InputParameterId_ExtraParameter, "Extra parameter", OpenViBE::Kernel::ParameterType_Pointer); rAlgorithmPrototype.addInputParameter (OVTK_Algorithm_Classifier_InputParameterId_NumberOfClasses, "Number of classes", OpenViBE::Kernel::ParameterType_UInteger); + rAlgorithmPrototype.addInputParameter (OVTK_Algorithm_Classifier_InputParameterId_ExtraParameter, "Extra parameter", OpenViBE::Kernel::ParameterType_Pointer); rAlgorithmPrototype.addOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_Class, "Class", OpenViBE::Kernel::ParameterType_Float); rAlgorithmPrototype.addOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_ClassificationValues, "Hyperplane distance", OpenViBE::Kernel::ParameterType_Matrix);