Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
[MXNET-1301] Remove the unnecessary WaitAll statements from inception…
Browse files Browse the repository at this point in the history
…_inference example (#13972)

* Removed the unnecessary WaitAll statements

* Removed the WaitAll() calls wherever they are not necessary.
  • Loading branch information
leleamol authored and sandeep-krishnamurthy committed Jan 25, 2019
1 parent 577275d commit f1c063e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cpp-package/example/inference/inception_inference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ void Predictor::LoadMeanImageData() {
mean_image_data.SyncCopyFromCPU(
NDArray::LoadToMap(mean_image_file)["mean_img"].GetData(),
input_shape.Size());
NDArray::WaitAll();
}


Expand Down Expand Up @@ -244,7 +243,6 @@ void Predictor::LoadDefaultMeanImageData() {
}
mean_image_data = NDArray(input_shape, global_ctx, false);
mean_image_data.SyncCopyFromCPU(array.data(), input_shape.Size());
NDArray::WaitAll();
}


Expand Down Expand Up @@ -273,7 +271,6 @@ NDArray Predictor::LoadInputImage(const std::string& image_file) {
}
NDArray image_data = NDArray(input_shape, global_ctx, false);
image_data.SyncCopyFromCPU(array.data(), input_shape.Size());
NDArray::WaitAll();
return image_data;
}

Expand All @@ -299,21 +296,26 @@ void Predictor::PredictImage(const std::string& image_file) {
*
*/
image_data.CopyTo(&(executor->arg_dict()["data"]));
NDArray::WaitAll();

// Run the forward pass.
executor->Forward(false);

// The output is available in executor->outputs.
auto array = executor->outputs[0].Copy(global_ctx);
NDArray::WaitAll();

/*
* Find out the maximum accuracy and the index associated with that accuracy.
* This is done by using the argmax operator on NDArray.
*/
auto predicted = array.ArgmaxChannel();
NDArray::WaitAll();

/*
* Wait until all the previous write operations on the 'predicted'
* NDArray to be complete before we read it.
* This method guarantees that all previous write operations that pushed into the backend engine
* for execution are actually finished.
*/
predicted.WaitToRead();

int best_idx = predicted.At(0, 0);
float best_accuracy = array.At(0, best_idx);
Expand Down

0 comments on commit f1c063e

Please sign in to comment.