benchmark_inference.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
  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. """ Scripts that simplifies running evaluation benchmark """
  15. import argparse
  16. import os
  17. import shutil
  18. import subprocess
  19. def main():
  20. # CLI flags
  21. parser = argparse.ArgumentParser(description="MaskRCNN evaluation benchmark")
  22. parser.add_argument('--batch_size', type=int, required=True)
  23. parser.add_argument('--amp', action='store_true')
  24. parser.add_argument('--data_dir', type=str, default='/data')
  25. parser.add_argument('--model_dir', type=str, default='/tmp/model')
  26. parser.add_argument('--weights_dir', type=str, default='/model')
  27. flags = parser.parse_args()
  28. main_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../mask_rcnn_main.py'))
  29. # build command
  30. cmd = (
  31. f'python {main_path}'
  32. f' --mode eval'
  33. f' --model_dir "{flags.model_dir}"'
  34. f' --checkpoint "{os.path.join(flags.weights_dir, "resnet/resnet-nhwc-2018-02-07/model.ckpt-112603")}"'
  35. f' --validation_file_pattern "{os.path.join(flags.data_dir, "val*.tfrecord")}"'
  36. f' --val_json_file "{os.path.join(flags.data_dir, "annotations/instances_val2017.json")}"'
  37. f' --num_steps_per_eval 200'
  38. f' --eval_samples 1200'
  39. f' --use_batched_nms'
  40. f' --nouse_custom_box_proposals_op'
  41. f' --xla'
  42. f' --eval_batch_size {flags.batch_size}'
  43. f' {"--amp" if flags.amp else ""}'
  44. )
  45. # print command
  46. line = '-' * shutil.get_terminal_size()[0]
  47. print(line, cmd, line, sep='\n')
  48. # run model
  49. subprocess.call(cmd, shell=True)
  50. if __name__ == '__main__':
  51. main()