kendricktan/endless-nn

TypeError when running collect.py

Opened this issue · 9 comments

Hi Kendrick, this is a really cool project!

Running python collect.py results in the following error:

Traceback (most recent call last):
  File "collect.py", line 35, in <module>
    eye.tune_roi()
  File "/home/mice/development/endless-nn/eyes.py", line 56, in tune_roi
    img = screeny.screenshot(region=tuple(self._roi))
  File "/home/mice/development/endless-nn/screeny.py", line 30, in screenshot
    bmp = wx.Bitmap(w, h)
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/_gdi.py", line 639, in __init__
    _gdi_.Bitmap_swiginit(self,_gdi_.new_Bitmap(*args, **kwargs))
TypeError: String or Unicode type required

I got around this by replacing bmp = wx.Bitmap(w, h) with bmp = wx.EmptyBitmap(w, h) in screeny.py .

I like this idea!
BUT...
Running autonomous.py or collect.py and this happens:

C:\Users%username%\Desktop\endless-nn-master>python collect.py
[X] Press "q" to quit
[!] Initializing...
[!] Ensure that the game window is initialized before proceeding
[!] Please click the top left and bottom right of the game window, and leave some margins
[E] Mouse Event: click, x: 54, y: 181
[E] Mouse Event: click, x: 440, y: 893
Traceback (most recent call last):
File "collect.py", line 34, in
eye.tune_roi()
File "C:\Users...\Desktop\endless-nn-master\eyes.py", line 65, in tune_roi
cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
ValueError: too many values to unpack

runtime error R6031

  • Attempt to initialize the CRT more than once.
    This indicates a bug in your application.

I replaced the bmp = wx.Bitmap(w, h) with bmp = wx.EmptyBitmap(w, h) in screeny.py and ended up getting this error instead.
have you any ways to fix this error? thanks

Woah, completely missed this issue. Apologies.

Unfortunately I'm not able to reproduce this error 😢 and can't debug it from here

My intuition tells me thats something to do with wx python as it requires some lower level libraries.

What OS are you running? And what version is it?

Hey! thanks for answering, I forgot completely to tell you my OS haha. I run Windows 10, 64bit, version 10.0.10586 Build 10586. I use the Python 2.7 :)

Hi, same problem here, Win10, 64bit and python 2.7, any idea?

I managed to resolve the issue commented by @walamo15 regarding

cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
ValueError: too many values to unpack

Here are the steps:

  1. Open/Edit eyes.py
  2. On def tune_roi(self): function, replace
    cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    with
    _, cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  3. On def roi_to_grid(self): function, replace
    cnts, _ = cv2.findContours(masked_player.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    with
    _, cnts, _ = cv2.findContours(masked_player.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

However, in terms of saving the collected data, how can I perform that? How can I proceed?

Here's the screenshot:
capture

Hope that @kendricktan will have fix/resolve to this.

@lemoncalamitous run train.py to train your NN on the collected data, once that's done run autonomous.py to let the trained NN play the game.

To the guys who are still interested on this Python bot, I manage to make this work on my platform (Windows 10, x64, Python 2.7, Anaconda (Prompt)). Sorry @kendricktan for the email :octocat:

  1. Make sure you use the latest code commits.
  2. Install all Python package dependencies (PyUserInput, wxPython, OpenCV, and others included on requirements.txt). If running the Python script returns an error related to package dependency, just install it 🔨
  3. On screeny.py, there will be no changes. It should be
# Construct a bitmap
bmp = wx.Bitmap(w, h)
  1. On eyes.py, replace
# Find contours of the image
cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

by

# Find contours of the image
_, cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  1. Still on eyes.py, replace
# Player thresholding
# Also moprhological transformation to reduce noise
masked_player = cv2.inRange(img, self._lower_player, self._upper_player)
masked_player = cv2.morphologyEx(masked_player, cv2.MORPH_OPEN, self._kernel)
cnts, _ = cv2.findContours(masked_player.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

by

# Player thresholding
# Also moprhological transformation to reduce noise
masked_player = cv2.inRange(img, self._lower_player, self._upper_player)
masked_player = cv2.morphologyEx(masked_player, cv2.MORPH_OPEN, self._kernel)
_, cnts, _ = cv2.findContours(masked_player.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  1. Run Endless Lake on Messenger.com (on your browser). Wait for it to initialize (loading). Then run python collect.py on Anaconda prompt. Press C on your keyboard before playing the game.
    After playing 1 round, press Q on your keyboard to save your data.
    1
    Play Endless Lake several times to collect enough data.
    2

  2. Run python train.py on Anaconda Prompt.

  3. Run python autonomous.py on Anaconda Prompt, just like what you've done on python collect.py. Verify if the bot is working.

Notes:
I still don't know when will I collect the training data (Press c to continue), in which of the three scenes below:
4
5
6

@kendricktan kindly confirm on the above. Thanks!

Cool;)