Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
reuben committed Jun 4, 2019
1 parent 35b937f commit 4713153
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
7 changes: 4 additions & 3 deletions native_client/deepspeech.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,12 @@ DS_CreateModel(const char* aModelPath,
return DS_ERR_NO_MODEL;
}

std::unique_ptr<ModelState> model(
#ifndef USE_TFLITE
std::unique_ptr<ModelState> model(new TFModelState());
new TFModelState()
#else
std::unique_ptr<ModelState> model(new TFLiteModelState());
#endif // USE_TFLITE
new TFLiteModelState()
);

if (!model) {
std::cerr << "Could not allocate model state." << std::endl;
Expand Down
16 changes: 13 additions & 3 deletions native_client/tflitemodelstate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ tflite_get_output_tensor_by_name(const Interpreter* interpreter, const char* nam
return interpreter->outputs()[idx];
}

void push_back_if_not_present(std::deque<int>& list, int value)
void
push_back_if_not_present(std::deque<int>& list, int value)
{
if (std::find(list.begin(), list.end(), value) == list.end()) {
list.push_back(value);
Expand Down Expand Up @@ -86,6 +87,10 @@ TFLiteModelState::TFLiteModelState()
{
}

TFLiteModelState::~TFLiteModelState()
{
}

int
TFLiteModelState::init(const char* model_path,
unsigned int n_features,
Expand Down Expand Up @@ -235,8 +240,13 @@ TFLiteModelState::compute_mfcc(const vector<float>& samples, vector<float>& mfcc
input_samples[i] = samples[i];
}

interpreter_->SetExecutionPlan(mfcc_exec_plan_);
TfLiteStatus status = interpreter_->Invoke();
TfLiteStatus status = interpreter_->SetExecutionPlan(mfcc_exec_plan_);
if (status != kTfLiteOk) {
std::cerr << "Error setting execution plan: " << status << "\n";
return;
}

status = interpreter_->Invoke();
if (status != kTfLiteOk) {
std::cerr << "Error running session: " << status << "\n";
return;
Expand Down
1 change: 1 addition & 0 deletions native_client/tflitemodelstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct TFLiteModelState : public ModelState
std::vector<int> mfcc_exec_plan_;

TFLiteModelState();
virtual ~TFLiteModelState();

virtual int init(const char* model_path,
unsigned int n_features,
Expand Down

0 comments on commit 4713153

Please sign in to comment.