f"Time per epoch:          {(time_epoch / 60):.2f} min",
                f"Time per item:           {(time_epoch / total_item):.8f} sec\n",
                f"Total epochs:            {len(loss)}",
                f"Best epoch               {min_val_loss_i + 1}\n",
                f"Training loss:           {loss[min_val_loss_i]:.8f}",
                f"Validation loss:         {min_val_loss:.8f}"
            ])

            with open(os.path.join(output_path, "train.txt"), "w") as lg:
                lg.write(t_corpus)
                print(t_corpus)

        elif args.test:
            start_time = time.time()
            predicts = model.predict_generator(
                generator=dtgen.next_test_batch(),
                steps=dtgen.test_steps,
                use_multiprocessing=True,
                verbose=1)

            predicts = [dtgen.tokenizer.decode(x) for x in predicts]
            total_time = time.time() - start_time

            with open(os.path.join(output_path, "predict.txt"), "w") as lg:
                for pd, gt in zip(predicts, dtgen.dataset["test"]["gt"]):
                    lg.write(f"TE_L {gt}\nTE_P {pd}\n")

            evaluate = evaluation.ocr_metrics(
                predicts=predicts,
                ground_truth=dtgen.dataset["test"]["gt"],
                norm_accentuation=False,
Пример #2
0
                    f"Time per item:              {time_epoch / total_item}\n",
                    f"Best epoch                  {best_epoch_index + 1}",
                    f"Training loss:              {loss[best_epoch_index]:.8f}",
                    f"Training accuracy:          {accuracy[best_epoch_index]:.8f}\n",
                    f"Validation loss:            {val_loss[best_epoch_index]:.8f}",
                    f"Validation accuracy:        {val_accuracy[best_epoch_index]:.8f}"
                ])

                with open(os.path.join(output_path, "train.txt"), "w") as lg:
                    lg.write(t_corpus)
                    print(t_corpus)

            elif args.test:
                start_time = datetime.datetime.now()

                predicts = model.predict(x=dtgen.next_test_batch(),
                                         steps=dtgen.steps['test'],
                                         verbose=1)
                predicts = [pp.text_standardize(x) for x in predicts]

                total_time = datetime.datetime.now() - start_time

                old_metric, new_metric = ev.ocr_metrics(
                    ground_truth=dtgen.dataset['test']['gt'],
                    data=dtgen.dataset['test']['dt'],
                    predict=predicts,
                    norm_accentuation=args.norm_accentuation,
                    norm_punctuation=args.norm_punctuation)

                p_corpus, e_corpus = report(dtgen=dtgen,
                                            predicts=predicts,
Пример #3
0
                    f"Time per item:              {time_epoch / total_item}\n",
                    f"Best epoch                  {best_epoch_index + 1}",
                    f"Training loss:              {loss[best_epoch_index]:.8f}",
                    f"Training accuracy:          {accuracy[best_epoch_index]:.8f}\n",
                    f"Validation loss:            {val_loss[best_epoch_index]:.8f}",
                    f"Validation accuracy:        {val_accuracy[best_epoch_index]:.8f}"
                ])

                with open(os.path.join(output_path, "train.txt"), "w") as lg:
                    lg.write(t_corpus)
                    print(t_corpus)

            elif args.test:
                start_time = datetime.datetime.now()

                predicts = model.predict(x=dtgen.next_test_batch(), steps=dtgen.steps['test'], verbose=1)
                predicts = [pp.text_standardize(x) for x in predicts]

                total_time = datetime.datetime.now() - start_time

                old_metric, new_metric = ev.ocr_metrics(ground_truth=dtgen.dataset['test']['gt'],
                                                        data=dtgen.dataset['test']['dt'],
                                                        predict=predicts,
                                                        norm_accentuation=args.norm_accentuation,
                                                        norm_punctuation=args.norm_punctuation)

                p_corpus, e_corpus = report(dtgen=dtgen,
                                            predicts=predicts,
                                            metrics=[old_metric, new_metric],
                                            total_time=total_time)