Conversation
nihui
left a comment
There was a problem hiding this comment.
docs/how-to-use-and-FAQ/quantized-int8-inference.md 文档中添加使用 npy 的内容
tools/quantize/ncnn2table.cpp
Outdated
| return ncnn::Mat(shape[0], (void*)(d.data.data())).clone(); | ||
| case 2: | ||
| return ncnn::Mat(shape[0], shape[1], (void*)(d.data.data())).clone(); | ||
| case 3: | ||
| return ncnn::Mat(shape[0], shape[1], shape[2], (void*)(d.data.data())).clone(); | ||
| case 4: | ||
| return ncnn::Mat(shape[0], shape[1], shape[2], shape[3], (void*)(d.data.data())).clone(); | ||
| default: |
There was a problem hiding this comment.
3d 4d 可能存在 channel gap
先从1d的构造,然后reshape到3d,再clone
tools/quantize/ncnn2table.cpp
Outdated
|
|
||
| inline ncnn::Mat read_npy(const std::vector<int>& shape, const std::string& npypath) | ||
| { | ||
| npy::npy_data<float> d = npy::read_npy<float>(npypath); |
There was a problem hiding this comment.
read_npy 可能会抛出异常,需要 catch 处理下,提示错误的文件是哪个,然后跳过当前文件?
There was a problem hiding this comment.
不建议处理异常,尤其是为了跳过错误文件,因为用npy的情况下,使用的数据一般是训练的数据,基本都是经过清洗和前处理的,几乎不可能出现个别错误的npy文件,只有可能全部出错,这个和自己收集的image文件不一样。
There was a problem hiding this comment.
不建议处理异常,尤其是为了跳过错误文件,因为用npy的情况下,使用的数据一般是训练的数据,基本都是经过清洗和前处理的,几乎不可能出现个别错误的npy文件,只有可能全部出错,这个和自己收集的image文件不一样。
那么 fprintf(stderr 输出npy错误信息,然后直接 exit ?
|
判断传入shape和npy的shape是否匹配还是直接判断两个的total size,如果是判断shape匹配,就稍微有点严格,要不要check这个? |
严格判断shape匹配,可变shape没法统计的... |
|
是的,我准备把这个npypath打印消息移除 |
|
Thanks for your contribution ! |
ncnn2table增加读npy功能
命令增加一个参数type,type为0时和原来一样,可省略
type为1时,以npy格式读文件,读npy引用(https://github.com/llohse/libnpy)实现。
单个input blob测试通过,多个未测试(没资源)