The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

aanno (8) [Avatar] Offline
#1
When on the chapter_7 branch and running:

python end_to_end.py


it is not possible to play at http://localhost:5000/static/play_predict_19.html becasue of the following error:

Epoch 20/20
11264/11264 [==============================] - 163s 14ms/step - loss: 1.2707 - acc: 0.5838
 * Serving Flask app "dlgo.httpfrontend.server" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
[2018-10-29 14:07:52,744] ERROR in app: Exception on /select-move/predict [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/Flask-1.0.2-py3.6.egg/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/Flask-1.0.2-py3.6.egg/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.6/site-packages/Flask-1.0.2-py3.6.egg/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/Flask-1.0.2-py3.6.egg/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/Flask-1.0.2-py3.6.egg/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/Flask-1.0.2-py3.6.egg/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.6/site-packages/dlgo-0.2-py3.6.egg/dlgo/httpfrontend/server.py", line 55, in select_move
    bot_move = bot_agent.select_move(game_state)
  File "/usr/local/lib/python3.6/site-packages/dlgo-0.2-py3.6.egg/dlgo/agent/predict.py", line 33, in select_move
    move_probs = self.predict(game_state)
  File "/usr/local/lib/python3.6/site-packages/dlgo-0.2-py3.6.egg/dlgo/agent/predict.py", line 29, in predict
    return self.model.predict(input_tensor)[0]
  File "/usr/local/lib/python3.6/site-packages/Keras-2.2.4-py3.6.egg/keras/engine/training.py", line 1164, in predict
    self._make_predict_function()
  File "/usr/local/lib/python3.6/site-packages/Keras-2.2.4-py3.6.egg/keras/engine/training.py", line 554, in _make_predict_function
    **kwargs)
  File "/usr/local/lib/python3.6/site-packages/Keras-2.2.4-py3.6.egg/keras/backend/tensorflow_backend.py", line 2744, in function
    return Function(inputs, outputs, updates=updates, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/Keras-2.2.4-py3.6.egg/keras/backend/tensorflow_backend.py", line 2546, in __init__
    with tf.control_dependencies(self.outputs):
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 5004, in control_dependencies
    return get_default_graph().control_dependencies(control_inputs)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 4543, in control_dependencies
    c = self.as_graph_element(c)
  File "/usr/local/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 "/usr/local/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("dense_2_1/Softmax:0", shape=(?, 361), dtype=float32) is not an element of this graph.
127.0.0.1 - - [29/Oct/2018 14:07:52] "POST /select-move/predict HTTP/1.1" 500 -
get_to_go (1) [Avatar] Offline
#2
Did you manage to solve it? I'm getting the same error when running the GitHub code
primeMover (3) [Avatar] Offline
#3
I managed to fix this by adding a call to model._make_predict_function() right after loading the model in predict.py

Code should look like this.

def load_prediction_agent(h5file):
    model = kerasutil.load_model_from_hdf5_group(h5file['model'])
    model._make_predict_function()