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

error in Python training.py #2

Open
mshaub opened this issue Jun 11, 2020 · 11 comments
Open

error in Python training.py #2

mshaub opened this issue Jun 11, 2020 · 11 comments

Comments

@mshaub
Copy link

mshaub commented Jun 11, 2020

I've finally gotten a working board assembled, tested, and working (sending serial signals out with ball bounces!) and a projector setup.

I'm running python 2.7.10 and installed the pySerial library and hoped that was all I needed to proceed. I can get through all the training bounces for one side, but then get the following error.

Traceback (most recent call last):
File "training.py", line 433, in
[xCoeff1, xCoeff2, xCoeff3, xCoeff4, yCoeff1, yCoeff2, yCoeff3, yCoeff4] = train(arduino_serial, False)
File "training.py", line 274, in train
xCoeff1 = M1inv * x
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/matrixlib/defmatrix.py", line 347, in rmul
return N.dot(other, self)
ValueError: matrices are not aligned

I printed the matrices (x and M1inv) and they do look quite different. I would love any help with matrix math and code that's over my head. Thanks!

@xiaosquared
Copy link
Owner

xiaosquared commented Jun 12, 2020 via email

@mshaub
Copy link
Author

mshaub commented Jun 12, 2020

I did verify that I have those libraries
Python Version: 2.7.10
Numpy version: 1.8.0rc1
Scipy version: 0.13.0b1
Any other theories about this issue? Would it help if I posted how the matrices are formatted? like I said they look quite different to me. Thank you!!

@xiaosquared
Copy link
Owner

xiaosquared commented Jun 12, 2020 via email

@mshaub
Copy link
Author

mshaub commented Jun 23, 2020

I tried your suggestion, had to switch to a Windows computer but saw a very similar issue. I tried the training on both sides, then each side separately as you suggested. Please see the errors posted about the "misalignment" of dot products. interesting that it's slightly different between the left and right sides. I really appreciate your help trying to make this work! I have several updates/improvements to share when I'm sure I've got things working, a circuit board design and a processing sketch with the "Corner Pin" library allowing easy alignment of projected image and table.

Training Both Sides (b):
(10L, 53L)
(100L, 1L)
Traceback (most recent call last):
File "training-win10.py", line 438, in
[xCoeff1, xCoeff2, xCoeff3, xCoeff4, yCoeff1, yCoeff2, yCoeff3, yCoeff4] = train(arduino_serial, False)
File "training-win10.py", line 279, in train
xCoeff1 = M1inv * x
File "C:\Users\Michael\AppData\Roaming\Python\Python27\site-packages\numpy\matrixlib\defmatrix.py", line 226, in rmul
return N.dot(other, self)
ValueError: shapes (10,53) and (100,1) not aligned: 53 (dim 1) != 100 (dim 0)

Training Sides Separately
Training 1 Side (l):

(10L, 43L)
(100L, 1L)
Traceback (most recent call last):
File "training-win10.py", line 438, in
[xCoeff1, xCoeff2, xCoeff3, xCoeff4, yCoeff1, yCoeff2, yCoeff3, yCoeff4] = train(arduino_serial, False)
File "training-win10.py", line 279, in train
xCoeff1 = M1inv * x
File "C:\Users\Michael\AppData\Roaming\Python\Python27\site-packages\numpy\matrixlib\defmatrix.py", line 226, in rmul
return N.dot(other, self)
ValueError: shapes (10,43) and (100,1) not aligned: 43 (dim 1) != 100 (dim 0)

Right Side Only (r):
(10L, 51L)
(100L, 1L)
Traceback (most recent call last):
File "training-win10.py", line 442, in
[xCoeff1, xCoeff2, xCoeff3, xCoeff4, yCoeff1, yCoeff2, yCoeff3, yCoeff4] = train(arduino_serial, True)
File "training-win10.py", line 279, in train
xCoeff1 = M1inv * x
File "C:\Users\Michael\AppData\Roaming\Python\Python27\site-packages\numpy\matrixlib\defmatrix.py", line 226, in rmul
return N.dot(other, self)
ValueError: shapes (10,51) and (100,1) not aligned: 51 (dim 1) != 100 (dim 0)

@mbernst
Copy link

mbernst commented Jun 27, 2020

@mshaub, are you getting an intermediate file hitdata-left.txt and hitdata-right.txt in the directory where you're running the training? If so, can you share them here? I can't promise a solution, but I think debugging this would require seeing what's getting recorded there.

@mshaub
Copy link
Author

mshaub commented Jun 29, 2020

hitdata-right.txt
hitdata-left.txt
Thanks for your reply @mbernst ! I did get some files when running the training. I did both sides separately just to be sure I got a file for each, please see the attached. I didn't follow the projected pattern when running the training this time, it didn't seem to matter if the data was "real" so I went quickly dropping the ball close to where I was sitting. Do let me know if that's a problem, I can certainly run this again the "right way."
I don't know if it matters, but on both sides today I got this error:

ValueError: shapes (10,48) and (100,1) not aligned: 48 (dim 1) != 100 (dim 0)

whereas in the last run the error was:

ValueError: shapes (10,51) and (100,1) not aligned: 51 (dim 1) != 100 (dim 0)

I greatly appreciate any thoughts you have on how I can make this work. I feel like I'm so close!

@xiaosquared
Copy link
Owner

xiaosquared commented Jun 29, 2020 via email

@mshaub
Copy link
Author

mshaub commented Jul 2, 2020

hello! I've finally gotten my projector setup again and rerun the calibration program the "right way." I'm still getting the same errors but with the "real" data maybe you are more able to see the issues.
on the left side the error this time was:
return N.dot(other, self)
ValueError: shapes (10,55) and (100,1) not aligned: 55 (dim 1) != 100 (dim 0)
on the right side the error was:
return N.dot(other, self)
ValueError: shapes (10,53) and (100,1) not aligned: 53 (dim 1) != 100 (dim 0)

please see the attached txt files generated despite the errors (I had to do the 2 sides separately). I'm very hopeful you have some suggestions of what I might try next! Thank you so much for your help with this.
hitdata-left.txt
hitdata-right.txt

@mbernst
Copy link

mbernst commented Jul 4, 2020

Here is what I think is going on, without having access to a table myself. Looking at training.py, it's clear that you're supposed to get 100 training points out of the exercise, but you're getting fewer, like in the range of 45-55 each time — that's why the shape is, for example, around (10,55) instead of (10,100). It looks like for each of the 20 training points, you do five repetitions (5*20=100). Notice that it calls parse_hit on each of the examples to generate diffs, but then asks if diffs is not None and only adds to the list of 100 hits if so. So if diffs is None, you'd be getting fewer than 100 points in your array.

Then I notice that parse_hit returns None if one of the sensors isn't returning a good output. You'd notice if you're seeing it print "none" to the console when you're dropping the training points instead of the hit data "one" "two" "three" "four".

The most likely cause of all this is that one of your sensors is intermittently malfunctioning. You'd be able to tell if you look at your console the line above any time it prints "none" to the console to see what the raw sensor inputs show. I'm looking at the top of the parse_hit function where it prints its raw sensor input before attempting to parse it:

print(line)

@mshaub
Copy link
Author

mshaub commented Jul 4, 2020

Awesome! I hope you’re right and it’s just a loose connection or something. I’m away from my ping pong table at the moment but I’ll test and see if any of the sensors are returning “none” as soon as I can. I’ll certainly report back. Thanks for your help and detective work!

@mshaub
Copy link
Author

mshaub commented Jul 7, 2020

You were right, 2 of my 8 sensors aren’t reporting anything. I swapped the cables with ones that were working and have established that the piezos and wiring is fine so it’s something in the circuit. I can’t see any issue with them, but will try to figure out how to repair them and try this again!

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

3 participants