You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

eval.py 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright 2021 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Evaluation for CTPN"""
  16. import argparse
  17. from mindspore import context
  18. from mindspore.train.serialization import load_checkpoint, load_param_into_net
  19. from mindspore.common import set_seed
  20. from src.ctpn import CTPN
  21. from src.config import config
  22. from src.dataset import create_ctpn_dataset
  23. from src.eval_utils import eval_for_ctpn
  24. set_seed(1)
  25. parser = argparse.ArgumentParser(description="CTPN evaluation")
  26. parser.add_argument("--dataset_path", type=str, default="", help="Dataset path.")
  27. parser.add_argument("--image_path", type=str, default="", help="Image path.")
  28. parser.add_argument("--checkpoint_path", type=str, default="", help="Checkpoint file path.")
  29. parser.add_argument("--device_id", type=int, default=0, help="Device id, default is 0.")
  30. args_opt = parser.parse_args()
  31. context.set_context(mode=context.GRAPH_MODE, device_target="Ascend", device_id=args_opt.device_id)
  32. def ctpn_infer_test(dataset_path='', ckpt_path='', img_dir=''):
  33. """ctpn infer."""
  34. print("ckpt path is {}".format(ckpt_path))
  35. ds = create_ctpn_dataset(dataset_path, batch_size=config.test_batch_size, repeat_num=1, is_training=False)
  36. total = ds.get_dataset_size()
  37. print("eval dataset size is {}".format(total))
  38. net = CTPN(config, batch_size=config.test_batch_size, is_training=False)
  39. param_dict = load_checkpoint(ckpt_path)
  40. load_param_into_net(net, param_dict)
  41. net.set_train(False)
  42. eval_for_ctpn(net, ds, img_dir)
  43. if __name__ == '__main__':
  44. ctpn_infer_test(args_opt.dataset_path, args_opt.checkpoint_path, img_dir=args_opt.image_path)