-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
WIP: add read npy for ncnn2table #5930
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3d 4d 可能存在 channel gap
先从1d的构造,然后reshape到3d,再clone
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read_npy 可能会抛出异常,需要 catch 处理下,提示错误的文件是哪个,然后跳过当前文件?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不建议处理异常,尤其是为了跳过错误文件,因为用npy的情况下,使用的数据一般是训练的数据,基本都是经过清洗和前处理的,几乎不可能出现个别错误的npy文件,只有可能全部出错,这个和自己收集的image文件不一样。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不建议处理异常,尤其是为了跳过错误文件,因为用npy的情况下,使用的数据一般是训练的数据,基本都是经过清洗和前处理的,几乎不可能出现个别错误的npy文件,只有可能全部出错,这个和自己收集的image文件不一样。
那么 fprintf(stderr 输出npy错误信息,然后直接 exit ?
判断传入shape和npy的shape是否匹配还是直接判断两个的total size,如果是判断shape匹配,就稍微有点严格,要不要check这个? |
严格判断shape匹配,可变shape没法统计的... |
ncnn2table增加读npy功能
命令增加一个参数type,type为0时和原来一样,可省略
type为1时,以npy格式读文件,读npy引用(https://github.com/llohse/libnpy)实现。
单个input blob测试通过,多个未测试(没资源)