batch scoring in cpp

Abierto
#80 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
30/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
cpp

Línea de trabajo

Comience reproduciendo las dos rutas del issue con los archivos de símbolos y parámetros de ResNet, y luego rastree las llamadas de C++ NDArray::Load, Symbol::SimpleBind y de configuración del executor que utiliza cada método. Compare los mapas de argumentos resultantes y el manejo de batches, y defina como terminado identificar la causa del segmentation fault y documentar qué enfoque de batch-scoring es válido y por qué.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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, &parameters);

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();
Lenguaje dominante
C++
Estrellas
113
Forks
78
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dmlc/MXNet.cpp

Todos los issues de dmlc/MXNet.cpp

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.