diff --git a/cpp-package/example/alexnet.cpp b/cpp-package/example/alexnet.cpp index 7564d4361b18..1c0f7130d974 100644 --- a/cpp-package/example/alexnet.cpp +++ b/cpp-package/example/alexnet.cpp @@ -244,10 +244,14 @@ int main(int argc, char const *argv[]) { }; auto train_iter = MXDataIter("MNISTIter"); - setDataIter(&train_iter, "Train", data_files, batch_size); + if (!setDataIter(&train_iter, "Train", data_files, batch_size)) { + return 1; + } auto val_iter = MXDataIter("MNISTIter"); - setDataIter(&val_iter, "Label", data_files, batch_size); + if (!setDataIter(&val_iter, "Label", data_files, batch_size)) { + return 1; + } Optimizer* opt = OptimizerRegistry::Find("sgd"); opt->SetParam("momentum", 0.9) diff --git a/cpp-package/example/googlenet.cpp b/cpp-package/example/googlenet.cpp index 4bd3be27fa43..c8078afd0af4 100644 --- a/cpp-package/example/googlenet.cpp +++ b/cpp-package/example/googlenet.cpp @@ -139,10 +139,14 @@ int main(int argc, char const *argv[]) { }; auto train_iter = MXDataIter("MNISTIter"); - setDataIter(&train_iter, "Train", data_files, batch_size); + if (!setDataIter(&train_iter, "Train", data_files, batch_size)) { + return 1; + } auto val_iter = MXDataIter("MNISTIter"); - setDataIter(&val_iter, "Label", data_files, batch_size); + if (!setDataIter(&val_iter, "Label", data_files, batch_size)) { + return 1; + } Optimizer* opt = OptimizerRegistry::Find("sgd"); opt->SetParam("momentum", 0.9) diff --git a/cpp-package/example/inception_bn.cpp b/cpp-package/example/inception_bn.cpp index 5b444e467a37..456e0d913475 100644 --- a/cpp-package/example/inception_bn.cpp +++ b/cpp-package/example/inception_bn.cpp @@ -168,10 +168,14 @@ int main(int argc, char const *argv[]) { }; auto train_iter = MXDataIter("MNISTIter"); - setDataIter(&train_iter, "Train", data_files, batch_size); + if (!setDataIter(&train_iter, "Train", data_files, batch_size)) { + return 1; + } auto val_iter = MXDataIter("MNISTIter"); - setDataIter(&val_iter, "Label", data_files, batch_size); + if (!setDataIter(&val_iter, "Label", data_files, batch_size)) { + return 1; + } // initialize parameters Xavier xavier = Xavier(Xavier::gaussian, Xavier::in, 2); diff --git a/cpp-package/example/lenet_with_mxdataiter.cpp b/cpp-package/example/lenet_with_mxdataiter.cpp index 4df6fbee92e5..39550a3e9e65 100644 --- a/cpp-package/example/lenet_with_mxdataiter.cpp +++ b/cpp-package/example/lenet_with_mxdataiter.cpp @@ -97,10 +97,14 @@ int main(int argc, char const *argv[]) { }; auto train_iter = MXDataIter("MNISTIter"); - setDataIter(&train_iter, "Train", data_files, batch_size); + if (!setDataIter(&train_iter, "Train", data_files, batch_size)) { + return 1; + } auto val_iter = MXDataIter("MNISTIter"); - setDataIter(&val_iter, "Label", data_files, batch_size); + if (!setDataIter(&val_iter, "Label", data_files, batch_size)) { + return 1; + } Optimizer* opt = OptimizerRegistry::Find("sgd"); opt->SetParam("momentum", 0.9) diff --git a/cpp-package/example/mlp_cpu.cpp b/cpp-package/example/mlp_cpu.cpp index dc1ab36727d1..93eaf0538269 100644 --- a/cpp-package/example/mlp_cpu.cpp +++ b/cpp-package/example/mlp_cpu.cpp @@ -63,10 +63,14 @@ int main(int argc, char** argv) { }; auto train_iter = MXDataIter("MNISTIter"); - setDataIter(&train_iter, "Train", data_files, batch_size); + if (!setDataIter(&train_iter, "Train", data_files, batch_size)) { + return 1; + } auto val_iter = MXDataIter("MNISTIter"); - setDataIter(&val_iter, "Label", data_files, batch_size); + if (!setDataIter(&val_iter, "Label", data_files, batch_size)) { + return 1; + } auto net = mlp(layers); diff --git a/cpp-package/example/mlp_gpu.cpp b/cpp-package/example/mlp_gpu.cpp index 67992a19f9f2..0befde8ae4bc 100644 --- a/cpp-package/example/mlp_gpu.cpp +++ b/cpp-package/example/mlp_gpu.cpp @@ -63,10 +63,14 @@ int main(int argc, char** argv) { }; auto train_iter = MXDataIter("MNISTIter"); - setDataIter(&train_iter, "Train", data_files, batch_size); + if (!setDataIter(&train_iter, "Train", data_files, batch_size)) { + return 1; + } auto val_iter = MXDataIter("MNISTIter"); - setDataIter(&val_iter, "Label", data_files, batch_size); + if (!setDataIter(&val_iter, "Label", data_files, batch_size)) { + return 1; + } auto net = mlp(layers); diff --git a/cpp-package/example/resnet.cpp b/cpp-package/example/resnet.cpp index 0bb77a1a1284..7c9dd4daa55a 100644 --- a/cpp-package/example/resnet.cpp +++ b/cpp-package/example/resnet.cpp @@ -179,10 +179,14 @@ int main(int argc, char const *argv[]) { }; auto train_iter = MXDataIter("MNISTIter"); - setDataIter(&train_iter, "Train", data_files, batch_size); + if (!setDataIter(&train_iter, "Train", data_files, batch_size)) { + return 1; + } auto val_iter = MXDataIter("MNISTIter"); - setDataIter(&val_iter, "Label", data_files, batch_size); + if (!setDataIter(&val_iter, "Label", data_files, batch_size)) { + return 1; + } // initialize parameters Xavier xavier = Xavier(Xavier::gaussian, Xavier::in, 2); diff --git a/cpp-package/example/test_score.cpp b/cpp-package/example/test_score.cpp index 9252701e2ae6..7e5096abb816 100644 --- a/cpp-package/example/test_score.cpp +++ b/cpp-package/example/test_score.cpp @@ -70,10 +70,14 @@ int main(int argc, char** argv) { }; auto train_iter = MXDataIter("MNISTIter"); - setDataIter(&train_iter, "Train", data_files, batch_size); + if (!setDataIter(&train_iter, "Train", data_files, batch_size)) { + return 1; + } auto val_iter = MXDataIter("MNISTIter"); - setDataIter(&val_iter, "Label", data_files, batch_size); + if (!setDataIter(&val_iter, "Label", data_files, batch_size)) { + return 1; + } auto net = mlp(layers); diff --git a/cpp-package/example/utils.h b/cpp-package/example/utils.h index 2ed5c4c11f02..020d1ec5804e 100644 --- a/cpp-package/example/utils.h +++ b/cpp-package/example/utils.h @@ -40,12 +40,13 @@ bool check_datafiles(const std::vector &data_files) { } } return true; - } +} bool setDataIter(MXDataIter *iter , const std::string &useType, const std::vector &data_files, int batch_size) { - if (!check_datafiles(data_files)) + if (!check_datafiles(data_files)) { return false; + } iter->SetParam("batch_size", batch_size); iter->SetParam("shuffle", 1);