我正在使用keras进行简单的OCR。调用:lazy Evaluation count : 35819946 time mean : 10.856 ns
:lazy-count Evaluation count : 8496 time mean : 69941.171 ns
:vec Evaluation count : 9492 time mean : 62965.632 ns
:ArrayList Evaluation count : 167490 time mean : 3594.586 ns
方法时,它会显示无效分数和丢失。
我已经从keras 2.0更新到keras 2.1.3,但仍有相同的问题。
这是我的发电机功能。
fit_generator
和方法调用
def generate_dataset(directory, batch_size=BATCH_SIZE):
data = pd.read_csv(directory + 'data.csv')
while 1:
data.sample(frac=1)
data_images = data['image']
classes = np.array([CHARACTERS.index(i) for i in data['char']])
classes = to_categorical(classes)
for i in range(0, len(data_images), batch_size):
y_train = classes[i:i+batch_size]
x_train_filenames = data_images[i:i+batch_size].tolist()
x_train = np.empty([len(x_train_filenames), 60, 60, 3], dtype=np.float32)
for j in range(len(x_train_filenames)):
im = Image.open(directory + x_train_filenames[j])
arr = np.array(im).astype(np.float32) / 255
x_train[j] = arr
im.close()
yield x_train, y_train
以下是前三个时期的输出
大纪元1/5 783/782 [==============================] - 122s 156ms /步 - 损失:9.5539 - acc:0.2319 - val_loss:0.6028 - val_acc:0.7958
Epoch 2/5 783/782 [==============================] - 96s 122ms /步 - 损失:9.0007 - acc:0.3991 - val_loss:0.3196 - val_acc:0.8865
Epoch 3/5 578/782 [=====================> ........] - ETA:23s - 损失: 8.9411 - acc:0.4181
你怎么看,火车损失无效。
我已为火车数据集运行steps_per_epoch = steps_per_epoch=pd.read_csv(TRAIN_DIR + 'data.csv').shape[0] / BATCH_SIZE + 1
validation_steps = pd.read_csv(VALIDATION_DIR + 'data.csv').shape[0] / BATCH_SIZE + 1
model.fit_generator(
generate_dataset(TRAIN_DIR),
steps_per_epoch=steps_per_epoch,
validation_data = generate_dataset(VALIDATION_DIR),
validation_steps = validation_steps,
verbose=1,
epochs=5)
方法,它正常工作,显示实数,而不是8.9表示损失。
我在Ubuntu 16.04上使用Keras 2.1.3和tensorflow后端