NiklasRosenstein / myo-python

Python bindings for the Myo SDK
Other
259 stars 102 forks source link

'Hub' object has no attribute 'shutdown' #85

Closed ryunosuke0723 closed 4 years ago

ryunosuke0723 commented 4 years ago

I tried to implement predit.py but the erro happend. 'Hub' object has no attribute 'shutdown' please tell me how to fix it.

import collections import time import myo import threading 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(myo.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(myo.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)

myo.init(bin_path=r'C:\Users\田澤龍之介\Desktop\myo-sdk-win-0.9.0\bin') hub = myo.Hub() start = time.time() temp = []

try: listener = MyListener() hub.run(2000, listener) 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: hub.shutdown() sess.close()

NiklasRosenstein commented 4 years ago

You're using code that works with an older version of myo-python.

https://github.com/NiklasRosenstein/myo-python/blob/v1.0.4/README.md

image