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.

evaluation.py 2.7 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright 2020 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."""
  16. import argparse
  17. from mindspore import context
  18. from mindspore import Model
  19. from mindspore.train.serialization import load_checkpoint, load_param_into_net
  20. from src.md_dataset import create_dataset
  21. from src.losses import OhemLoss
  22. from src.miou_precision import MiouPrecision
  23. from src.deeplabv3 import deeplabv3_resnet50
  24. from src.config import config
  25. parser = argparse.ArgumentParser(description="Deeplabv3 evaluation")
  26. parser.add_argument('--epoch_size', type=int, default=2, help='Epoch size.')
  27. parser.add_argument("--device_id", type=int, default=0, help="Device id, default is 0.")
  28. parser.add_argument('--batch_size', type=int, default=2, help='Batch size.')
  29. parser.add_argument('--data_url', required=True, default=None, help='Evaluation data url')
  30. parser.add_argument('--checkpoint_url', default=None, help='Checkpoint path')
  31. args_opt = parser.parse_args()
  32. context.set_context(mode=context.GRAPH_MODE, device_target="Ascend", device_id=args_opt.device_id)
  33. print(args_opt)
  34. if __name__ == "__main__":
  35. args_opt.crop_size = config.crop_size
  36. args_opt.base_size = config.crop_size
  37. eval_dataset = create_dataset(args_opt, args_opt.data_url, args_opt.epoch_size, args_opt.batch_size, usage="eval")
  38. net = deeplabv3_resnet50(config.seg_num_classes, [args_opt.batch_size, 3, args_opt.crop_size, args_opt.crop_size],
  39. infer_scale_sizes=config.eval_scales, atrous_rates=config.atrous_rates,
  40. decoder_output_stride=config.decoder_output_stride, output_stride=config.output_stride,
  41. fine_tune_batch_norm=config.fine_tune_batch_norm, image_pyramid=config.image_pyramid)
  42. param_dict = load_checkpoint(args_opt.checkpoint_url)
  43. load_param_into_net(net, param_dict)
  44. mIou = MiouPrecision(config.seg_num_classes)
  45. metrics = {'mIou': mIou}
  46. loss = OhemLoss(config.seg_num_classes, config.ignore_label)
  47. model = Model(net, loss, metrics=metrics)
  48. model.eval(eval_dataset)