yanpanlau / DDPG-Keras-Torcs

Using Keras and Deep Deterministic Policy Gradient to play TORCS
717 stars 267 forks source link

Someting error when running on Keras2.0.3 #17

Open xiaoguai0992 opened 7 years ago

xiaoguai0992 commented 7 years ago

When I tried your code under Keras2.0.3 and tensorflow1.0.1 backend, some error occurs. Python version is 3.6

Which part should I modify if I want to run it correctly and why?

Thanks a lot.

Here are the detail imformation:

Traceback (most recent call last): File "ddpg.py", line 162, in playGame() File "ddpg.py", line 52, in playGame actor = ActorNetwork(sess, state_dim, action_dim, BATCH_SIZE, TAU, LRA) File "/home/test/gym_torcs/ActorNetwork.py", line 25, in init self.model , self.weights, self.state = self.create_actor_network(state_size, action_size)
File "/home/test/gym_torcs/ActorNetwork.py", line 51, in create_actor_network Steering = Dense(1,activation='tanh',init=lambda shape, name: normal(shape, scale=1e-4, name=name))(h1)
File "/home/test/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 551, in call self.build(input_shapes[0]) File "/home/test/anaconda3/lib/python3.6/site-packages/keras/layers/core.py", line 827, in build constraint=self.kernel_constraint) File "/home/test/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 384, in add_weight weight = K.variable(initializer(shape), dtype=K.floatx(), name=name) TypeError: () missing 1 required positional argument: 'name'

yanpanlau commented 7 years ago

The code was only test with Python 2.7, tensorflow 0.12 and Keras version 1.x (which is the latest version as of Oct 2016).

I heard there are many new changes in Keras 2.0 and Tensorflow 1.x so probably not compatible.

I will need a bit time to re-write under the latest version.

Thanks for your kind understanding.

[Or you can just setup an virtual environment and install the old version, I am sure it will work]

On Wed, Apr 12, 2017 at 7:23 PM, xiaoguai0992 notifications@github.com wrote:

When I tried your code under Keras2.0.3 and tensorflow1.0.1 backend, some error occurs. Python version is 3.6

Which part should I modify if I want to run it correctly and why?

Thanks a lot.

Here are the detail imformation:

Traceback (most recent call last): File "ddpg.py", line 162, in playGame() File "ddpg.py", line 52, in playGame actor = ActorNetwork(sess, state_dim, action_dim, BATCH_SIZE, TAU, LRA) File "/home/test/gym_torcs/ActorNetwork.py", line 25, in init self.model , self.weights, self.state = self.create_actor_network(state_size, action_size) File "/home/test/gym_torcs/ActorNetwork.py", line 51, in create_actor_network Steering = Dense(1,activation='tanh',init=lambda shape, name: normal(shape, scale=1e-4, name=name))(h1) File "/home/test/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 551, in call self.build(input_shapes[0]) File "/home/test/anaconda3/lib/python3.6/site-packages/keras/layers/core.py", line 827, in build constraint=self.kernel_constraint) File "/home/test/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 384, in add_weight weight = K.variable(initializer(shape), dtype=K.floatx(), name=name) TypeError: () missing 1 required positional argument: 'name'

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/yanpanlau/DDPG-Keras-Torcs/issues/17, or mute the thread https://github.com/notifications/unsubscribe-auth/AO1sY_guZDrIT1aGh67cIkF3iHnNN-ujks5rvLQagaJpZM4M7SpL .

xiaoguai0992 commented 7 years ago

I solved it by changing part of your code.

At ActionNetwork.py:

Replace Steering = Dense(.... and following 3 lines Dense call with Dense(1,activation='tanh',init=lambda shape:VarianceScaling(scale=1e-4)(shape))(h1)

and from keras.initializers import VarianceScaling

then the code works correctly.

s7ev3n commented 7 years ago

I was facing this keras(2.0.5) and tensorflow (gpu 1.2.1) version mismatch problem too. And I replaced what you did, and it stoped error, but it keeps relauching torcs, I am not sure it is training??

brucewayne1248 commented 6 years ago

Could someone elaborate on what the lines Steering = Dense(1,activation='tanh',init=lambda shape, name: normal(shape, scale=1e-4, name=name))(h1) or the replaced Steering = Dense(1,activation='tanh',init=lambda shape:VarianceScaling(scale=1e-4)(shape))(h1) exactly do? I understand that it creates a layer outputting one scalar value with the activation function tanh (values -1 to 1) using the input layer h1. However I am confused by the way the lambda command and the shape keyword is used. I assume it is used to initialize the kernel weights of the output layer to normally distributed values with respect to amount of input and output values? Is there maybe a "more beginner friendly" way to write those lines? Thanks in advance