【问题标题】:Python Keras ValueError NeuralNetwork FlappyBird GamePython Keras ValueError 神经网络 FlappyBird 游戏
【发布时间】:2016-12-30 13:07:44
【问题描述】:

我在我的电脑本地克隆了以下涉及reinforcement learningFlappy-Bird 项目(https://github.com/yanpanlau/Keras-FlappyBird)。我安装了依赖项,但是当我运行它时(python qlearn.py -m "Run"),我收到了以下错误:

/usr/local/lib/python2.7/dist-packages/skimage/viewer/__init__.py:6: UserWarning: Viewer requires Qt
  warn('Viewer requires Qt')
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Using TensorFlow backend.
Now we build the model
We finish building the model
Now we load weight
Traceback (most recent call last):
  File "qlearn.py", line 198, in <module>
    main()
  File "qlearn.py", line 195, in main
    playGame(args)
  File "qlearn.py", line 189, in playGame
    trainNetwork(model,args)
  File "qlearn.py", line 85, in trainNetwork
    model.load_weights("model.h5")
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2701, in load_weights
    self.load_weights_from_hdf5_group(f)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2787, in load_weights_from_hdf5_group
    K.batch_set_value(weight_value_tuples)
  File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 1544, in batch_set_value
    assign_op = x.assign(assign_placeholder)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variables.py", line 575, in assign
    return state_ops.assign(self._variable, value, use_locking=use_locking)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_state_ops.py", line 47, in assign
    use_locking=use_locking, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 759, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2242, in create_op
    set_shapes_for_outputs(ret)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1617, in set_shapes_for_outputs
    shapes = shape_func(op)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1568, in call_with_requiring
    return call_cpp_shape_fn(op, require_shape_fn=True)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 610, in call_cpp_shape_fn
    debug_python_shape_fn, require_shape_fn)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 675, in _call_cpp_shape_fn_impl
    raise ValueError(err.message)
ValueError: Dimension 0 in both shapes must be equal, but are 8 and 32 for 'Assign' (op: 'Assign') with input shapes: [8,8,80,32], [32,4,8,8].

默认情况下,Keras 使用tensorflow 作为后端,所以也许参数的顺序可以暗示这个错误,但我想不通。

【问题讨论】:

    标签: python neural-network keras


    【解决方案1】:

    使用"image_dim_ordering": "th" 训练保存的模型。我很确定您的系统当前配置为tf。只需打开 ~/.keras/keras.json 并将其更改为 th 即可正确加载模型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-07
      • 2017-11-28
      • 2020-03-16
      • 1970-01-01
      • 2017-11-21
      • 1970-01-01
      • 2021-01-21
      • 1970-01-01
      相关资源
      最近更新 更多