CHINESE-OCR
CHINESE-OCR copied to clipboard
您好请教trainbatch文件中怎么添加accuracy值?
print('Strat training!!') for i in range(EPOCH_NUMS): for X, Y in train_loader: start = time.time() X = X.numpy() X = X.reshape((-1, imgH, imgW, 1)) Y = np.array(Y) Length = int(imgW / 4) - 2 batch = X.shape[0] X_train, Y_train = [ X, Y, np.ones(batch) * Length, np.ones(batch) * n_len ], np.ones(batch) model.train_on_batch(X_train, Y_train) if j % interval == 0: times = time.time() - start currentLoss_train = model.evaluate(X_train, Y_train) X, Y = next(iter(test_loader)) X = X.numpy() X = X.reshape((-1, imgH, imgW, 1)) Y = Y.numpy() Y = np.array(Y) batch = X.shape[0] X_val, Y_val = [ X, Y, np.ones(batch) * Length, np.ones(batch) * n_len ], np.ones(batch) crrentLoss = model.evaluate(X_val, Y_val) print('Learning rate is: ', LEARNING_RATE) now_time = time.strftime('%Y/%m/%d-%H:%M:%S', time.localtime(time.time())) print('Time: [%s]--Step/Epoch/Total: [%d/%d/%d]' % (now_time, j, i, EPOCH_NUMS)) print('\tTraining Loss is: [{}]'.format(currentLoss_train)) print('\tVal Loss is: [{}]'.format(crrentLoss)) print('\tSpeed is: [{}] Samples/Secs'.format(interval / times)) path = MODEL_PATH + '/my_model_keras.h5' with open(LOG_FILE, mode='a') as log_file: log_str = now_time + '----global_step:' + str( j) + '----loss:' + str(loss) + '\n' log_file.writelines(log_str) print(log_str) log_file.close() print('\tWriting to the file: log.txt') print("\tSave model to disk: {}".format(path)) model.save(path) if crrentLoss < loss: loss = crrentLoss if j > 0 and j % Learning_decay_step == 0: LEARNING_RATE_ori = LEARNING_RATE LEARNING_RATE = 0.5 * LEARNING_RATE print('\tUpdating Leaning rate from {} to {}'.format( LEARNING_RATE_ori, LEARNING_RATE)) j += 1
您好,请问这个train跑通了吗?可以指点我一下吗?我在for X, Y in train_loader:这一句出现错误:TypeError: can't pickle Environment objects,请问是因为环境问题引起的吗