harvitronix / reinforcement-learning-car

Using reinforcement learning to teach a car to avoid obstacles.
MIT License
488 stars 202 forks source link

Layer shape not compatible with weight shape #5

Closed Tveek closed 8 years ago

Tveek commented 8 years ago

it is long time to train,however,after some time ,I get some moudles.when i run thepython3 playing.py,there are some errro that Exception: Layer shape (3, 164) not compatible with weight shape (6, 164).

harvitronix commented 8 years ago

@DemoRunner Looks like your NUM_SENSORS constant in playing.py is set to 3. Update that to 6 and you should be good!

Tveek commented 8 years ago

@harvitronix thanks,this problem is solved.however,there is another"ValueError: Shape mismatch: x has 3 cols (and 1 rows) but y has 6 rows (and 164 cols)".I know it is related with theano,but I can not deal it.had you encountered this problem ?can you help me ?

harvitronix commented 8 years ago

@DemoRunner Not sure I know what that one is, off the top of my head. Is there more info from the error? File/line? Thanks.

Tveek commented 8 years ago

@harvitronix I am also run the python3 playing.py. Error is in 25 line of playing.py.The all message is that File "playing.py", line 38, in play(model) File "playing.py", line 25, in play action = (np.argmax(model.predict(state, batch_size=1))) File "/usr/local/lib/python3.4/dist-packages/keras/models.py", line 661, in predict return self._predict_loop(self._predict, X, batch_size, verbose)[0] File "/usr/local/lib/python3.4/dist-packages/keras/models.py", line 322, in _predict_loop batch_outs = f(ins_batch) File "/usr/local/lib/python3.4/dist-packages/keras/backend/theano_backend.py", line 384, in call return self.function(*inputs) File "/usr/local/lib/python3.4/dist-packages/theano/compile/function_module.py", line 871, in call storage_map=getattr(self.fn, 'storage_map', None)) File "/usr/local/lib/python3.4/dist-packages/theano/gof/link.py", line 314, in raise_with_op reraise(exc_type, exc_value, exc_trace) File "/usr/lib/python3/dist-packages/six.py", line 535, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.4/dist-packages/theano/compile/function_module.py", line 859, in call outputs = self.fn() ValueError: Shape mismatch: x has 3 cols (and 1 rows) but y has 6 rows (and 164 cols)

MickyDowns commented 8 years ago

@harvitronix, great job! Looking forward to the next post. I've added a "dog" to spice mine up a bit. I may take a crack at adding forecast trajectories for your moving objects to see if that speeds training.

@DemoRunner, I had both these problems today on "Sonar". Haven't solved the second error yet, but did get the model output from learning.py to work with playing.py by learning w/ just 3 input nodes i.e.,: NUM_FRAMES = 1 # was 2 NUM_SENSORS = 3 NUM_INPUT = NUM_SENSORS * NUM_FRAMES

It trains more slowly. So, while it's training, take the model output that's auto-generated after 25k frames and run it thru playing.py to make sure you're on the right track: saved_model = 'saved-models/164-150-100-50000-25000.h5'.

Two related notes:

  1. I had to create that "saved_models" sub-directory manually,
  2. You'll need to flip the output flags in carmunk.py to ensure playing.py results are shown on the screen: show_sensors = True # was False draw_screen = True # was False

Just make sure to flip them back next time you train.

harvitronix commented 8 years ago

@DemoRunner Sorry for my slow response. Just to be sure, do you have your net shape defined? Ie. If you're training a 164x150, do you have line 38 in playing.py set to 164x150 as well?

Apologies also for the bugs in the released code. Think I need to release an update that has the number of frames and sensors lined up correctly. Seems I committed in an in-between state.

harvitronix commented 8 years ago

@DemoRunner @MickyDowns Hey guys, I figured out the issue. Totally my bad. I had incorporated multi-frame training into learning, but had never added support for that in playing. So I removed it from learning.

Now, if you learn a model in learning, you can immediately play it in playing.

Thanks a ton for the feedback.

Tveek commented 8 years ago

@harvitronix Thanks ,I am busy with other things on this days.You are a responsible person.