paoloviviani commented on issue #8126: Not able to train a neural network [XOR added] URL: https://github.com/apache/incubator-mxnet/issues/8126#issuecomment-387795585 I'm implementing a multi layer perceptron for naïve regression. I succeeded in training by creating DataBatch objects from NDArray and using them to train the model: ```cpp vector<DataBatch> data_loader; size_t samples = 0; while (samples < data_count) { DataBatch mini_batch; mini_batch.data = data_array.Slice(samples, samples + batch_size).Copy(ctx); mini_batch.label = label_array.Slice(samples, samples + batch_size).Copy(ctx); if (data_count-samples < batch_size) mini_batch.pad_num = padding; else mini_batch.pad_num = 0; data_loader.push_back(mini_batch); samples += batch_size; } ``` then this can be used to train as following: ```cpp for (auto mb : data_loader) { mb.data.CopyTo(&args["X"]); mb.label.CopyTo(&args["label"]); exec->Forward(true); exec->Backward(); for (size_t i = 0; i < arg_names.size(); ++i) { if (arg_names[i] == "X" || arg_names[i] == "label") continue; opt->Update(i, exec->arg_arrays[i], exec->grad_arrays[i]); } } ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
