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

[MXNET-1301] Remove the unnecessary WaitAll statements from inception_inference example #13972

Merged
merged 2 commits into from
Jan 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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