Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Someting error when running on Keras2.0.3 #17

Open
xiaoguai0992 opened this issue Apr 12, 2017 · 4 comments
Open

Someting error when running on Keras2.0.3 #17

xiaoguai0992 opened this issue Apr 12, 2017 · 4 comments

Comments

@xiaoguai0992
Copy link

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
Copy link
Owner

yanpanlau commented Apr 13, 2017 via email

@xiaoguai0992
Copy link
Author

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
Copy link

s7ev3n commented Jul 3, 2017

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
Copy link

brucewayne1248 commented May 1, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants