Coder Social home page Coder Social logo

exelban / myo-armband-nn Goto Github PK

View Code? Open in Web Editor NEW
38.0 11.0 24.0 1.06 MB

Gesture recognition using myo armband via neural network (tensorflow library).

License: GNU General Public License v3.0

Python 100.00%
myo myo-armband neural-network tensorflow myo-devices gesture gestures-recognition

myo-armband-nn's Introduction

Archived project. No maintenance.

This project is not maintained anymore and is archived. Feel free to fork and make your own changes if needed. It's because Myo production and sales has officially ended as of Oct 12, 2018.

Thanks to everyone for their valuable feedback.

myo-armband-nn

Gesture recognition using myo armband via neural network (tensorflow library).

Requirement

Library Version
Python ^3.5
Tensorflow ^1.1.0
Numpy ^1.12.0
sklearn ^0.18.1
myo-python ^0.2.2

Collecting data

You can use your own scripts for collecting EMG data from Myo armband. But you need to push 64-value array with data from each sensor.
By default myo-python returns 8-value array from each sensors. Each output return by 2-value array: [datetime, [EMG DATA]].
64 - value array its 8 output from armband. Just put it to one dimension array. So you just need to collect 8 values with gesture from armband (if you read data 10 times/s its not a problem).

In repo are collected dataset from Myo armband collected by me. Dataset contains only 5 gestures:

๐Ÿ‘ - Ok    (1)
โœŠ๏ธ - Fist  (2)
โœŒ๏ธ - Like  (3)
๐Ÿค˜ - Rock  (4)
๐Ÿ–– - Spock (5)

Training network

python3 train.py

75k iteration take about 20 min on GTX 960 or 2h on i3-6100.

Accuracy after ~75k iteration (98.75%):

Loose after ~75k iteration (1.28):

Prediction

Prediction on data from MYO armband

python3 predict.py

You must have installed MYO SDK. Script will return number (0-5) witch represent gesture (0 - relaxed arm).

Prediction on training dataset

python3 predict_train_dataset.py

Example output:

Accuracy on Test-Set: 98.27% (19235 / 19573)
[2438    5    9    6    4   20] (0) Relax
[   4 2652   45    1    3    9] (1) Ok
[   8   44 4989    1    1    9] (2) Fist
[   8    2    2 4152   28   13] (3) Like
[   2    5    6   27 1839    1] (4) Rock
[  14   22   13   21    5 3165] (5) Spock
 (0) (1) (2) (3) (4) (5)

I know that making prediction on training dataset wrong. But i don't have time to make testing dataset(

Model

Fully connected 1 (528 neurons)
ReLu
Fully connected 2 (786 neurons)
ReLu
Fully connected 3 (1248 neurons)
ReLu
Dropout
Softmax_linear

License

GNU General Public License v3.0

myo-armband-nn's People

Contributors

exelban avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

myo-armband-nn's Issues

Failed to restore checkpoint. Help!

Hi! I'm using your solution. I ran the train, and when I run the predict with dataset, it was ok. But when I run the predict (from Myo), it recognizes the archive from checkpoint but failures to restore it. Well... the archive is the same hehe... How can I proceed?

data raw

Why you can have 64 features to use?
Myo just have 8 feature , doesn't it?

Features

Do you get any feature from MYO? I see you use RAW data from armbands

ValueError: attempt to get argmax of an empty sequence

I'm getting an error when I run predict.py

myo.init()
hub = myo.Hub()
start = time.time()
temp = []
try:
    listener = Listener()
    hub.run(listener, 2000)
    while True:
        data = listener.get_emg_data()
        if time.time() - start >= 1:
            response = np.argmax(np.bincount(temp))      -------> ERROR
            print("Predicted gesture: {0}".format(response))
            temp = []
            start = time.time()
        if len(data) > 0:
            tmp = []
            for v in listener.get_emg_data():
                tmp.append(v[1])
            tmp = list(np.stack(tmp).flatten())
            if len(tmp) >= 64:
                pred = sess.run(y_pred_cls, feed_dict={x: np.array([tmp])})
                temp.append(pred[0])
        time.sleep(0.01)
finally:
    sess.close()

TypeError: expected callable or DeviceListener

In predict.py, I get an error when I try to initialize the listener:

import collections
import myo as libmyo
from myo import Hub
import threading
import time
import numpy as np
import tensorflow as tf
from include.model import model


x, y, output, global_step, y_pred_cls = model()

saver = tf.train.Saver()
_SAVE_PATH = "./data/tensorflow_sessions/myo_armband/"
sess = tf.Session()


try:
    print("Trying to restore last checkpoint ...")
    last_chk_path = tf.train.latest_checkpoint(checkpoint_dir=_SAVE_PATH)
    print(last_chk_path)
    saver.restore(sess, save_path=last_chk_path)
    print("Restored checkpoint from:", last_chk_path)
except:
    print("Failed to restore checkpoint. Initializing variables instead.")
    sess.run(tf.global_variables_initializer())


class MyListener(libmyo.DeviceListener):

    def __init__(self, queue_size=8):
        self.lock = threading.Lock()
        self.emg_data_queue = collections.deque(maxlen=queue_size)

    def on_connect(self, device, timestamp, firmware_version):
        device.set_stream_emg(libmyo.StreamEmg.enabled)

    def on_emg_data(self, device, timestamp, emg_data):
        with self.lock:
            self.emg_data_queue.append((timestamp, emg_data))

    def get_emg_data(self):
        with self.lock:
            return list(self.emg_data_queue)


libmyo.init()
hub = Hub()
start = time.time()
temp = []
try:
    listener = MyListener()      
    hub.run(2000, listener)        ---> ERROR
    while True:
        data = listener.get_emg_data()
        if time.time() - start >= 1:
            response = np.argmax(np.bincount(temp))
            print("Predicted gesture: {0}".format(response))
            temp = []
            start = time.time()
        if len(data) > 0:
            tmp = []
            for v in listener.get_emg_data():
                tmp.append(v[1])
            tmp = list(np.stack(tmp).flatten())
            if len(tmp) >= 64:
                pred = sess.run(y_pred_cls, feed_dict={x: np.array([tmp])})
                temp.append(pred[0])
        time.sleep(0.01)
finally:
    sess.close()

hub.run(2000, listener)
File "C:\Python35\lib\site-packages\myo_python-1.0.3-py3.5.egg\myo_ffi.py", line 527, in run
TypeError: expected callable or DeviceListener

What could be the reason?

listener.get_emg_data()

Hi Mr Exelban
when um printing listener.get_emg_data()
i get a very very long list
b

I know that first element is timestamp right (1530437403075359L, [2, 2, -2, -6, -6, -8, -2, -2])
so what for all these lists that is included in one listener.get_emg_data() ?
Thanks in advance

Dataset

Hi!
Could you publish your dataset?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.