MycroftAI / mycroft-precise

A lightweight, simple-to-use, RNN wake word listener
Apache License 2.0
838 stars 227 forks source link

Failed when exec "precise-listen", tensorflow.python.framework.errors_impl.FailedPreconditionError #88

Open xianhuasheng opened 4 years ago

xianhuasheng commented 4 years ago

HI, guys: I following the steps to collect audio samples, train the net, and when I exec "precise-listen", I got errors as below, I use the latest "dev" branch. Can anyone help me on this? Thanks.

Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner self.run() File "/usr/lib/python3.5/threading.py", line 862, in run self._target(*self._args, **self._kwargs) File "/mnt/data/work/mycroft/mycroft-precise-n/runner/precise_runner/runner.py", line 236, in _handle_predictions prob = self.engine.get_prediction(chunk) File "/mnt/data/work/mycroft/mycroft-precise-n/precise/scripts/listen.py", line 87, in get_prediction return listener.update(chunk) File "/mnt/data/work/mycroft/mycroft-precise-n/precise/network_runner.py", line 139, in update raw_output = self.runner.run(mfccs) File "/mnt/data/work/mycroft/mycroft-precise-n/precise/network_runner.py", line 82, in run return self.predict(inp[np.newaxis])[0][0] File "/mnt/data/work/mycroft/mycroft-precise-n/precise/network_runner.py", line 79, in predict return self.model.predict(inputs) File "/mnt/data/work/mycroft/mycroft-precise-n/.venv/lib/python3.5/site-packages/keras/engine/training.py", line 1462, in predict callbacks=callbacks) File "/mnt/data/work/mycroft/mycroft-precise-n/.venv/lib/python3.5/site-packages/keras/engine/training_arrays.py", line 324, in predict_loop batch_outs = f(ins_batch) File "/mnt/data/work/mycroft/mycroft-precise-n/.venv/lib/python3.5/site-packages/tensorflow/python/keras/backend.py", line 3076, in call run_metadata=self.run_metadata) File "/mnt/data/work/mycroft/mycroft-precise-n/.venv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1439, in call run_metadata_ptr) File "/mnt/data/work/mycroft/mycroft-precise-n/.venv/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 528, in exit c_api.TF_GetCode(self.status.status)) tensorflow.python.framework.errors_impl.FailedPreconditionError: Error while reading resource variable dense_1/kernel from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/dense_1/kernel) [[{{node dense_1/MatMul/ReadVariableOp}}]]

Ake-w commented 4 years ago

@xianhuasheng I have same problem.

harminder0209 commented 4 years ago

I have same issue

liny90626 commented 4 years ago

Got the same problem. Can any one help?

liny90626 commented 4 years ago

I guess I found a way to solve it. We need to change the code of precise/network_runner.py, added like this:

class KerasRunner(Runner):
    def __init__(self, model_name: str):
        import os
        os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
        import tensorflow as tf
        from tensorflow.python.keras.backend import set_session     # added
        self.sess = tf.Session()        # added
        set_session(self.sess)      # added
        self.model = load_precise_model(model_name)
        self.graph = tf.get_default_graph()

    def predict(self, inputs: np.ndarray):
        from tensorflow.python.keras.backend import set_session     # added
        with self.graph.as_default():
            set_session(self.sess)      # added
            return self.model.predict(inputs)

Then run precise-listen, it works for me

MatthewScholefield commented 4 years ago

@liny90626 Awesome, this looks great. Feel free to submit a PR (with a CLA). Otherwise, I can try get the change in within a few days. Sorry for not responding to this. I've been quite busy lately.

imfing commented 4 years ago

I found that the latest Keras version (2.3.1) would cause this weird problem. Revert back to older version simply solved all the problems:

tensorflow==1.13.2 keras==2.2.4

======= Oh, there is a requirements.txt. The setup.sh and setup.py messed up with the versions of the dependencies.

alexisdiaz008 commented 4 years ago

I guess I found a way to solve it. We need to change the code of precise/network_runner.py, added like this:

class KerasRunner(Runner):
    def __init__(self, model_name: str):
        import os
        os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
        import tensorflow as tf
        from tensorflow.python.keras.backend import set_session       # added
        self.sess = tf.Session()      # added
        set_session(self.sess)        # added
        self.model = load_precise_model(model_name)
        self.graph = tf.get_default_graph()

    def predict(self, inputs: np.ndarray):
        from tensorflow.python.keras.backend import set_session       # added
        with self.graph.as_default():
            set_session(self.sess)        # added
            return self.model.predict(inputs)

Then run precise-listen, it works for me

Thank you! working for me now!