yanpanlau / Keras-FlappyBird

Using Keras and Deep Q-Network to Play FlappyBird

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: <lambda>() got an unexpected keyword argument 'dim_ordering'

Kaido0 opened this issue · comments

commented

This is my first time run this code,and I got the error.
Keras=1.2.2
using theano backend.

I do not know how to solve this problem~

libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Using Theano backend.
Now we build the model
Traceback (most recent call last):
File "qlearn.py", line 198, in
main()
File "qlearn.py", line 195, in main
playGame(args)
File "qlearn.py", line 188, in playGame
model = buildmodel()
File "qlearn.py", line 44, in buildmodel
model.add(Convolution2D(32, 8, 8, subsample=(4,4),init=lambda shape, name: normal(shape, scale=0.01, name=name), border_mode='same',input_shape=(img_channels,img_rows,img_cols)))
File "/home/kaido/anaconda2/lib/python2.7/site-packages/keras/models.py", line 299, in add
layer.create_input_layer(batch_input_shape, input_dtype)
File "/home/kaido/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 401, in create_input_layer
self(x)
File "/home/kaido/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 546, in call
self.build(input_shapes[0])
File "/home/kaido/anaconda2/lib/python2.7/site-packages/keras/layers/convolutional.py", line 436, in build
constraint=self.W_constraint)
File "/home/kaido/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 418, in add_weight
weight = initializer(shape, name=name)
TypeError: () got an unexpected keyword argument 'dim_ordering'

commented

I have solved this problem.
1.lambed shape——>'normal'
2.delete name:......

Changing to init='normal', and deleting name:... works for me.

I did just like you said, Changing to init='normal', and deleting name:
but I got this: what's the problem?

python qlearn.py -m "Run"
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
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 2708, in load_weights
self.load_weights_from_hdf5_group(f)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2794, 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 1876, in batch_set_value
assign_op = x.assign(assign_placeholder)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variables.py", line 522, 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 763, in apply_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2329, in create_op
set_shapes_for_outputs(ret)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1717, in set_shapes_for_outputs
shapes = shape_func(op)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1667, 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 676, 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].

I got that error as well. I believe it has to do with tensorflow/keras configuration,as the author pointed out:
B) The ordering of the dimension is important, the default setting is 4x80x80 (Theano setting), so if your input is 80x80x4 (Tensorflow setting) then you are in trouble because the dimension is wrong. Alert: If your input dimension is 80x80x4 (Tensorflow setting) you need to set dim_ordering = tf (tf means tensorflow, th means theano)

Thank you so much! I will try that. :)

When I first write the program, I would like to initialize the neural network with a custom initialization

https://groups.google.com/forum/#!topic/keras-users/kc0Jsw1vTqY

But it seems the lambda function is no longer support in the latest version of the Keras.

I suggest you just remove the additional "lambda" statement and also delete the weight file and re-run the code.

python qlearn.py -m "Train"

It should work. I just test it.

I have fixed the code. You should able to run with Keras and tensorflow backend.

I trained the model with your old version on 12 March, it kept exploring after 420000 timesteps without any improvement visually. I'll try the new one.