質問編集履歴

1

書式の使い方を誤り,また伝わりにくい質問をしてしまいました.大変,失礼致しました.

2020/08/31 07:40

投稿

tazaryu
tazaryu

スコア6

test CHANGED
@@ -1 +1 @@
1
- attempt to get argmax of an empty sequence argmaxが空ままでエラーが治りません
1
+ attempt to get argmax of an empty sequenceのエラーを直し行列値を取得したいです.
test CHANGED
@@ -1,200 +1,218 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
-
4
-
5
- ここに質問の内容を詳しく書いてください。
6
-
7
- (例)PHP(CakePHP)●●なシステム作っています
3
+ 現在,Pythonのtensorflowprdict.pyという未知の値予測するためのart neural netのコードを書いています
8
-
4
+
9
- ■■な機能を実装中に以下のエラーメッセージ発生しした。
5
+ argmax 値が空というエラーが出ており,行列値が取得できせん.
6
+
7
+
8
+
9
+ 直接,値を入れたりとしたのですが(temp = [1, 1, 2]のように),違うような感じがします.下にコードをを記載させていただきますが、temp = [] という部分がおそらくエラーの原因ではないかと考えております.
10
+
11
+ また,参考に致しましたソースコードは以下のリンクのものです.(predict.py)
12
+
13
+ https://github.com/exelban/myo-armband-nn
14
+
15
+ エラー文は以下のようなものです
16
+
17
+ ValueError: attempt to get argmax of an empty sequence
18
+
19
+ よろしければ,ぜひご教示頂きたいです.何卒,よろしく,お願いいたします.
20
+
21
+
22
+
23
+
10
24
 
11
25
 
12
26
 
13
27
  ### 発生している問題・エラーメッセージ
14
28
 
29
+
30
+
31
+
32
+
15
- argmaxの値が空で取得できません
33
+ エラーメッセージ
16
34
 
17
35
  ```
18
36
 
37
+ Failed to restore checkpoint. Initializing variables instead.
38
+
39
+ Traceback (most recent call last):
40
+
41
+ File "C:\Users\ユーザー名\Desktop\myo-python-1.0.4\myo-armband-nn-master\predict.py", line 57, in <module>
42
+
43
+ response = np.argmax(np.bincount(temp))
44
+
45
+ File "<_arry_function_internals>", line 6, in argmax
46
+
47
+ return_wrapfunc(a, 'argmax', axis=axis, out=out)
48
+
49
+ File "C:\Program Files\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 56, in _wrapfunc
50
+
51
+ return bound(*args, **kwds)
52
+
53
+ ValueError:attempt to get argmax of an empty sequence
54
+
55
+ [Finished in 8.365s]
56
+
57
+ ### 該当のソースコード
58
+
59
+  ``````
60
+
61
+ import collections
62
+
63
+ import myo
64
+
65
+ import threading
66
+
67
+ import time
68
+
69
+ import numpy as np
70
+
71
+ import tensorflow as tf
72
+
73
+ from include.model import model
74
+
75
+
76
+
77
+
78
+
79
+ x, y, output, global_step, y_pred_cls = model()
80
+
81
+
82
+
83
+ saver = tf.train.Saver()
84
+
85
+ _SAVE_PATH = "C:/Users/ユーザー名/Desktop/myo-python-1.0.4/myo-armband-nn-master/data/tensorflow_sessions/myo_armband/"
86
+
87
+ #"./data/tensorflow_sessions/myo_armband/"
88
+
89
+ sess = tf.Session()
90
+
91
+
92
+
93
+
94
+
95
+ try:
96
+
97
+ print("Trying to restore last checkpoint ...")
98
+
99
+ last_chk_path = tf.train.latest_checkpoint(checkpoint_dir=_SAVE_PATH)
100
+
101
+ print(last_chk_path)
102
+
103
+ saver.restore(sess, save_path=last_chk_path)
104
+
105
+ print("Restored checkpoint from:", last_chk_path)
106
+
107
+ except:
108
+
109
+ print("Failed to restore checkpoint. Initializing variables instead.")
110
+
111
+ sess.run(tf.global_variables_initializer())
112
+
113
+
114
+
115
+
116
+
117
+ class MyListener(myo.DeviceListener):
118
+
119
+
120
+
121
+ def __init__(self, queue_size=8):
122
+
123
+ self.lock = threading.Lock()
124
+
125
+ self.emg_data_queue = collections.deque(maxlen=queue_size)
126
+
127
+
128
+
129
+ def on_connect(self, device, timestamp, firmware_version):
130
+
131
+ device.set_stream_emg(myo.StreamEmg.enabled)
132
+
133
+
134
+
135
+ def on_emg_data(self, device, timestamp, emg_data):
136
+
137
+ with self.lock:
138
+
139
+ self.emg_data_queue.append((timestamp, emg_data))
140
+
141
+
142
+
143
+ def get_emg_data(self):
144
+
145
+ with self.lock:
146
+
147
+ return list(self.emg_data_queue)
148
+
149
+
150
+
151
+
152
+
153
+ myo.init('C:/Users/ユーザー名/Desktop/myo-python-1.0.4/myo64.dll')
154
+
155
+ hub = myo.Hub()
156
+
157
+ start = time.time()
158
+
159
+ temp = [] ☚ ここではないかと思います.
160
+
161
+ try:
162
+
163
+ listener = MyListener()
164
+
165
+ hub.run(listener, 2000)
166
+
167
+ while True:
168
+
169
+ data = listener.get_emg_data()
170
+
171
+ if time.time() - start >= 1:
172
+
173
+ response = np.argmax(np.bincount(temp))
174
+
175
+ print("Predicted gesture: {0}".format(response))
176
+
177
+ temp = []
178
+
179
+ start = time.time()
180
+
181
+ if len(data) > 0:
182
+
19
- エラーメッセージ
183
+ tmp = []
184
+
185
+ for v in listener.get_emg_data():
186
+
187
+ tmp.append(v[1])
188
+
189
+ tmp = list(np.stack(tmp).flatten())
190
+
191
+ if len(tmp) >= 64:
192
+
193
+ pred = sess.run(y_pred_cls, feed_dict={x: np.array([tmp])})
194
+
195
+ temp.append(pred[0])
196
+
197
+ time.sleep(0.01)
198
+
199
+ finally:
200
+
201
+ sess.close()
20
202
 
21
203
  ```
22
204
 
23
- attempt to get argmax of an empty sequence
205
+
24
-
25
- ### 該当のソースコード
206
+
26
-
27
-
28
-
29
- ```ここに言語名を入力 python
207
+
30
-
31
- ソースコード
208
+
32
-
33
- ``````python
209
+
34
-
35
- コード
36
-
37
- ```
38
-
39
- # -*- coding: utf-8 -*-
40
-
41
- """
42
-
43
- Created on Tue Aug 25 14:53:03 2020
44
-
45
-
46
-
47
- @author: tazawa
48
-
49
- """
50
-
51
-
52
-
53
- import collections
54
-
55
- import myo
56
-
57
- import threading
58
-
59
- import time
60
-
61
- import numpy as np
62
-
63
- import tensorflow as tf
64
-
65
- from include.model import model
66
-
67
-
68
-
69
-
70
-
71
- x, y, output, global_step, y_pred_cls = model()
72
-
73
-
74
-
75
- saver = tf.train.Saver()
76
-
77
- _SAVE_PATH = "./data/tensorflow_sessions/myo_armband/"
78
-
79
- sess = tf.Session()
80
-
81
-
82
-
83
-
84
-
85
- try:
86
-
87
- print("Trying to restore last checkpoint ...")
88
-
89
- last_chk_path = tf.train.latest_checkpoint(checkpoint_dir=_SAVE_PATH)
90
-
91
- print(last_chk_path)
92
-
93
- saver.restore(sess, save_path=last_chk_path)
94
-
95
- print("Restored checkpoint from:", last_chk_path)
96
-
97
- except:
98
-
99
- print("Failed to restore checkpoint. Initializing variables instead.")
100
-
101
- sess.run(tf.global_variables_initializer())
102
-
103
-
104
-
105
-
106
-
107
- class MyListener(myo.DeviceListener):
108
-
109
-
110
-
111
- def __init__(self, queue_size=8):
112
-
113
- self.lock = threading.Lock()
114
-
115
- self.emg_data_queue = collections.deque(maxlen=queue_size)
116
-
117
-
118
-
119
- def on_connect(self, device, timestamp, firmware_version):
120
-
121
- device.set_stream_emg(myo.StreamEmg.enabled)
122
-
123
-
124
-
125
- def on_emg_data(self, device, timestamp, emg_data):
126
-
127
- with self.lock:
128
-
129
- self.emg_data_queue.append((timestamp, emg_data))
130
-
131
-
132
-
133
- def get_emg_data(self):
134
-
135
- with self.lock:
136
-
137
- return list(self.emg_data_queue)
138
-
139
-
140
-
141
- myo.init(bin_path=r'C:\Users\田澤龍之介\Desktop\myo-sdk-win-0.9.0\bin')
142
-
143
- hub = myo.Hub()
144
-
145
- start = time.time()
146
-
147
- temp = []      # ☚ここではないかと
148
-
149
- try:
150
-
151
- listener = MyListener()
152
-
153
- hub.run(listener, 2000)
154
-
155
- while True:
156
-
157
- data = listener.get_emg_data()
158
-
159
- if time.time() - start >= 1:
160
-
161
- response = np.argmax(np.bincount(temp))
162
-
163
- print("Predicted gesture: {0}".format(response))
164
-
165
- temp = []
166
-
167
- start = time.time()
168
-
169
- if len(data) > 0:
170
-
171
- tmp = []
172
-
173
- for v in listener.get_emg_data():
174
-
175
- tmp.append(v[1])
176
-
177
- tmp = list(np.stack(tmp).flatten())
178
-
179
- if len(tmp) >= 64:
180
-
181
- pred = sess.run(y_pred_cls, feed_dict={x: np.array([tmp])})
182
-
183
- temp.append(pred[0])
184
-
185
- time.sleep(0.01)
186
-
187
- finally:
188
-
189
- #hub.shutdown()
190
-
191
- sess.close()
192
210
 
193
211
  ### 試したこと
194
212
 
195
213
  おそらくtemp[]の表現の仕方が間違っていると推測し,直接行列値を代入などしましたが,うまくいきませんでした.
196
214
 
197
- ここに問題に対して試したことを記載してください。
215
+
198
216
 
199
217
 
200
218