質問編集履歴
4
コードに関して補足しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -86,7 +86,7 @@
|
|
86
86
|
|
87
87
|
input_shape=(300, 300, 3)
|
88
88
|
|
89
|
-
model = SSD(input_shape, num_classes=NUM_CLASSES)
|
89
|
+
model = SSD300(input_shape, num_classes=NUM_CLASSES)
|
90
90
|
|
91
91
|
|
92
92
|
|
3
コードに関して補足しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,6 +20,196 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
+
```python
|
24
|
+
|
25
|
+
import cv2
|
26
|
+
|
27
|
+
import keras
|
28
|
+
|
29
|
+
from keras.applications.imagenet_utils import preprocess_input
|
30
|
+
|
31
|
+
from keras.backend.tensorflow_backend import set_session
|
32
|
+
|
33
|
+
from keras.models import Model
|
34
|
+
|
35
|
+
from keras.preprocessing import image
|
36
|
+
|
37
|
+
import matplotlib.pyplot as plt
|
38
|
+
|
39
|
+
import numpy as np
|
40
|
+
|
41
|
+
from scipy.misc import imread
|
42
|
+
|
43
|
+
import tensorflow as tf
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
from ssd import SSD300
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
from ssd_utils import BBoxUtility
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
#%matplotlib inline
|
56
|
+
|
57
|
+
plt.rcParams['figure.figsize'] = (8, 8)
|
58
|
+
|
59
|
+
plt.rcParams['image.interpolation'] = 'nearest'
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
np.set_printoptions(suppress=True)
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
#config = tf.ConfigProto()
|
68
|
+
|
69
|
+
#config.gpu_options.per_process_gpu_memory_fraction = 0.9
|
70
|
+
|
71
|
+
#set_session(tf.Session(config=config))
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
voc_classes = ['Aeroplane', 'Bicycle', 'Bird', 'Boat', 'Bottle',
|
76
|
+
|
77
|
+
'Bus', 'Car', 'Cat', 'Chair', 'Cow', 'Diningtable',
|
78
|
+
|
79
|
+
'Dog', 'Horse','Motorbike', 'Person', 'Pottedplant',
|
80
|
+
|
81
|
+
'Sheep', 'Sofa', 'Train', 'Tvmonitor']
|
82
|
+
|
83
|
+
NUM_CLASSES = len(voc_classes) + 1
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
input_shape=(300, 300, 3)
|
88
|
+
|
89
|
+
model = SSD(input_shape, num_classes=NUM_CLASSES)
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
model.load_weights('weights_SSD300.hdf5', by_name=True)
|
94
|
+
|
95
|
+
bbox_util = BBoxUtility(NUM_CLASSES)
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
inputs = []
|
100
|
+
|
101
|
+
images = []
|
102
|
+
|
103
|
+
img_path = './1.jpg'
|
104
|
+
|
105
|
+
img = image.load_img(img_path, target_size=(300, 300))
|
106
|
+
|
107
|
+
img = image.img_to_array(img)
|
108
|
+
|
109
|
+
images.append(imread(img_path))
|
110
|
+
|
111
|
+
inputs.append(img.copy())
|
112
|
+
|
113
|
+
inputs = preprocess_input(np.array(inputs))
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
preds = model.predict(inputs, batch_size=1, verbose=1)
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
results = bbox_util.detection_out(preds)
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
#%%time
|
126
|
+
|
127
|
+
a = model.predict(inputs, batch_size=1)
|
128
|
+
|
129
|
+
b = bbox_util.detection_out(preds)
|
130
|
+
|
131
|
+
for i, img in enumerate(images):
|
132
|
+
|
133
|
+
# Parse the outputs.
|
134
|
+
|
135
|
+
det_label = results[i][:, 0]
|
136
|
+
|
137
|
+
det_conf = results[i][:, 1]
|
138
|
+
|
139
|
+
det_xmin = results[i][:, 2]
|
140
|
+
|
141
|
+
det_ymin = results[i][:, 3]
|
142
|
+
|
143
|
+
det_xmax = results[i][:, 4]
|
144
|
+
|
145
|
+
det_ymax = results[i][:, 5]
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
# Get detections with confidence higher than 0.6.
|
150
|
+
|
151
|
+
top_indices = [i for i, conf in enumerate(det_conf) if conf >= 0.6]
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
top_conf = det_conf[top_indices]
|
156
|
+
|
157
|
+
top_label_indices = det_label[top_indices].tolist()
|
158
|
+
|
159
|
+
top_xmin = det_xmin[top_indices]
|
160
|
+
|
161
|
+
top_ymin = det_ymin[top_indices]
|
162
|
+
|
163
|
+
top_xmax = det_xmax[top_indices]
|
164
|
+
|
165
|
+
top_ymax = det_ymax[top_indices]
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
colors = plt.cm.hsv(np.linspace(0, 1, 21)).tolist()
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
plt.imshow(img / 255.)
|
174
|
+
|
175
|
+
currentAxis = plt.gca()
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
for i in range(top_conf.shape[0]):
|
180
|
+
|
181
|
+
xmin = int(round(top_xmin[i] * img.shape[1]))
|
182
|
+
|
183
|
+
ymin = int(round(top_ymin[i] * img.shape[0]))
|
184
|
+
|
185
|
+
xmax = int(round(top_xmax[i] * img.shape[1]))
|
186
|
+
|
187
|
+
ymax = int(round(top_ymax[i] * img.shape[0]))
|
188
|
+
|
189
|
+
score = top_conf[i]
|
190
|
+
|
191
|
+
label = int(top_label_indices[i])
|
192
|
+
|
193
|
+
label_name = voc_classes[label - 1]
|
194
|
+
|
195
|
+
display_txt = '{:0.2f}, {}'.format(score, label_name)
|
196
|
+
|
197
|
+
coords = (xmin, ymin), xmax-xmin+1, ymax-ymin+1
|
198
|
+
|
199
|
+
color = colors[label]
|
200
|
+
|
201
|
+
currentAxis.add_patch(plt.Rectangle(*coords, fill=False, edgecolor=color, linewidth=2))
|
202
|
+
|
203
|
+
currentAxis.text(xmin, ymin, display_txt, bbox={'facecolor':color, 'alpha':0.5})
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
plt.show()
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
```
|
212
|
+
|
23
213
|
|
24
214
|
|
25
215
|
### 試したこと
|
@@ -36,6 +226,8 @@
|
|
36
226
|
|
37
227
|
|
38
228
|
|
229
|
+
python=3.5.3
|
230
|
+
|
39
231
|
Tensorflow=1.11.0
|
40
232
|
|
41
233
|
Keras=2.2.4
|
@@ -62,9 +254,9 @@
|
|
62
254
|
|
63
255
|
SSD.ipynbの各セルをテキストファイルにコピーペーストしてSSD.pyとし、実行しました。
|
64
256
|
|
257
|
+
上記のコードがSSD.pyです。
|
258
|
+
|
65
|
-
画像
|
259
|
+
画像はSSD.pyと同じディレクトリに置いています。
|
66
|
-
|
67
|
-
%matplotlib inlineはコメントアウトしました。
|
68
260
|
|
69
261
|
|
70
262
|
|
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,4 +50,22 @@
|
|
50
50
|
|
51
51
|
エラーは”パスエラー”で全文です。
|
52
52
|
|
53
|
+
|
54
|
+
|
55
|
+
https://github.com/rykov8/ssd_keras?files=1
|
56
|
+
|
57
|
+
上記のコードを
|
58
|
+
|
59
|
+
https://qiita.com/ttskng/items/4f67f4bbda2568229956
|
60
|
+
|
61
|
+
に従って変更し、
|
62
|
+
|
63
|
+
SSD.ipynbの各セルをテキストファイルにコピーペーストしてSSD.pyとし、実行しました。
|
64
|
+
|
65
|
+
画像(1.jpg)はSSD.pyと同ディレクトリに配置し、パスは(‘./1.jpg’)としています。
|
66
|
+
|
67
|
+
%matplotlib inlineはコメントアウトしました。
|
68
|
+
|
69
|
+
|
70
|
+
|
53
71
|
よろしくお願いいたします。
|
1
エラー内容について補足しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -45,3 +45,9 @@
|
|
45
45
|
model.predict()でエラーが返されることは
|
46
46
|
|
47
47
|
ソースコードをコメントアウトしながら調べました。
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
エラーは”パスエラー”で全文です。
|
52
|
+
|
53
|
+
よろしくお願いいたします。
|