質問編集履歴

1

該当プログラムとエラー文の追加

2022/12/12 00:22

投稿

osumosan
osumosan

スコア11

test CHANGED
File without changes
test CHANGED
@@ -19,9 +19,73 @@
19
19
 
20
20
  初期の考えとしては、3. が達成できたので、アニメ動画像リスト(900枚の画像)を作成し、その1枚1枚の要素に対して顔パーツの検出を行うループ処理を考えていました。以上の処理が終わり、顔パーツが検出された900枚の画像を再構成し、検出されたラベルのみが表示される動画の出力を目的としていました。
21
21
 
22
+ ### モデルの読み込みと利用のプログラム
23
+
24
+ ```python
25
+ #モデルを読み込み
26
+ model = load_model('AnimeImageLearn.h5', compile=False)
27
+
28
+ #画像のリサイズ
29
+ x_image_size = 320 #インプット画像のサイズ
30
+ y_image_size = 224 #インプット画像のサイズ
31
+
32
+ #画像表示の関数
33
+ def visualize(**images):
34
+ n = len(images)
35
+ plt.figure(figsize=(32, 16))
36
+ for i, (name, image) in enumerate(images.items()):
37
+ plt.subplot(1, n, i + 1)
38
+ plt.xticks([])
39
+ plt.yticks([])
40
+ plt.title(' '.join(name.split('_')).title())
41
+ plt.imshow(image)
42
+ plt.show()
43
+
44
+ #任意の画像が格納されているディレクトリへのパス
45
+ %cd C:\Users\XXXX\Desktop\TestImage
46
+
47
+ #判別したい画像群用配列
48
+ TestImgArray = []
49
+
50
+ #TestImageディレクトリ内の画像をTestImgArrayに格納していく
51
+ dir = 'C:/Users/XXXX/Desktop/TestImage'
52
+ dir_NumSum = glob.glob(dir+"/*.png")
53
+ for i, file in enumerate(dir_NumSum):
54
+ image = Image.open(file) #画像の読み込み
55
+ image = image.convert("RGB") #RGBに変換
56
+ image = image.resize((x_image_size, y_image_size)) #サイズ変更
57
+ data = np.asarray(image) #画像データを配列へ変更
58
+ TestImgArray.append(data) #画像データを繰返し追加
59
+ TestImgArray = np.array(TestImgArray)
60
+
61
+ #リスト単位で検出したい
62
+ for i in TestImgArray:
63
+ image = TestImgArray[i]
64
+ image = np.expand_dims(image, axis=0)
65
+ pr_mask = model.predict(image)
66
+
67
+ visualize(
68
+ image=image.squeeze(),
69
+ A_Prediction=pr_mask[..., 1].squeeze(),
70
+ B_Prediction=pr_mask[..., 2].squeeze(),
71
+ )
72
+ ```
73
+
22
74
  ### 発生している問題・エラーメッセージ
23
75
 
24
76
  900枚もの画像を含んだリストをループで処理しようとした結果、メモリエラーが発生してしまい、動画を作成するための材料の準備ができない状況になってしまいました。
77
+
78
+ ```python
79
+ MemoryError Traceback (most recent call last)
80
+ ~\AppData\Local\Temp\ipykernel_32008\349585566.py in <module>
81
+ 1 #リスト単位で判別したい
82
+ 2 for i in TestImgArray:
83
+ ----> 3 image = TestImgArray[i]
84
+ 4 image = np.expand_dims(image, axis=0)
85
+ 5 pr_mask = model.predict(image)
86
+
87
+ MemoryError: Unable to allocate 43.1 GiB for an array with shape (224, 320, 3, 224, 320, 3) and data type uint8
88
+ ```
25
89
 
26
90
  ### 試したこと
27
91