Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui committed Feb 20, 2025
1 parent a6b2eef commit de69646
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions docs/developer-guide/param-and-model-file-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ the meaning of existing param key index can be looked up at [operation-param-wei
* integer array value : [array size],int,int,...,int
* float array value : [array size],float,float,...,float

In modern ncnn param file

* array could be represented as `3=2.0,3.0` that is much more human friendly
* string typed value: `4=hello` and the string is no longer than 255

## net.bin
```
+---------+---------+---------+---------+---------+---------+
Expand Down
21 changes: 11 additions & 10 deletions tests/test_paramdict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static int test_paramdict_0()
static int test_paramdict_1()
{
ParamDictTest pdt;
pdt.load_param("0=-1 1=4, 2=0.01 3=-1.45e-2,");
pdt.load_param("0=-1 1=4, 2=0.01 3=-1.45e-2,3.14");

// int
int typei = pdt.type(0);
Expand Down Expand Up @@ -173,14 +173,14 @@ static int test_paramdict_1()
return -1;
}
ncnn::Mat af = pdt.get(3, ncnn::Mat());
if (af.w != 1)
if (af.w != 2)
{
fprintf(stderr, "test_paramdict float array size failed %d != 1\n", af.w);
fprintf(stderr, "test_paramdict float array size failed %d != 2\n", af.w);
return -1;
}
if (af[0] != -0.0145f)
if (af[0] != -0.0145f || af[1] != 3.14f)
{
fprintf(stderr, "test_paramdict float array value failed %f\n", af[0]);
fprintf(stderr, "test_paramdict float array value failed %f %f\n", af[0], af[1]);
return -1;
}

Expand Down Expand Up @@ -346,8 +346,9 @@ static int test_paramdict_4()
0x02, 0x00, 0x00, 0x00,
0x0a, 0xd7, 0x23, 0x3c,
0xf9, 0xa4, 0xff, 0xff,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x68, 0x91, 0x6d, 0xbc,
0xc3, 0xf5, 0x48, 0x40,
0x17, 0xff, 0xff, 0xff
};

Expand Down Expand Up @@ -410,14 +411,14 @@ static int test_paramdict_4()
return -1;
}
ncnn::Mat af = pdt.get(3, ncnn::Mat());
if (af.w != 1)
if (af.w != 2)
{
fprintf(stderr, "test_paramdict float array size failed %d != 1\n", af.w);
fprintf(stderr, "test_paramdict float array size failed %d != 2\n", af.w);
return -1;
}
if (af[0] != -0.0145f)
if (af[0] != -0.0145f || af[1] != 3.14f)
{
fprintf(stderr, "test_paramdict float array value failed %f\n", af[0]);
fprintf(stderr, "test_paramdict float array value failed %f %f\n", af[0], af[1]);
return -1;
}

Expand Down

0 comments on commit de69646

Please sign in to comment.