前提
tensorflowのkerasを用いて画像分類を行っているのですが、model.predictを行う際に透明の画像,または白色か黒色の画像を分類させないということをしたいです。
実現したいこと
・tensorflowのkerasでmodel.predictを行う際に透明の画像か白色か黒色の画像を分類させない
発生している問題・エラーメッセージ
ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 3 but received input with shape [None, 50, 50, 4]
該当のソースコード
python
1###追記### 2def kiritori(img): 3 img_array=np.array(img,dtype='int16') #(50行,83列,3次元)の3次元配列 4 a=np.split(img_array,img.height/50) 5 img_data=np.split(a[0],img.width/50,axis=1)#stackする土台づくり 6 for i in range(len(a)-1): 7 img_data=np.vstack([img_data,np.split(a[i+1],img.width/50,axis=1)]) 8 return img_data 9 10 11test_data = Image.open('Output_file/dst.png') 12 13copy_back=test_data.copy() 14x_test=kiritori(test_data) 15x_test = x_test/255. 16 17# ##精度のアウトプット 18probs=model.predict(x_test) #学習したパラメータで精度を出力 19probs_max=np.reshape(np.argmax(probs,axis=1),(int(test_data.height/50),int(test_data.width/50))) 20np.savetxt('Output_file/output.csv',probs_max,fmt="%d",delimiter=",")
試したこと
dst.pngは、白色の部分を透過した画像になっています。
kiritori関数は、画像を50×50ずつ分割する関数です。
解決方法を教えていただけると幸いです。
補足情報(FW/ツールのバージョンなど)
windows10(64bit)
anacondaを使用
python 3.8.13
TensorFlow 2.3
Spyder 5.3.3を利用

回答2件
あなたの回答
tips
プレビュー