質問編集履歴
8
誤字
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
plt.imshowでは正しいものが見れるのに、保存すると真っ黒になる
|
test
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
plt.imshow(image, cmap = "gray")
|
22
22
|
で1枚ずつならGoogle Colabでは出力できるようになりましたが、visual studioでは真っ黒になります。
|
23
23
|
ここからどのようにして保存すれば良いのかが分かりません。
|
24
|
+
どうやら、plt.imshowでは正しいものが見れるのに、cv2.imshow()だと黒い画像になるようです。
|
24
25
|
|
25
26
|
### 補足情報(FW/ツールのバージョンなど)
|
26
27
|
|
7
情報の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -19,7 +19,8 @@
|
|
19
19
|
image = image.squeeze()#サイズ1の次元を削除
|
20
20
|
print(image.shape)>>>(128, 128)
|
21
21
|
plt.imshow(image, cmap = "gray")
|
22
|
+
で1枚ずつならGoogle Colabでは出力できるようになりましたが、visual studioでは真っ黒になります。
|
22
|
-
|
23
|
+
ここからどのようにして保存すれば良いのかが分かりません。
|
23
24
|
|
24
25
|
### 補足情報(FW/ツールのバージョンなど)
|
25
26
|
|
6
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -19,8 +19,7 @@
|
|
19
19
|
image = image.squeeze()#サイズ1の次元を削除
|
20
20
|
print(image.shape)>>>(128, 128)
|
21
21
|
plt.imshow(image, cmap = "gray")
|
22
|
-
|
23
|
-
で1枚ずつなら出力はできるようになりました。
|
22
|
+
で1枚ずつなら出力はできるようになりましたが、ここからどのようにして保存すれば良いのかが分かりません。
|
24
23
|
|
25
24
|
### 補足情報(FW/ツールのバージョンなど)
|
26
25
|
|
5
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,9 +18,9 @@
|
|
18
18
|
print(image.shape)>>>(1, 128, 128, 1)
|
19
19
|
image = image.squeeze()#サイズ1の次元を削除
|
20
20
|
print(image.shape)>>>(128, 128)
|
21
|
-
plt.imshow(image)
|
21
|
+
plt.imshow(image, cmap = "gray")
|
22
22
|
|
23
|
-
で出力はできるようにな
|
23
|
+
で1枚ずつなら出力はできるようになりました。
|
24
24
|
|
25
25
|
### 補足情報(FW/ツールのバージョンなど)
|
26
26
|
|
4
情報の更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,11 +11,16 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
|
14
|
+
### 試したこと
|
15
|
+
image = test_DS[0][np.newaxis, :, :, :]
|
16
|
+
print(image.shape)>>>(1, 128, 128, 4)
|
17
|
+
image = model.predict(image)
|
18
|
+
print(image.shape)>>>(1, 128, 128, 1)
|
19
|
+
image = image.squeeze()#サイズ1の次元を削除
|
20
|
+
print(image.shape)>>>(128, 128)
|
21
|
+
plt.imshow(image)
|
14
22
|
|
15
|
-
|
16
|
-
### 試したこと
|
17
|
-
|
18
|
-
|
23
|
+
で出力はできるようになったのですが、白黒でほしいのですが黄色で出力されてしまいます。
|
19
24
|
|
20
25
|
### 補足情報(FW/ツールのバージョンなど)
|
21
26
|
|
3
編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,168 +9,9 @@
|
|
9
9
|
|
10
10
|
学習結果をファイル一括でmodel.predictを使って適応させ、保存したい。
|
11
11
|
|
12
|
-
### 発生している問題・エラーメッセージ
|
13
|
-
|
14
|
-
OpenCV(4.6.0) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
|
15
|
-
```
|
16
|
-
|
17
|
-
### 該当のソースコード
|
18
|
-
|
19
|
-
```python
|
20
|
-
Combine = np.load("C:\\Users\\Combined_image.npy",allow_pickle=True)#13500枚
|
21
|
-
Trimap = np.load("C:\\Users\\Trimap_image.npy",allow_pickle=True)
|
22
|
-
GT = np.load("C:\\Users\\GT_image.npy",allow_pickle=True)
|
23
|
-
|
24
|
-
|
25
|
-
#Dataset(テストと訓練に分割)
|
26
|
-
Trimap = Trimap[..., tf.newaxis]
|
27
|
-
GT = GT[..., tf.newaxis]
|
28
|
-
DS = tf.concat([Combine,Trimap],3)
|
29
|
-
|
30
|
-
#Dataset
|
31
|
-
print(Combine.shape)
|
32
|
-
print(Trimap.shape)
|
33
|
-
print(GT.shape)
|
34
|
-
print(DS.shape)
|
35
|
-
|
36
|
-
#free memory
|
37
|
-
del Combine
|
38
|
-
gc.collect()
|
39
|
-
del Trimap
|
40
|
-
gc.collect()
|
41
12
|
|
42
13
|
|
43
14
|
|
44
|
-
train_DS0 = DS[0:12000]#訓練データ(0:12000)
|
45
|
-
train_GT0 = GT[0:12000]
|
46
|
-
|
47
|
-
test_DS = DS[12000:13500]#訓練データ(12000):合計(13500)
|
48
|
-
test_GT = GT[12000:13500]
|
49
|
-
|
50
|
-
|
51
|
-
train_ds0 = np.asarray(train_DS0)#配列を生成
|
52
|
-
train_gt0 = np.asarray(train_GT0)
|
53
|
-
test_ds = np.asarray(test_DS)
|
54
|
-
test_gt = np.asarray(test_GT)
|
55
|
-
|
56
|
-
train_ds0 = train_ds0.astype('float32')/255.0#計算の都合上、入力を 0〜1の範囲の数値にした方が良い→データ型をfloatに変換したのち、255で割る
|
57
|
-
train_gt0 = train_gt0.astype('float32')/255.0
|
58
|
-
test_ds = test_ds.astype('float32')/255.0
|
59
|
-
test_gt = test_gt.astype('float32')/255.0
|
60
|
-
|
61
|
-
|
62
|
-
#パラメータ(エポックとバッチ)
|
63
|
-
epochs = 75#epochsはデータを何周するか
|
64
|
-
epoch_num=list(range(1,epochs+1))
|
65
|
-
train_loss_num=[]
|
66
|
-
test_loss_num=[]
|
67
|
-
|
68
|
-
train_ds = tf.data.Dataset.from_tensor_slices((train_ds0,train_gt0)).batch(50)#tf.data.Dataset.from_tensor_slices().batch()を用いてバッチ化(一定量のデータを集め、一括処理する)
|
69
|
-
test_ds = tf.data.Dataset.from_tensor_slices((test_ds,test_gt)).batch(20)
|
70
|
-
print(train_ds)
|
71
|
-
print(test_ds)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
#U-Netの実装
|
76
|
-
def unet(size=(128,128,4)):#画像サイズ,4チャンネル(RGB+Trimap)
|
77
|
-
x=Input(size)
|
78
|
-
inputs=x
|
79
|
-
|
80
|
-
#エンコーダ
|
81
|
-
conv1=Conv2D(64, (3, 3) , activation = 'relu', padding = 'same')(x)#3*3convolution(畳み込み)、フィルタ(カーネル)64、padding(サイズ保持)
|
82
|
-
conv1=Conv2D(64, (3, 3) , activation = 'relu', padding = 'same')(conv1)#二回反復
|
83
|
-
down1=MaxPooling2D(pool_size=(2, 2), strides=None)(conv1)#サイズ2*2の最大プーリング層(入力画像内の2*2の領域で最大の数値を出力)
|
84
|
-
|
85
|
-
conv2=Conv2D(128, (3, 3) , activation = 'relu', padding = 'same')(down1)#(活性化関数)ReLU関数は入力値が負であれば0、正であれば1
|
86
|
-
conv2=Conv2D(128, (3, 3) , activation = 'relu', padding = 'same')(conv2)
|
87
|
-
down2=MaxPooling2D((2, 2), strides=2)(conv2)#2*2 max pooling と stride(各次元方向に1つ隣の要素に移動するために必要なバイト数)2
|
88
|
-
|
89
|
-
conv3=Conv2D(256, (3, 3) , activation = 'relu', padding = 'same')(down2)
|
90
|
-
conv3=Conv2D(256, (3, 3) , activation = 'relu', padding = 'same')(conv3)
|
91
|
-
down3=MaxPooling2D((2, 2), strides=2)(conv3)
|
92
|
-
|
93
|
-
conv4=Conv2D(512, (3, 3) , activation = 'relu', padding = 'same')(down3)
|
94
|
-
conv4=Conv2D(512, (3, 3) , activation = 'relu', padding = 'same')(conv4)
|
95
|
-
drop4=Dropout(0.5)(conv4)#入力にドロップアウトを適用(過学習を防ぐ)
|
96
|
-
down4=MaxPooling2D((2, 2), strides=2)(drop4)
|
97
|
-
|
98
|
-
conv5=Conv2D(1024, (3, 3) , activation = 'relu', padding = 'same')(down4)
|
99
|
-
conv5=Conv2D(1024, (3, 3) , activation = 'relu', padding = 'same')(conv5)
|
100
|
-
drop5=Dropout(0.5)(conv5)
|
101
|
-
|
102
|
-
#デコーダ
|
103
|
-
up1=UpSampling2D((2, 2))(drop5)
|
104
|
-
conv6=Conv2D(512, (2, 2), activation='relu', padding='same')(up1)
|
105
|
-
concat1=concatenate([drop4, up1], axis=3)#対応する(同じサイズ同士)マップ同士を連結(concatenate()....配列同士を結合)
|
106
|
-
conv6=Conv2D(512, (3, 3), activation='relu', padding='same')(concat1)
|
107
|
-
conv6=Conv2D(512, (3, 3), activation='relu', padding='same')(conv6)
|
108
|
-
|
109
|
-
up2=UpSampling2D((2, 2))(drop5)
|
110
|
-
conv7=Conv2D(256, (2, 2), activation='relu', padding='same')(up2)#up1はミス?
|
111
|
-
concat2=concatenate([down3, up2], axis=3)
|
112
|
-
conv7=Conv2D(256, (3, 3), activation='relu', padding='same')(concat2)
|
113
|
-
conv7=Conv2D(256, (3, 3), activation='relu', padding='same')(conv7)
|
114
|
-
|
115
|
-
up3=UpSampling2D((2, 2))(conv6)
|
116
|
-
conv8=Conv2D(128, (2, 2), activation='relu', padding='same')(up3)
|
117
|
-
concat3=concatenate([down2, up3], axis=3)
|
118
|
-
conv8=Conv2D(128, (3, 3), activation='relu', padding='same')(concat3)
|
119
|
-
conv8=Conv2D(128, (3, 3), activation='relu', padding='same')(conv8)
|
120
|
-
|
121
|
-
up4=UpSampling2D((2, 2))(conv8)
|
122
|
-
conv9=Conv2D(64, (2, 2), activation='relu', padding='same')(up4)
|
123
|
-
concat4=concatenate([down1, up4], axis=3)
|
124
|
-
conv9=Conv2D(64, (3, 3), activation='relu', padding='same')(concat4)
|
125
|
-
conv9=Conv2D(64, (3, 3), activation='relu', padding='same')(conv9)
|
126
|
-
|
127
|
-
outputs = Conv2D(1, 1, activation='sigmoid')(x)#最後は1*1convolutionを使って2クラス(前、背)で分類?,sigmoid関数(あらゆる入力値を0~1.0の範囲の数値に変換して出力)
|
128
|
-
model = Model(inputs=[inputs], outputs=[outputs])#F...sigmoidで3チャンネル(RGB)、背景の差分
|
129
|
-
|
130
|
-
return model
|
131
|
-
|
132
|
-
model=unet()
|
133
|
-
|
134
|
-
#モデルを構築
|
135
|
-
model.compile(optimizer=tf.optimizers.Adam(0.01), loss='categorical_crossentropy', metrics=['accuracy'])
|
136
|
-
|
137
|
-
#optimize(損失(予測値と正解値との差)を最小にする )
|
138
|
-
optimizer = tf.keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False)
|
139
|
-
train_loss = tf.keras.metrics.Mean(name='train_loss')#与えられた値の(加重された)平均を計算
|
140
|
-
test_loss = tf.keras.metrics.Mean(name='test_loss')
|
141
|
-
|
142
|
-
@tf.function#計算の高速化
|
143
|
-
def train_step(image,alpha):
|
144
|
-
with tf.GradientTape() as tape:#GradientTapeは勾配(実際の結果の差を少なくする)を求める
|
145
|
-
predictions = model(image)
|
146
|
-
loss = tf.reduce_mean(tf.square(tf.subtract(predictions, alpha)))#平均二乗誤差
|
147
|
-
gradients = tape.gradient(loss, model.trainable_variables)
|
148
|
-
optimizer.apply_gradients(zip(gradients, model.trainable_variables))
|
149
|
-
train_loss(loss)
|
150
|
-
|
151
|
-
@tf.function
|
152
|
-
def test_step(image,alpha):
|
153
|
-
predictions = model(image)
|
154
|
-
t_loss = tf.reduce_mean(tf.square(tf.subtract(predictions, alpha)))
|
155
|
-
test_loss(t_loss)
|
156
|
-
|
157
|
-
##Do train & test
|
158
|
-
for epoch in range(epochs):
|
159
|
-
for image,alpha in train_ds:
|
160
|
-
train_step(image,alpha)
|
161
|
-
|
162
|
-
for test_image,test_alpha in test_ds:
|
163
|
-
test_step(test_image,test_alpha)
|
164
|
-
|
165
|
-
template = 'Epoch {}, Loss: {}, Test Loss: {}'
|
166
|
-
print (template.format(epoch+1,
|
167
|
-
train_loss.result(),
|
168
|
-
test_loss.result()
|
169
|
-
)
|
170
|
-
)
|
171
|
-
train_loss_num.append(train_loss.result())
|
172
|
-
test_loss_num.append(test_loss.result())
|
173
|
-
```
|
174
15
|
|
175
16
|
### 試したこと
|
176
17
|
|
2
情報の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -17,25 +17,159 @@
|
|
17
17
|
### 該当のソースコード
|
18
18
|
|
19
19
|
```python
|
20
|
-
import numpy
|
21
|
-
count=1
|
22
|
-
import glob
|
23
|
-
i
|
20
|
+
Combine = np.load("C:\\Users\\Combined_image.npy",allow_pickle=True)#13500枚
|
24
|
-
impor
|
21
|
+
Trimap = np.load("C:\\Users\\Trimap_image.npy",allow_pickle=True)
|
25
|
-
import cv2
|
26
|
-
|
22
|
+
GT = np.load("C:\\Users\\GT_image.npy",allow_pickle=True)
|
27
23
|
|
28
24
|
|
25
|
+
#Dataset(テストと訓練に分割)
|
26
|
+
Trimap = Trimap[..., tf.newaxis]
|
27
|
+
GT = GT[..., tf.newaxis]
|
29
|
-
|
28
|
+
DS = tf.concat([Combine,Trimap],3)
|
29
|
+
|
30
|
+
#Dataset
|
30
|
-
|
31
|
+
print(Combine.shape)
|
32
|
+
print(Trimap.shape)
|
33
|
+
print(GT.shape)
|
34
|
+
print(DS.shape)
|
35
|
+
|
36
|
+
#free memory
|
37
|
+
del Combine
|
38
|
+
gc.collect()
|
39
|
+
del Trimap
|
40
|
+
gc.collect()
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
train_DS0 = DS[0:12000]#訓練データ(0:12000)
|
45
|
+
train_GT0 = GT[0:12000]
|
46
|
+
|
47
|
+
test_DS = DS[12000:13500]#訓練データ(12000):合計(13500)
|
48
|
+
test_GT = GT[12000:13500]
|
49
|
+
|
50
|
+
|
51
|
+
train_ds0 = np.asarray(train_DS0)#配列を生成
|
31
|
-
|
52
|
+
train_gt0 = np.asarray(train_GT0)
|
32
|
-
|
53
|
+
test_ds = np.asarray(test_DS)
|
54
|
+
test_gt = np.asarray(test_GT)
|
55
|
+
|
56
|
+
train_ds0 = train_ds0.astype('float32')/255.0#計算の都合上、入力を 0〜1の範囲の数値にした方が良い→データ型をfloatに変換したのち、255で割る
|
57
|
+
train_gt0 = train_gt0.astype('float32')/255.0
|
58
|
+
test_ds = test_ds.astype('float32')/255.0
|
59
|
+
test_gt = test_gt.astype('float32')/255.0
|
60
|
+
|
61
|
+
|
62
|
+
#パラメータ(エポックとバッチ)
|
63
|
+
epochs = 75#epochsはデータを何周するか
|
64
|
+
epoch_num=list(range(1,epochs+1))
|
65
|
+
train_loss_num=[]
|
66
|
+
test_loss_num=[]
|
67
|
+
|
68
|
+
train_ds = tf.data.Dataset.from_tensor_slices((train_ds0,train_gt0)).batch(50)#tf.data.Dataset.from_tensor_slices().batch()を用いてバッチ化(一定量のデータを集め、一括処理する)
|
33
|
-
|
69
|
+
test_ds = tf.data.Dataset.from_tensor_slices((test_ds,test_gt)).batch(20)
|
70
|
+
print(train_ds)
|
71
|
+
print(test_ds)
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
#U-Netの実装
|
76
|
+
def unet(size=(128,128,4)):#画像サイズ,4チャンネル(RGB+Trimap)
|
77
|
+
x=Input(size)
|
34
|
-
|
78
|
+
inputs=x
|
79
|
+
|
80
|
+
#エンコーダ
|
81
|
+
conv1=Conv2D(64, (3, 3) , activation = 'relu', padding = 'same')(x)#3*3convolution(畳み込み)、フィルタ(カーネル)64、padding(サイズ保持)
|
82
|
+
conv1=Conv2D(64, (3, 3) , activation = 'relu', padding = 'same')(conv1)#二回反復
|
83
|
+
down1=MaxPooling2D(pool_size=(2, 2), strides=None)(conv1)#サイズ2*2の最大プーリング層(入力画像内の2*2の領域で最大の数値を出力)
|
84
|
+
|
85
|
+
conv2=Conv2D(128, (3, 3) , activation = 'relu', padding = 'same')(down1)#(活性化関数)ReLU関数は入力値が負であれば0、正であれば1
|
86
|
+
conv2=Conv2D(128, (3, 3) , activation = 'relu', padding = 'same')(conv2)
|
87
|
+
down2=MaxPooling2D((2, 2), strides=2)(conv2)#2*2 max pooling と stride(各次元方向に1つ隣の要素に移動するために必要なバイト数)2
|
88
|
+
|
89
|
+
conv3=Conv2D(256, (3, 3) , activation = 'relu', padding = 'same')(down2)
|
90
|
+
conv3=Conv2D(256, (3, 3) , activation = 'relu', padding = 'same')(conv3)
|
91
|
+
down3=MaxPooling2D((2, 2), strides=2)(conv3)
|
92
|
+
|
93
|
+
conv4=Conv2D(512, (3, 3) , activation = 'relu', padding = 'same')(down3)
|
94
|
+
conv4=Conv2D(512, (3, 3) , activation = 'relu', padding = 'same')(conv4)
|
95
|
+
drop4=Dropout(0.5)(conv4)#入力にドロップアウトを適用(過学習を防ぐ)
|
96
|
+
down4=MaxPooling2D((2, 2), strides=2)(drop4)
|
97
|
+
|
98
|
+
conv5=Conv2D(1024, (3, 3) , activation = 'relu', padding = 'same')(down4)
|
99
|
+
conv5=Conv2D(1024, (3, 3) , activation = 'relu', padding = 'same')(conv5)
|
100
|
+
drop5=Dropout(0.5)(conv5)
|
101
|
+
|
102
|
+
#デコーダ
|
103
|
+
up1=UpSampling2D((2, 2))(drop5)
|
104
|
+
conv6=Conv2D(512, (2, 2), activation='relu', padding='same')(up1)
|
105
|
+
concat1=concatenate([drop4, up1], axis=3)#対応する(同じサイズ同士)マップ同士を連結(concatenate()....配列同士を結合)
|
106
|
+
conv6=Conv2D(512, (3, 3), activation='relu', padding='same')(concat1)
|
107
|
+
conv6=Conv2D(512, (3, 3), activation='relu', padding='same')(conv6)
|
108
|
+
|
109
|
+
up2=UpSampling2D((2, 2))(drop5)
|
110
|
+
conv7=Conv2D(256, (2, 2), activation='relu', padding='same')(up2)#up1はミス?
|
111
|
+
concat2=concatenate([down3, up2], axis=3)
|
112
|
+
conv7=Conv2D(256, (3, 3), activation='relu', padding='same')(concat2)
|
113
|
+
conv7=Conv2D(256, (3, 3), activation='relu', padding='same')(conv7)
|
114
|
+
|
115
|
+
up3=UpSampling2D((2, 2))(conv6)
|
116
|
+
conv8=Conv2D(128, (2, 2), activation='relu', padding='same')(up3)
|
117
|
+
concat3=concatenate([down2, up3], axis=3)
|
118
|
+
conv8=Conv2D(128, (3, 3), activation='relu', padding='same')(concat3)
|
119
|
+
conv8=Conv2D(128, (3, 3), activation='relu', padding='same')(conv8)
|
120
|
+
|
121
|
+
up4=UpSampling2D((2, 2))(conv8)
|
122
|
+
conv9=Conv2D(64, (2, 2), activation='relu', padding='same')(up4)
|
123
|
+
concat4=concatenate([down1, up4], axis=3)
|
124
|
+
conv9=Conv2D(64, (3, 3), activation='relu', padding='same')(concat4)
|
125
|
+
conv9=Conv2D(64, (3, 3), activation='relu', padding='same')(conv9)
|
126
|
+
|
127
|
+
outputs = Conv2D(1, 1, activation='sigmoid')(x)#最後は1*1convolutionを使って2クラス(前、背)で分類?,sigmoid関数(あらゆる入力値を0~1.0の範囲の数値に変換して出力)
|
128
|
+
model = Model(inputs=[inputs], outputs=[outputs])#F...sigmoidで3チャンネル(RGB)、背景の差分
|
129
|
+
|
130
|
+
return model
|
131
|
+
|
132
|
+
model=unet()
|
133
|
+
|
134
|
+
#モデルを構築
|
135
|
+
model.compile(optimizer=tf.optimizers.Adam(0.01), loss='categorical_crossentropy', metrics=['accuracy'])
|
136
|
+
|
137
|
+
#optimize(損失(予測値と正解値との差)を最小にする )
|
138
|
+
optimizer = tf.keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False)
|
139
|
+
train_loss = tf.keras.metrics.Mean(name='train_loss')#与えられた値の(加重された)平均を計算
|
140
|
+
test_loss = tf.keras.metrics.Mean(name='test_loss')
|
141
|
+
|
142
|
+
@tf.function#計算の高速化
|
143
|
+
def train_step(image,alpha):
|
144
|
+
with tf.GradientTape() as tape:#GradientTapeは勾配(実際の結果の差を少なくする)を求める
|
35
|
-
|
145
|
+
predictions = model(image)
|
146
|
+
loss = tf.reduce_mean(tf.square(tf.subtract(predictions, alpha)))#平均二乗誤差
|
36
|
-
ds
|
147
|
+
gradients = tape.gradient(loss, model.trainable_variables)
|
148
|
+
optimizer.apply_gradients(zip(gradients, model.trainable_variables))
|
149
|
+
train_loss(loss)
|
150
|
+
|
151
|
+
@tf.function
|
152
|
+
def test_step(image,alpha):
|
153
|
+
predictions = model(image)
|
154
|
+
t_loss = tf.reduce_mean(tf.square(tf.subtract(predictions, alpha)))
|
155
|
+
test_loss(t_loss)
|
156
|
+
|
157
|
+
##Do train & test
|
158
|
+
for epoch in range(epochs):
|
159
|
+
for image,alpha in train_ds:
|
160
|
+
train_step(image,alpha)
|
161
|
+
|
162
|
+
for test_image,test_alpha in test_ds:
|
163
|
+
test_step(test_image,test_alpha)
|
164
|
+
|
165
|
+
template = 'Epoch {}, Loss: {}, Test Loss: {}'
|
166
|
+
print (template.format(epoch+1,
|
167
|
+
train_loss.result(),
|
37
|
-
|
168
|
+
test_loss.result()
|
169
|
+
)
|
170
|
+
)
|
171
|
+
train_loss_num.append(train_loss.result())
|
38
|
-
|
172
|
+
test_loss_num.append(test_loss.result())
|
39
173
|
```
|
40
174
|
|
41
175
|
### 試したこと
|
1
編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
### 発生している問題・エラーメッセージ
|
13
13
|
|
14
|
-
|
14
|
+
OpenCV(4.6.0) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
|
15
15
|
```
|
16
16
|
|
17
17
|
### 該当のソースコード
|
@@ -19,17 +19,23 @@
|
|
19
19
|
```python
|
20
20
|
import numpy
|
21
21
|
count=1
|
22
|
+
import glob
|
23
|
+
import os.path
|
24
|
+
import numpy as np
|
25
|
+
import cv2
|
26
|
+
from google.colab.patches import cv2_imshow
|
27
|
+
|
28
|
+
|
29
|
+
path = "/content/drive/MyDrive/Alpha Matting/Dataset/final_pre/Combine"
|
22
|
-
for
|
30
|
+
for x in glob.glob(path):
|
23
|
-
|
31
|
+
name, ext = os.path.splitext(os.path.basename(x))
|
24
|
-
|
32
|
+
dirname = os.path.dirname(x)
|
25
|
-
|
33
|
+
outpath = os.path.join(dirname, (name + "-rgba" + ext))
|
34
|
+
inpath = x
|
26
|
-
c
|
35
|
+
src = cv2.imread(inpath)
|
27
|
-
|
36
|
+
dst = cv2.cvtColor(src, cv2.COLOR_RGB2RGBA)
|
28
|
-
pil_image = img_to_array(pil_image) #ここで適応させたい
|
29
|
-
|
37
|
+
dst = model.predict(dst)
|
30
|
-
#w1.save(to_dir / str('comb'+ count2 +'.png'))
|
31
|
-
|
38
|
+
cv2_imshow(dst)
|
32
|
-
count += 1
|
33
39
|
```
|
34
40
|
|
35
41
|
### 試したこと
|