0

so I am trying to run the a deep q learning code from the book: Python Deep Learning: Exploring deep learning techniques, neural network architectures and GANs with PyTorch, Keras and TensorFlow. When I copy pasted the code, it was out of format so I tried to work on the indintations, spaces,...etc manually. When I run the code I get the following error:

TypeError                                 Traceback (most recent call last)
<ipython-input-365-8b0bd613b3e8> in <module>
      1 if __name__ == '__main__':
      2     session, q_network, t_network, t_net_updates, frame_proc, saver, train_op, env = initialize()
----> 3     deep_q_learning()

<ipython-input-363-ca3b0c8573ad> in deep_q_learning()
     49         if COMPRESS_ER:
     50             mini_batch = [pickle.loads(zlib.decompress(comp_item)) 
---> 51     for comp_item in mini_batch]
     52 
     53         states_batch, action_batch, reward_batch, next_states_batch, terminal_batch = map(np.array, zip(*mini_batch))

<ipython-input-363-ca3b0c8573ad> in <listcomp>(.0)
     49         if COMPRESS_ER:
     50             mini_batch = [pickle.loads(zlib.decompress(comp_item)) 
---> 51     for comp_item in mini_batch]
     52 
     53         states_batch, action_batch, reward_batch, next_states_batch, terminal_batch = map(np.array, zip(*mini_batch))

TypeError: a bytes-like object is required, not 'tuple'

Can you please explain and help me resolve the issue? I think that during the reformatting I may have missed something. If the error message is not enough I can provide the notebook.

Thanks in advance.

DailyReader
  • 43
  • 1
  • 8
  • It's very common error when you copy Python code between different editors. I would recommend to use something like Sublime or IDE such as Pycharm to regulate the format, then it should work. Usually it because of tab or number of spaces are different. – Christopher Jul 03 '20 at 04:37
  • Btw if it helps I think this is a repo for the code in that book: https://github.com/ivan-vasilev/Python-Deep-Learning-SE – ssp Jul 03 '20 at 04:38
  • @Christopher Great advice will try it out. I was using Pycharm for sometime but then I was advised to use an online notebook as it will help with running the code in cells (not sure if that was an option in Pycharm) Thanks a lot and will consider returning to Pycharm! – DailyReader Jul 03 '20 at 05:53
  • @Moosefeather That is great! Helps for sure. Thank you very much. Code is now running lets see if it will reproduce the same error. Hope not! Thanks again!! – DailyReader Jul 03 '20 at 05:54
  • @Moosefeather so I have run the code and it worked for about 35 episodes before giving met the same error at the same spot ( although this time I literally copy pasted the related function from the link you mentioned). What could be wrong with this line ? `mini_batch = [pickle.loads(zlib.decompress(comp_item)) for comp_item in mini_batch]` – DailyReader Jul 03 '20 at 06:20

0 Answers0