實作https://github.com/JasonLiTW/simple-railway-captcha-solver
由於電腦GPU不夠,手動自製Generator後餵入fit一直出現異常訊息
若有夥伴知道再麻煩協助,萬謝感恩
異常訊息:
Invalid argument: Can not squeeze dim[2], expected a dimension of 1, got 34
自製Generator:
from tensorflow.keras.utils import Sequence
class VerificationCodeSequence(Sequence):
def init(self,x_set,y_set,batch_size) :
y_set = np.array(y_set)
self.x ,self.y = x_set, y_set
self.batch_size = batch_size
def len(self):
return math.ceil(len(self.x)//self.batch_size)
def getitem(self, idx):
batch_x = self.x[idx * self.batch_size:(idx + 1) * self.batch_size] # (batch_size,60,200,34)
batch_y = self.y[:,idx * self.batch_size:(idx + 1) * self.batch_size] # (6,batch_size,34)
return np.array(batch_x), np.array(batch_y)
餵入fit:
model.fit(x=VerificationCodeSequence(train_data, train_label,batch_size),
epochs=2,
verbose=2,
callbacks=None)
版本資訊:
tensorflow = 2.6
keras = 2.6
python = 3.9
備註:雖有查過Keras官方文件,一直看不懂要它要怎麼的格式
https://www.tensorflow.org/versions/r2.6/api_docs/python/tf/keras/Model#fit