nickgillian / grt

gesture recognition toolkit
862 stars 284 forks source link

PyGRT: Python bindings for GRT via SWIG #151

Closed royshil closed 5 years ago

royshil commented 6 years ago

This implements a Python API for GRT.

Enables writing Python code like this:

    print("Loading dataset...")
    training_data = GRT.ClassificationData()
    training_data.load(filename)
    print("Data Loaded")

    # Print out some stats about the training data
    training_data.printStats()

    print("Splitting data into training/test split...")
    test_data = training_data.split(80)

    # Create a new Gesture Recognition Pipeline
    pipeline = GRT.GestureRecognitionPipeline()

    # Add a KNN classifier to the pipeline with a K value of 10
    knn = GRT.KNN(10)
    pipeline.setClassifier(knn)

    print("Training model...")
    pipeline.train(training_data)

I started with the examples to get a good API coverage.

The Travis build fails because the MLPRegressor unit test fail, i.e. the problem is not with this code, but GRT itself.

alexszameitat commented 5 years ago

Hey there Roy,

I was trying to use your PyGRT, but got stuck trying to build up everything properly. I kindly wanted to ask whether you could help me out. After I build the binaries with CMake into the tmp folder (just like described in the README from Nick ... I'm on Windows), I then open the ALL_BUILD.vcxproj (in that tmp folder) in Visual Studio and build/compile ALL_BUILD.

This doesn't build correctly, but it does build the python package. In the python package I can also find the GRT.py, but not the GRT_.so. When I create a new project in that build/tmp/python directory it works out to import the GRT but if I compile the hello_world_example.py... I'll get the following error:


"C:\Program Files\Python37\python.exe" "D:/szameitat/Documents/Programming Projects/8_Python/GRT/tmp/try2/grt-roy.pygrt/build/tmp/python/hello_world_example.py" Traceback (most recent call last): File "D:\szameitat\Documents\Programming Projects\8_Python\GRT\tmp\try2\grt-roy.pygrt\build\tmp\python\GRT.py", line 14, in swig_import_helper return importlib.import_module(mname) File "C:\Program Files\Python37\lib\importlib__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 965, in _find_and_load_unlocked ModuleNotFoundError: No module named '_GRT'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:/szameitat/Documents/Programming Projects/8_Python/GRT/tmp/try2/grt-roy.pygrt/build/tmp/python/hello_world_example.py", line 1, in import GRT File "D:\szameitat\Documents\Programming Projects\8_Python\GRT\tmp\try2\grt-roy.pygrt\build\tmp\python\GRT.py", line 17, in _GRT = swig_import_helper() File "D:\szameitat\Documents\Programming Projects\8_Python\GRT\tmp\try2\grt-roy.pygrt\build\tmp\python\GRT.py", line 16, in swig_import_helper return importlib.import_module('_GRT') File "C:\Program Files\Python37\lib\importlib__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) ModuleNotFoundError: No module named '_GRT'

Process finished with exit code 1

Also the Error List from Visual Studio after trying to build "ALL_BUILD": ErrorList_VS_ALLBUILD.xlsx

I'd be glad if you or anyone else could help!

royshil commented 5 years ago

I won't be able to help with a Windows build. One thing I'd expect is that there will not be a GRT.so output file rather a GRT.dll (using MSVS). Anyway I'd start with fixing the build of the library itself, and see that it completes without errors. The Python package is almost just garnish.

nickgillian commented 5 years ago

This is great, thanks for the contribution. Apologies that this took so long to merge.