質問編集履歴

3

改善

2020/10/17 09:56

投稿

kusegasugoi0221
kusegasugoi0221

スコア11

test CHANGED
File without changes
test CHANGED
@@ -50,7 +50,7 @@
50
50
 
51
51
 
52
52
 
53
- # 学習用の画像ファイルの格納先(FEのT1~T8,WのT1~T8)
53
+ # 学習用の画像ファイルの格納先
54
54
 
55
55
  LOAD_TRAIN_IMG1S_PATH = './preprocess_images/case3/train/T1-FE/*'
56
56
 
@@ -190,7 +190,7 @@
190
190
 
191
191
 
192
192
 
193
- # 正解ラベルを生成imgs.番号でラベルを決める
193
+ # 正解ラベルを生成imgs
194
194
 
195
195
  '''
196
196
 
@@ -232,47 +232,7 @@
232
232
 
233
233
 
234
234
 
235
- '''
235
+
236
-
237
-
238
-
239
- #2パターン目:T1~T8を判別
240
-
241
- labels1 = np.full(len(load_img1_paths), 1, np.int32)
242
-
243
- labels2 = np.full(len(load_img2_paths), 2, np.int32)
244
-
245
- labels3 = np.full(len(load_img3_paths), 3, np.int32)
246
-
247
- labels4 = np.full(len(load_img4_paths), 4, np.int32)
248
-
249
- labels5 = np.full(len(load_img5_paths), 5, np.int32)
250
-
251
- labels6 = np.full(len(load_img6_paths), 6, np.int32)
252
-
253
- labels7 = np.full(len(load_img7_paths), 7, np.int32)
254
-
255
- labels8 = np.full(len(load_img8_paths), 8, np.int32)
256
-
257
-
258
-
259
- labels9 = np.full(len(load_img9_paths), 1, np.int32)
260
-
261
- labels10 = np.full(len(load_img10_paths), 2, np.int32)
262
-
263
- labels11 = np.full(len(load_img11_paths), 3, np.int32)
264
-
265
- labels12 = np.full(len(load_img12_paths), 4, np.int32)
266
-
267
- labels13 = np.full(len(load_img13_paths), 5, np.int32)
268
-
269
- labels14 = np.full(len(load_img14_paths), 6, np.int32)
270
-
271
- labels15 = np.full(len(load_img15_paths), 7, np.int32)
272
-
273
- labels16 = np.full(len(load_img16_paths), 8, np.int32)
274
-
275
-
276
236
 
277
237
 
278
238
 

2

改善

2020/10/17 09:56

投稿

kusegasugoi0221
kusegasugoi0221

スコア11

test CHANGED
File without changes
test CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  # 特徴量抽出器
8
8
 
9
+ # 特徴量抽出器
10
+
9
11
  def create_images_array(load_img_paths):
10
12
 
11
13
  imgs=[]
@@ -48,19 +50,47 @@
48
50
 
49
51
 
50
52
 
51
- # 学習用の画像ファイルの格納先
53
+ # 学習用の画像ファイルの格納先(FEのT1~T8,WのT1~T8)
52
-
54
+
53
- LOAD_TRAIN_IMG1S_PATH = './sample/case3/train/T1-FE/*'
55
+ LOAD_TRAIN_IMG1S_PATH = './preprocess_images/case3/train/T1-FE/*'
54
-
56
+
55
- LOAD_TRAIN_IMG2S_PATH = './sample/case3/train/T2-FE/*'
57
+ LOAD_TRAIN_IMG2S_PATH = './preprocess_images/case3/train/T2-FE/*'
56
-
58
+
57
- LOAD_TRAIN_IMG3S_PATH = './sample/case3/train/T3-FE/*'
59
+ LOAD_TRAIN_IMG3S_PATH = './preprocess_images/case3/train/T3-FE/*'
60
+
58
-
61
+ LOAD_TRAIN_IMG4S_PATH = './preprocess_images/case3/train/T4-FE/*'
62
+
59
-
63
+ LOAD_TRAIN_IMG5S_PATH = './preprocess_images/case3/train/T5-FE/*'
64
+
65
+ LOAD_TRAIN_IMG6S_PATH = './preprocess_images/case3/train/T6-FE/*'
66
+
67
+ LOAD_TRAIN_IMG7S_PATH = './preprocess_images/case3/train/T7-FE/*'
68
+
69
+ LOAD_TRAIN_IMG8S_PATH = './preprocess_images/case3/train/T8-FE/*'
70
+
71
+
72
+
73
+ LOAD_TRAIN_IMG9S_PATH = './preprocess_images/case3/train/T1-W/*'
74
+
75
+ LOAD_TRAIN_IMG10S_PATH = './preprocess_images/case3/train/T2-W/*'
76
+
77
+ LOAD_TRAIN_IMG11S_PATH = './preprocess_images/case3/train/T3-W/*'
78
+
79
+ LOAD_TRAIN_IMG12S_PATH = './preprocess_images/case3/train/T4-W/*'
80
+
81
+ LOAD_TRAIN_IMG13S_PATH = './preprocess_images/case3/train/T5-W/*'
82
+
83
+ LOAD_TRAIN_IMG14S_PATH = './preprocess_images/case3/train/T6-W/*'
84
+
85
+ LOAD_TRAIN_IMG15S_PATH = './preprocess_images/case3/train/T7-W/*'
86
+
87
+ LOAD_TRAIN_IMG16S_PATH = './preprocess_images/case3/train/T8-W/*'
60
88
 
61
89
 
62
90
 
63
-
91
+
92
+
93
+
64
94
 
65
95
  # 作成した学習モデルの保存先
66
96
 
@@ -80,9 +110,41 @@
80
110
 
81
111
  load_img3_paths = glob.glob(LOAD_TRAIN_IMG3S_PATH)
82
112
 
83
-
113
+ load_img4_paths = glob.glob(LOAD_TRAIN_IMG4S_PATH)
114
+
84
-
115
+ load_img5_paths = glob.glob(LOAD_TRAIN_IMG5S_PATH)
116
+
85
-
117
+ load_img6_paths = glob.glob(LOAD_TRAIN_IMG6S_PATH)
118
+
119
+ load_img7_paths = glob.glob(LOAD_TRAIN_IMG7S_PATH)
120
+
121
+ load_img8_paths = glob.glob(LOAD_TRAIN_IMG8S_PATH)
122
+
123
+
124
+
125
+ load_img9_paths = glob.glob(LOAD_TRAIN_IMG9S_PATH)
126
+
127
+ load_img10_paths = glob.glob(LOAD_TRAIN_IMG10S_PATH)
128
+
129
+ load_img11_paths = glob.glob(LOAD_TRAIN_IMG11S_PATH)
130
+
131
+ load_img12_paths = glob.glob(LOAD_TRAIN_IMG12S_PATH)
132
+
133
+ load_img13_paths = glob.glob(LOAD_TRAIN_IMG13S_PATH)
134
+
135
+ load_img14_paths = glob.glob(LOAD_TRAIN_IMG14S_PATH)
136
+
137
+ load_img15_paths = glob.glob(LOAD_TRAIN_IMG15S_PATH)
138
+
139
+ load_img16_paths = glob.glob(LOAD_TRAIN_IMG16S_PATH)
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
86
148
 
87
149
  # 学習用の画像ファイルをロードし特徴量抽出
88
150
 
@@ -92,33 +154,129 @@
92
154
 
93
155
  imgs3 = create_images_array(load_img3_paths)
94
156
 
95
-
157
+ imgs4 = create_images_array(load_img4_paths)
158
+
159
+ imgs5 = create_images_array(load_img5_paths)
160
+
161
+ imgs6 = create_images_array(load_img6_paths)
162
+
163
+ imgs7 = create_images_array(load_img7_paths)
164
+
165
+ imgs8 = create_images_array(load_img8_paths)
166
+
167
+
168
+
169
+ imgs9 = create_images_array(load_img9_paths)
170
+
171
+ imgs10 = create_images_array(load_img10_paths)
172
+
173
+ imgs11 = create_images_array(load_img11_paths)
174
+
175
+ imgs12 = create_images_array(load_img12_paths)
176
+
177
+ imgs13 = create_images_array(load_img13_paths)
178
+
179
+ imgs14 = create_images_array(load_img14_paths)
180
+
181
+ imgs15 = create_images_array(load_img15_paths)
182
+
183
+ imgs16 = create_images_array(load_img16_paths)
96
184
 
97
185
 
98
186
 
99
187
 
100
188
 
101
- imgs = np.r_[imgs1, imgs2, imgs3]
189
+ imgs = np.r_[imgs1, imgs2, imgs3, imgs4, imgs5, imgs6, imgs7, imgs8, imgs9, imgs10, imgs11, imgs12, imgs13, imgs14, imgs15, imgs16]
102
190
 
103
191
 
104
192
 
105
193
  # 正解ラベルを生成imgs.番号でラベルを決める
106
194
 
195
+ '''
196
+
197
+ #1パターン目:T1-FE,T2-FE,・・・T1-W,T2-W,・・・全部判別
198
+
107
199
  labels1 = np.full(len(load_img1_paths), 1, np.int32)
108
200
 
109
201
  labels2 = np.full(len(load_img2_paths), 2, np.int32)
110
202
 
111
203
  labels3 = np.full(len(load_img3_paths), 3, np.int32)
112
204
 
113
-
205
+ labels4 = np.full(len(load_img4_paths), 4, np.int32)
206
+
114
-
207
+ labels5 = np.full(len(load_img5_paths), 5, np.int32)
208
+
115
-
209
+ labels6 = np.full(len(load_img6_paths), 6, np.int32)
210
+
116
-
211
+ labels7 = np.full(len(load_img7_paths), 7, np.int32)
212
+
117
-
213
+ labels8 = np.full(len(load_img8_paths), 8, np.int32)
214
+
215
+
216
+
118
-
217
+ labels9 = np.full(len(load_img9_paths), 9, np.int32)
218
+
119
-
219
+ labels10 = np.full(len(load_img10_paths), 10, np.int32)
220
+
120
-
221
+ labels11 = np.full(len(load_img11_paths), 11, np.int32)
222
+
223
+ labels12 = np.full(len(load_img12_paths), 12, np.int32)
224
+
225
+ labels13 = np.full(len(load_img13_paths), 13, np.int32)
226
+
227
+ labels14 = np.full(len(load_img14_paths), 14, np.int32)
228
+
229
+ labels15 = np.full(len(load_img15_paths), 15, np.int32)
230
+
231
+ labels16 = np.full(len(load_img16_paths), 16, np.int32)
232
+
233
+
234
+
235
+ '''
236
+
237
+
238
+
239
+ #2パターン目:T1~T8を判別
240
+
241
+ labels1 = np.full(len(load_img1_paths), 1, np.int32)
242
+
121
- labels = np.array([np.r_[labels1, labels2, labels3]])
243
+ labels2 = np.full(len(load_img2_paths), 2, np.int32)
244
+
245
+ labels3 = np.full(len(load_img3_paths), 3, np.int32)
246
+
247
+ labels4 = np.full(len(load_img4_paths), 4, np.int32)
248
+
249
+ labels5 = np.full(len(load_img5_paths), 5, np.int32)
250
+
251
+ labels6 = np.full(len(load_img6_paths), 6, np.int32)
252
+
253
+ labels7 = np.full(len(load_img7_paths), 7, np.int32)
254
+
255
+ labels8 = np.full(len(load_img8_paths), 8, np.int32)
256
+
257
+
258
+
259
+ labels9 = np.full(len(load_img9_paths), 1, np.int32)
260
+
261
+ labels10 = np.full(len(load_img10_paths), 2, np.int32)
262
+
263
+ labels11 = np.full(len(load_img11_paths), 3, np.int32)
264
+
265
+ labels12 = np.full(len(load_img12_paths), 4, np.int32)
266
+
267
+ labels13 = np.full(len(load_img13_paths), 5, np.int32)
268
+
269
+ labels14 = np.full(len(load_img14_paths), 6, np.int32)
270
+
271
+ labels15 = np.full(len(load_img15_paths), 7, np.int32)
272
+
273
+ labels16 = np.full(len(load_img16_paths), 8, np.int32)
274
+
275
+
276
+
277
+
278
+
279
+ labels = np.array([np.r_[labels1, labels2, labels3, labels4, labels5, labels6, labels7, labels8, labels9, labels10, labels11, labels12, labels13, labels14, labels15, labels16]])
122
280
 
123
281
 
124
282
 
@@ -138,7 +296,11 @@
138
296
 
139
297
  svm.train(imgs, cv2.ml.ROW_SAMPLE, labels)
140
298
 
299
+
300
+
301
+
302
+
141
- # 学習結果を保存
303
+ # 学習結果を保存
142
304
 
143
305
  svm.save(SAVE_TRAINED_DATA_PATH)
144
306
 
@@ -164,4 +326,6 @@
164
326
 
165
327
  error: OpenCV(3.4.2) C:\projects\opencv-python\opencv\modules\ml\src\data.cpp:259: error: (-215:Assertion failed) samples.type() == 5 || samples.type() == 4 in function 'cv::ml::TrainDataImpl::setData'
166
328
 
329
+
330
+
167
331
  ```

1

文法修正

2020/10/17 09:54

投稿

kusegasugoi0221
kusegasugoi0221

スコア11

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- LBPを画像から特徴量を抽出してSVMで学習をさせたいのですが、WEBで調べてコードができて実行をしてもエラーが起きてしまいます。いろいろ試してはいるのですが初めてみるエラーなのでやりかたが分かりません。
1
+ LBPを画像から特徴量を抽出してSVMで学習をさせた、WEBで調べてコードを作ってはみたんですが実行をしてもエラーが起きてしまいます。いろいろ試してはいるのですが初めてみるエラーなのでやりかたが分かりません。
2
2
 
3
3
  教えていただけると嬉しいです
4
4
 
@@ -142,6 +142,14 @@
142
142
 
143
143
  svm.save(SAVE_TRAINED_DATA_PATH)
144
144
 
145
+
146
+
147
+
148
+
149
+ if __name__ == '__main__':
150
+
151
+ main()
152
+
145
153
  ```
146
154
 
147
155