質問するログイン新規登録

質問編集履歴

1

プログラム(前処理)を追記しました

2020/09/15 00:32

投稿

51sep
51sep

スコア22

title CHANGED
File without changes
body CHANGED
@@ -8,7 +8,37 @@
8
8
  28×28ピクセル、0~9が描かれた各20画像:合計200画像
9
9
  ![画像データ](6a46847c8247d608845f9e9ff3377893.png)
10
10
 
11
+ ■プログラム(前処理)
12
+ ```
13
+ v_image = []
14
+ v_label = []
15
+ for index, name in enumerate(folder):
16
+ dir = TRAIN_PATH + "\" + name
17
+ files = glob.glob(dir + "\*.png")
18
+ print(dir)
19
+ for i, file in enumerate(files):
20
+ if COLOR_CHANNEL == 1:
21
+ img = load_img(file, color_mode = "grayscale", target_size=(INPUT_IMAGE_SIZE, INPUT_IMAGE_SIZE))
22
+ elif COLOR_CHANNEL == 3:
23
+ img = load_img(file, color_mode = "rgb", target_size=(INPUT_IMAGE_SIZE, INPUT_IMAGE_SIZE))
24
+ array = img_to_array(img)
25
+ v_image.append(array)
26
+ v_label.append(index)
27
+ v_image = np.array(v_image)
28
+ v_label = np.array(v_label)
29
+ v_image = v_image.astype('float32')
30
+ v_image = v_image / 255.0
31
+ v_label = np_utils.to_categorical(v_label, CLASS_NUM)
32
+ train_images, test_images, train_labels, test_labels = train_test_split(v_image, v_label, test_size=0.20)
33
+ train_images2 = np.squeeze(train_images)
34
+ test_images2 = np.squeeze(test_images)
35
+ print(train_images2.shape)
36
+ print(test_images2.shape)
37
+ #(160, 28, 28)
38
+ #(40, 28, 28)
11
39
 
40
+ ```
41
+
12
42
  ■プログラム(モデル)
13
43
  ```
14
44
  model = keras.Sequential([