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
When on the chapter_7 branch and running:


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 (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/", 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/", 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/", 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/", line 35, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/Flask-1.0.2-py3.6.egg/flask/", 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/", 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/", 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/", 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/", 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/", line 1164, in predict
  File "/usr/local/lib/python3.6/site-packages/Keras-2.2.4-py3.6.egg/keras/engine/", line 554, in _make_predict_function
  File "/usr/local/lib/python3.6/site-packages/Keras-2.2.4-py3.6.egg/keras/backend/", 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/", line 2546, in __init__
    with tf.control_dependencies(self.outputs):
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/", line 5004, in control_dependencies
    return get_default_graph().control_dependencies(control_inputs)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/", line 4543, in control_dependencies
    c = self.as_graph_element(c)
  File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/", 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/", 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. - - [29/Oct/2018 14:07:52] "POST /select-move/predict HTTP/1.1" 500 -
get_to_go (1) [Avatar] Offline
Did you manage to solve it? I'm getting the same error when running the GitHub code
primeMover (3) [Avatar] Offline
I managed to fix this by adding a call to model._make_predict_function() right after loading the model in

Code should look like this.

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