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

Add counters reference-getters for PrecisionRecallLayer #594

Merged
merged 2 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions NeoML/include/NeoML/Dnn/Layers/PrecisionRecallLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class NEOML_API CPrecisionRecallLayer : public CQualityControlLayer {
void OnReset() override;
void RunOnceAfterReset() override;

virtual int& PositivesTotal(){ return positivesTotal; };
virtual int& NegativesTotal(){ return negativesTotal; };
virtual int& PositivesCorrect(){ return positivesCorrect; };
virtual int& NegativesCorrect(){ return negativesCorrect; };

private:
int positivesTotal;
int negativesTotal;
Expand Down
40 changes: 20 additions & 20 deletions NeoML/src/Dnn/Layers/PrecisionRecallLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ void CPrecisionRecallLayer::Reshape()
void CPrecisionRecallLayer::GetLastResult( CArray<int>& results )
{
results.FreeBuffer();
results.Add( positivesCorrect );
results.Add( positivesTotal );
results.Add( negativesCorrect );
results.Add( negativesTotal );
results.Add( PositivesCorrect() );
results.Add( PositivesTotal() );
results.Add( NegativesCorrect() );
results.Add( NegativesTotal() );
}

void CPrecisionRecallLayer::OnReset()
{
positivesCorrect = 0;
positivesTotal = 0;
negativesCorrect = 0;
negativesTotal = 0;
PositivesCorrect() = 0;
PositivesTotal() = 0;
NegativesCorrect() = 0;
NegativesTotal() = 0;
}

void CPrecisionRecallLayer::RunOnceAfterReset()
Expand Down Expand Up @@ -123,21 +123,21 @@ void CPrecisionRecallLayer::RunOnceAfterReset()
MathEngine().VectorAbs( binarizedLabel, binarizedLabel, vectorSize );
MathEngine().VectorSum( binarizedLabel, vectorSize, negativesCount );

positivesTotal += to<int>( positivesCount.GetValue() );
negativesTotal += to<int>( negativesCount.GetValue() );
positivesCorrect += to<int>( truePositivesCount.GetValue() );
negativesCorrect += to<int>( trueNegativeCount.GetValue() );
PositivesTotal() += to<int>( positivesCount.GetValue() );
NegativesTotal() += to<int>( negativesCount.GetValue() );
PositivesCorrect() += to<int>( truePositivesCount.GetValue() );
NegativesCorrect() += to<int>( trueNegativeCount.GetValue() );

NeoAssert( positivesTotal >= 0 );
NeoAssert( negativesTotal >= 0 );
NeoAssert( positivesCorrect <= positivesTotal );
NeoAssert( negativesCorrect <= negativesTotal );
NeoAssert( PositivesTotal() >= 0 );
NeoAssert( NegativesTotal() >= 0 );
NeoAssert( PositivesCorrect() <= PositivesTotal() );
NeoAssert( NegativesCorrect() <= NegativesTotal() );

CFastArray<float, 1> buffer;
buffer.Add( static_cast<float>( positivesCorrect ) );
buffer.Add( static_cast<float>( positivesTotal ) );
buffer.Add( static_cast<float>( negativesCorrect ) );
buffer.Add( static_cast<float>( negativesTotal ) );
buffer.Add( static_cast<float>( PositivesCorrect() ) );
buffer.Add( static_cast<float>( PositivesTotal() ) );
buffer.Add( static_cast<float>( NegativesCorrect() ) );
buffer.Add( static_cast<float>( NegativesTotal() ) );

outputBlobs[0]->CopyFrom( buffer.GetPtr() );
}
Expand Down