質問編集履歴

2

追記

2020/01/07 04:19

投稿

apeirogon0813
apeirogon0813

スコア117

test CHANGED
File without changes
test CHANGED
@@ -19,3 +19,385 @@
19
19
  [こちらの記事は](https://github.com/paramiko/paramiko/issues/1317)英語のため参考になりそうでしたあまり理解できずエラーが治りません.
20
20
 
21
21
  ご教示願います.
22
+
23
+
24
+
25
+ コマンドライン上で
26
+
27
+ ```ここに言語を入力
28
+
29
+ ssh a python3.7 test.py
30
+
31
+ ```
32
+
33
+ なお,aは~/.ssh/configに設定されており,ssh-addでパスワードは追加されているものとする
34
+
35
+ このaのホスト上でtest.pyを実行し
36
+
37
+ /Users/xxx/anaconda3/bin/fab -H edge hello
38
+
39
+ を実行し,edgeのホストに接続しようとするとエラーを吐いているようです.
40
+
41
+ --test.py--
42
+
43
+ ```python
44
+
45
+ from __future__ import division
46
+
47
+ import psutil
48
+
49
+ import time
50
+
51
+ import torch
52
+
53
+ import torch.nn as nn
54
+
55
+ from torch.autograd import Variable
56
+
57
+ import numpy as np
58
+
59
+ import cv2
60
+
61
+ from util import *
62
+
63
+ from darknet import Darknet
64
+
65
+ from preprocess import prep_image, inp_to_image
66
+
67
+ import pandas as pd
68
+
69
+ import random
70
+
71
+ import argparse
72
+
73
+ import pickle as pkl
74
+
75
+ import subprocess
76
+
77
+
78
+
79
+
80
+
81
+ def get_test_input(input_dim, CUDA):
82
+
83
+ img = cv2.imread("imgs/messi.jpg")
84
+
85
+ img = cv2.resize(img, (input_dim, input_dim))
86
+
87
+ img_ = img[:,:,::-1].transpose((2,0,1))
88
+
89
+ img_ = img_[np.newaxis,:,:,:]/255.0
90
+
91
+ img_ = torch.from_numpy(img_).float()
92
+
93
+ img_ = Variable(img_)
94
+
95
+
96
+
97
+ if CUDA:
98
+
99
+ img_ = img_.cuda()
100
+
101
+
102
+
103
+ return img_
104
+
105
+
106
+
107
+ def prep_image(img, inp_dim):
108
+
109
+ """
110
+
111
+ Prepare image for inputting to the neural network.
112
+
113
+
114
+
115
+ Returns a Variable
116
+
117
+ """
118
+
119
+
120
+
121
+ orig_im = img
122
+
123
+ dim = orig_im.shape[1], orig_im.shape[0]
124
+
125
+ img = cv2.resize(orig_im, (inp_dim, inp_dim))
126
+
127
+ img_ = img[:,:,::-1].transpose((2,0,1)).copy()
128
+
129
+ img_ = torch.from_numpy(img_).float().div(255.0).unsqueeze(0)
130
+
131
+ return img_, orig_im, dim
132
+
133
+
134
+
135
+ def write(x, img):
136
+
137
+ c1 = tuple(x[1:3].int())
138
+
139
+ c2 = tuple(x[3:5].int())
140
+
141
+ cls = int(x[-1])
142
+
143
+ print(cls)
144
+
145
+ label = "{0}".format(classes[cls])
146
+
147
+ color = random.choice(colors)
148
+
149
+ cv2.rectangle(img, c1, c2,color, 1)
150
+
151
+ t_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_PLAIN, 1 , 1)[0]
152
+
153
+ c2 = c1[0] + t_size[0] + 3, c1[1] + t_size[1] + 4
154
+
155
+ cv2.rectangle(img, c1, c2,color, -1)
156
+
157
+ cv2.putText(img, label, (c1[0], c1[1] + t_size[1] + 4), cv2.FONT_HERSHEY_PLAIN, 1, [225,255,255], 1);
158
+
159
+ if label == 'bottle':
160
+
161
+ cmd = "/Users/xxx/anaconda3/bin/fab -H edge hello"
162
+
163
+ subprocess.call(cmd.split())
164
+
165
+ return img
166
+
167
+
168
+
169
+ def arg_parse():
170
+
171
+ """
172
+
173
+ Parse arguements to the detect module
174
+
175
+
176
+
177
+ """
178
+
179
+
180
+
181
+
182
+
183
+ parser = argparse.ArgumentParser(description='YOLO v3 Cam Demo')
184
+
185
+ parser.add_argument("--confidence", dest = "confidence", help = "Object Confidence to filter predictions", default = 0.25)
186
+
187
+ parser.add_argument("--nms_thresh", dest = "nms_thresh", help = "NMS Threshhold", default = 0.4)
188
+
189
+ parser.add_argument("--reso", dest = 'reso', help =
190
+
191
+ "Input resolution of the network. Increase to increase accuracy. Decrease to increase speed",
192
+
193
+ default = "160", type = str)
194
+
195
+ return parser.parse_args()
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+ if __name__ == '__main__':
204
+
205
+
206
+
207
+ cfgfile = "cfg/yolov3.cfg"
208
+
209
+ weightsfile = "yolov3.weights"
210
+
211
+ num_classes = 80
212
+
213
+ i = 0
214
+
215
+ args = arg_parse()
216
+
217
+ confidence = float(args.confidence)
218
+
219
+ nms_thesh = float(args.nms_thresh)
220
+
221
+ start = 0
222
+
223
+ CUDA = torch.cuda.is_available()
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+ num_classes = 80
234
+
235
+ bbox_attrs = 5 + num_classes
236
+
237
+
238
+
239
+ model = Darknet(cfgfile)
240
+
241
+ model.load_weights(weightsfile)
242
+
243
+
244
+
245
+ model.net_info["height"] = args.reso
246
+
247
+ inp_dim = int(model.net_info["height"])
248
+
249
+
250
+
251
+ assert inp_dim % 32 == 0
252
+
253
+ assert inp_dim > 32
254
+
255
+
256
+
257
+ if CUDA:
258
+
259
+ model.cuda()
260
+
261
+
262
+
263
+ model.eval()
264
+
265
+
266
+
267
+ videofile = 'video.avi'
268
+
269
+
270
+
271
+ cap = cv2.VideoCapture("http://192.168.xxx.xxx:8080/?action=stream")
272
+
273
+
274
+
275
+ assert cap.isOpened(), 'Cannot capture source'
276
+
277
+
278
+
279
+ frames = 0
280
+
281
+ start = time.time()
282
+
283
+ while cap.isOpened():
284
+
285
+
286
+
287
+ ret, frame = cap.read()
288
+
289
+ if ret:
290
+
291
+
292
+
293
+ img, orig_im, dim = prep_image(frame, inp_dim)
294
+
295
+
296
+
297
+ # im_dim = torch.FloatTensor(dim).repeat(1,2)
298
+
299
+
300
+
301
+
302
+
303
+ if CUDA:
304
+
305
+ im_dim = im_dim.cuda()
306
+
307
+ img = img.cuda()
308
+
309
+
310
+
311
+
312
+
313
+ output = model(Variable(img), CUDA)
314
+
315
+ output = write_results(output, confidence, num_classes, nms = True, nms_conf = nms_thesh)
316
+
317
+
318
+
319
+ if type(output) == int:
320
+
321
+ frames += 1
322
+
323
+ print("FPS of the video is {:5.2f}".format( frames / (time.time() - start)))
324
+
325
+ cv2.imshow("frame", orig_im)
326
+
327
+ key = cv2.waitKey(1)
328
+
329
+ if key & 0xFF == ord('q'):
330
+
331
+ break
332
+
333
+ continue
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+ output[:,1:5] = torch.clamp(output[:,1:5], 0.0, float(inp_dim))/inp_dim
342
+
343
+
344
+
345
+ # im_dim = im_dim.repeat(output.size(0), 1)
346
+
347
+ output[:,[1,3]] *= frame.shape[1]
348
+
349
+ output[:,[2,4]] *= frame.shape[0]
350
+
351
+
352
+
353
+
354
+
355
+ classes = load_classes('data/coco.names')
356
+
357
+ colors = pkl.load(open("pallete", "rb"))
358
+
359
+
360
+
361
+ list(map(lambda x: write(x, orig_im), output))
362
+
363
+
364
+
365
+
366
+
367
+ cv2.imshow("frame", orig_im)
368
+
369
+ key = cv2.waitKey(1)
370
+
371
+ if key & 0xFF == ord('q'):
372
+
373
+ break
374
+
375
+ frames += 1
376
+
377
+ print("FPS of the video is {:5.2f}".format( frames / (time.time() - start)))
378
+
379
+
380
+
381
+
382
+
383
+ else:
384
+
385
+ break
386
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+ ```

1

追記

2020/01/07 04:18

投稿

apeirogon0813
apeirogon0813

スコア117

test CHANGED
File without changes
test CHANGED
File without changes