ParikhKadam / bidaf-keras

Bidirectional Attention Flow for Machine Comprehension implemented in Keras 2
GNU General Public License v3.0
64 stars 21 forks source link

Tensor Errors. #10

Open hariteja97 opened 5 years ago

hariteja97 commented 5 years ago

@ParikhKadam I have implemented the code using flask . The error that I face is that.

  1. For first time when I load the passage and question . I get the answer but when I reload to the get page and again load a new passage and question .

    I get error as `` 127.0.0.1 - - [04/Jun/2019 00:02:04] "POST /upload HTTP/1.1" 500 - Traceback (most recent call last): File "/home/hariteja/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1092, in _run subfeed, allow_tensor=True, allow_operation=False) File "/home/hariteja/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3490, in as_graph_element return self._as_graph_element_locked(obj, allow_tensor, allow_operation) File "/home/hariteja/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3569, in _as_graph_element_locked raise ValueError("Tensor %s is not an element of this graph." % obj) ValueError: Tensor Tensor("Placeholder:0", shape=(400, 400), dtype=float32) is not an element of this graph.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/hariteja/anaconda3/lib/python3.6/site-packages/flask/app.py", line 2309, in call return self.wsgi_app(environ, start_response) File "/home/hariteja/anaconda3/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app response = self.handle_exception(e) File "/home/hariteja/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception reraise(exc_type, exc_value, tb) File "/home/hariteja/anaconda3/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise raise value File "/home/hariteja/anaconda3/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "/home/hariteja/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/hariteja/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/hariteja/anaconda3/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise raise value File "/home/hariteja/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "/home/hariteja/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request return self.view_functionsrule.endpoint File "/home/hariteja/PycharmProjects/Question&Answer/app.py", line 24, in upload result=PassageAns(passage,question) File "/home/hariteja/PycharmProjects/Question&Answer/MachineComp/BiDAF.py", line 13, in PassageAns bidaf_model.load_bidaf(r"/home/hariteja/PycharmProjects/Question&Answer/MachineComp/bidaf/saved_items/bidaf.h5") File "/home/hariteja/anaconda3/lib/python3.6/site-packages/bidaf_keras-1.0.0-py3.6.egg/bidaf/models/bidaf.py", line 87, in load_bidaf self.model = load_model(path, custom_objects=custom_objects) File "/home/hariteja/anaconda3/lib/python3.6/site-packages/keras/engine/saving.py", line 264, in load_model load_weights_from_hdf5_group(f['model_weights'], model.layers) File "/home/hariteja/anaconda3/lib/python3.6/site-packages/keras/engine/saving.py", line 929, in load_weights_from_hdf5_group K.batch_set_value(weight_value_tuples) File "/home/hariteja/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2435, in batch_set_value get_session().run(assign_ops, feed_dict=feed_dict) File "/home/hariteja/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 929, in run run_metadata_ptr) File "/home/hariteja/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1095, in _run 'Cannot interpret feed_dict key as Tensor: ' + e.args[0]) TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(400, 400), dtype=float32) is not an element of this graph.

`` I tried to remove the session but still the error exists.

Thanks in advance

ParikhKadam commented 5 years ago

@hariteja97

There might be some error in your flask backend scripts. Share the code or wait for some time. I have GUI ready for this project. Was busy in past few weeks and hence forgot to upload the new version here. You can share your flask code so that I can help you debug it.

Also, I had put comments in my code "bidaf.py" in predict_ans function. Where I used K.clear_session(). Uncomment it.. And load the model every time before predictions. This will help you run predictions on low memory. Maybe this solves your issue.

hariteja97 commented 5 years ago

This is the code in flask . I can't again run the same code as it was delivering me tensors error.

@app.route("/upload",methods=['POST']) def upload(): if(request.form["submit_button"]=="Answer"): passage=request.form["passage"] question=request.form["question"] result=PassageAns(passage,question) print(result) return render_template("upload.html",data_list=result)

nayanar03 commented 5 years ago

same issue with django... TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder_32:0", shape=(400, 400), dtype=float32) is not an element of this graph.