CMSIS-NN: Added arm_softmax_with_batch_q7

Some study of the error rate of softmax compared to f32 reference.
pull/19/head
Christophe Favergeon 6 years ago
parent 8a8bf1ebb3
commit 12e07e1683

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -5,6 +5,31 @@
#include <cstdio>
/*
Tests have shown that, compared to a float32 implementation
there is an average error of 4.2 percent and standard deviation
of 0.89.
Which means that with 100 batches, 4 batches will give the wrong position
for the max.
But it depends highly of the vector dimension.
Regressions are giving:
Average error rate = -0.555548 + 0.246918 vecDim
Variance = -0.0112281 + 0.0382476 vecDim
So for vecDim = 21 we have
Average error rate = 4.6 percent
Variance for error rate = 0.8
This data is used to define the threshold for tests
*/
#define THRESHOLD 7.5
int16_t findMaxIndex(q7_t *vec_in, int length)
{
int16_t currentIndex=0;
@ -61,9 +86,30 @@ int16_t differences(int16_t *pa,int16_t *pb, int length)
}
int diff = differences(ref.ptr(),output.ptr(),this->nbSamples);
//printf("diffs = %d\n",diff);
// 6% of errors are accepted for 20 entry samples
ASSERT_TRUE(100.0*diff/this->nbSamples <= 6.5);
ASSERT_TRUE(100.0*diff/this->nbSamples <= THRESHOLD);
}
void Softmax::test_softmax_with_batch_q7()
{
const q7_t *vec_in = input.ptr();
q7_t *pTmp = temp.ptr();
int16_t *pOut = output.ptr();
int16_t maxIndex;
arm_softmax_with_batch_q7(vec_in, this->nbSamples,this->vecDim, pTmp );
for(int i=0; i <this->nbSamples;i++)
{
maxIndex=findMaxIndex(pTmp,this->vecDim);
*pOut++ = maxIndex;
pTmp += this->vecDim;
}
int diff = differences(ref.ptr(),output.ptr(),this->nbSamples);
ASSERT_TRUE(100.0*diff/this->nbSamples <= THRESHOLD);
}
@ -74,6 +120,7 @@ int16_t differences(int16_t *pa,int16_t *pb, int length)
switch(id)
{
case Softmax::TEST_SOFTMAX_Q7_1:
{
ref.reload(Softmax::REF1_S16_ID,mgr);
dims.reload(Softmax::DIMS1_S16_ID,mgr);
input.reload(Softmax::INPUT1_Q7_ID,mgr);
@ -82,6 +129,20 @@ int16_t differences(int16_t *pa,int16_t *pb, int length)
this->nbSamples = pDims[0];
this->vecDim = pDims[1];
}
break;
case Softmax::TEST_SOFTMAX_WITH_BATCH_Q7_2:
{
ref.reload(Softmax::REF1_S16_ID,mgr);
dims.reload(Softmax::DIMS1_S16_ID,mgr);
input.reload(Softmax::INPUT1_Q7_ID,mgr);
const int16_t *pDims=dims.ptr();
this->nbSamples = pDims[0];
this->vecDim = pDims[1];
}
break;
}

@ -656,6 +656,7 @@ group Root {
Functions {
arm_softmax_q7 Test 1:test_softmax_q7
arm_softmax_with_batch_q7 Test 2:test_softmax_with_batch_q7
}
}
}

Loading…
Cancel
Save