batch scoring in cpp
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 30/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- cpp
调研方向
首先使用 ResNet 符号文件和参数文件重现 issue 中的两条路径,然后跟踪每种方法所使用的 C++ NDArray::Load、Symbol::SimpleBind 和 executor 设置调用。比较得到的参数映射和批处理方式,并将完成定义为:确定 segmentation fault 的原因,并记录哪种 batch-scoring 方法有效以及原因。
由索引模型根据 Issue 内容生成。
描述
I am trying to load a pre-built model and do batch scoring, I tried the following two ways, the first one can produce some results, and the second one compiles successfully but runs with segmentation fault. Could you please let me know which way I should follow, and why the second way doesn't work? Thanks!
method 1:
/* Image size and channels */
int width = 224;
int height = 224;
int channels = 3;
int batch_size = 5;
Context ctx_dev(DeviceType::kCPU, 0);
map<string, NDArray> args_map;
map<string, NDArray> aux_map;
map<string, NDArray> parameters;
NDArray::Load("../Resnet/resnet-152-0000.params", 0, ¶meters);
for (const auto &k : parameters) {
if (k.first.substr(0, 4) == "aux:") {
auto name = k.first.substr(4, k.first.size() - 4);
aux_map[name] = k.second.Copy(ctx_dev);
}
if (k.first.substr(0, 4) == "arg:") {
auto name = k.first.substr(4, k.first.size() - 4);
args_map[name] = k.second.Copy(ctx_dev);
}
}
auto net = Symbol::Load("../Resnet/resnet-152-symbol.json");
auto data_iter = MXDataIter("ImageRecordIter")
.SetParam("path_imglist","../caltech_256/caltech-256-60-train.lst")
.SetParam("path_imgrec","../caltech_256/caltech-256-60-train.rec")
.SetParam("data_shape", Shape(3, 224, 224))
.SetParam("batch_size", batch_size)
.SetParam("shuffle", 1)
.CreateDataIter();
while(data_iter.Next()){
auto batch = data_iter.GetData();
args_map["data"] = batch;
auto *exec = net.SimpleBind(ctx_dev, args_map);
exec->Forward(false);
auto outputs = exec->outputs[0].Copy(Context(kCPU, 0));
NDArray::WaitAll();
for (int i = 0; i <2; i++) {
cout << outputs.At(0, i) <<",";
}
cout << endl;
}
MXNotifyShutdown();
method 2:
int width = 224;
int height = 224;
int channels = 3;
int batch_size = 5;
Context ctx_dev(DeviceType::kCPU, 0);
map<string, NDArray> args_map;
map<string, NDArray> aux_map;
args_map["data"] = NDArray(Shape(batch_size, channels, width, height), ctx_dev);
args_map["label"] = NDArray(Shape(batch_size), ctx_dev);
auto net = Symbol::Load("../Resnet/resnet-152-symbol.json");
auto *exec = net.SimpleBind(ctx_dev, args_map);
NDArray::Load("../Resnet/resnet-152-0000.params", 0, &args_map);
auto data_iter = MXDataIter("ImageRecordIter")
.SetParam("path_imglist","../caltech_256/caltech-256-60-train.lst")
.SetParam("path_imgrec","../caltech_256/caltech-256-60-train.rec")
.SetParam("data_shape", Shape(3, 224, 224))
.SetParam("batch_size", batch_size)
.SetParam("shuffle", 1)
.CreateDataIter();
while(data_iter.Next()){
auto batch = data_iter.GetDataBatch();
batch.data.CopyTo(&args_map["data"]);
batch.label.CopyTo(&args_map["label"]);
exec->Forward(false);
NDArray::WaitAll();
}
delete exec;
MXNotifyShutdown();
- 主要语言
- C++
- 星标
- 113
- 派生
- 78
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dmlc/MXNet.cpp 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 25/100
-
难度 3/5 1-2 天 新手友好度 25/100
-
难度 4/5 3-5 天 新手友好度 25/100
-
难度 3/5 1-2 天 新手友好度 25/100
-
难度 4/5 3-5 天 新手友好度 25/100
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 90/100
AXERA-TECH/ax-llm#77 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
games-on-whales/wolf#509 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
-
bug-unconfirmed
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 74/100
NVIDIA/cuda-samples#453 ·