質問編集履歴

2

内容調整

2019/07/10 00:16

投稿

Nitta
Nitta

スコア96

test CHANGED
File without changes
test CHANGED
@@ -186,6 +186,8 @@
186
186
 
187
187
  ```
188
188
 
189
+ ●データの整調
190
+
189
191
  ```
190
192
 
191
193
  #取り込んだ犬と猫のデータを調整(回転させるなど)

1

内容調整

2019/07/10 00:16

投稿

Nitta
Nitta

スコア96

test CHANGED
File without changes
test CHANGED
@@ -186,6 +186,104 @@
186
186
 
187
187
  ```
188
188
 
189
+ ```
190
+
191
+ #取り込んだ犬と猫のデータを調整(回転させるなど)
192
+
193
+ from PIL import Image
194
+
195
+ import os,glob
196
+
197
+ import numpy as np
198
+
199
+
200
+
201
+ classes=["dogs","cats"]
202
+
203
+ num_classes = len(classes)
204
+
205
+ image_size = 64
206
+
207
+ num_testdata = 25
208
+
209
+
210
+
211
+ X_train = []
212
+
213
+ Y_train = []
214
+
215
+ X_test = []
216
+
217
+ Y_test = []
218
+
219
+
220
+
221
+ for index,classlabel in enumerate(classes):
222
+
223
+
224
+
225
+ photos_dir = "./" + classlabel
226
+
227
+ files = glob.glob(photos_dir + "/*.jpg")
228
+
229
+ for i, file in enumerate(files):
230
+
231
+ image = Image.open(file).convert("RGB")
232
+
233
+ #image = Image.convert("RGB")
234
+
235
+ image = image.resize((image_size, image_size))
236
+
237
+ data = np.asarray(image)
238
+
239
+ if i < num_testdata:
240
+
241
+ X_test.append(data)
242
+
243
+ Y_test.append(index)
244
+
245
+ else:
246
+
247
+ for angle in range(-20, 20, 5):
248
+
249
+
250
+
251
+ img_r = image.rotate(angle)
252
+
253
+ data = np.asarray(img_r)
254
+
255
+ X_train.append(data)
256
+
257
+ Y_train.append(index)
258
+
259
+
260
+
261
+ img_trans = img_r.transpose(Image.FLIP_LEFT_RIGHT)
262
+
263
+ data = np.asarray(img_trans)
264
+
265
+ X_train.append(data)
266
+
267
+ Y_train.append(index)
268
+
269
+
270
+
271
+ X_train = np.array(X_train)
272
+
273
+ X_test = np.array(X_test)
274
+
275
+ Y_train = np.array(Y_train)
276
+
277
+ Y_test = np.array(Y_test)
278
+
279
+
280
+
281
+ xy = (X_train, X_test, Y_train, Y_test)
282
+
283
+ np.save("./dog_cat.npy", xy)
284
+
285
+ ```
286
+
189
287
  input_shapeガおかしいのでしょうが、どう修正すればいいのか??
190
288
 
191
289