Skip to content

Commit

Permalink
Add counters reference-getters for PrecisionRecallLayer (#594)
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Zimka <boris.zimka@abbyy.com>

Co-authored-by: Boris Zimka <boris.zimka@abbyy.com>
Co-authored-by: Valeriy Fedyunin <valery.fedyunin@abbyy.com>
  • Loading branch information
3 people committed Mar 31, 2022
1 parent 071aa1b commit 658e059
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
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

0 comments on commit 658e059

Please sign in to comment.