/alveo/apps/aks/examples/googlenet_tinyyolov3.py

https://github.com/Xilinx/Vitis-AI
Python | 98 lines | 59 code | 20 blank | 19 comment | 9 complexity | 4194d70d2cd6b8a51d9be2e5f1a1a424 MD5 | raw file
  1. #!/usr/bin/env python
  2. # Copyright 2019 Xilinx Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import sys
  16. import glob
  17. import time
  18. import threading
  19. from apps.aks.libs import aks
  20. def usage(exe):
  21. print("[INFO] Usage: ")
  22. print("[INFO] ---------------------- ")
  23. print("[INFO] ", exe, " <img-dir-googlenet> <img-dir-tinyyolov3>")
  24. def enqJobThread (name, graph, images):
  25. # Get AKS Sys Manager
  26. sysMan = aks.SysManager()
  27. print ("[INFO] Starting Enqueue:", name)
  28. for img in images:
  29. sysMan.enqueueJob(graph, img)
  30. def main(imageDirectory, graphs):
  31. fileExtension = ('*.jpg', '*.JPEG', '*.png')
  32. images = {}
  33. nImages = 0
  34. for g in graphs.keys():
  35. images[g] = list()
  36. for ext in fileExtension:
  37. images[g].extend(glob.glob(imageDirectory[g] + '/' + ext))
  38. nImages = nImages + len(images[g])
  39. kernelDir = "kernel_zoo"
  40. sysMan = aks.SysManager()
  41. sysMan.loadKernels(kernelDir)
  42. lgraphs = {}
  43. # Load graphs
  44. for graphName, graphJson in graphs.items():
  45. sysMan.loadGraphs(graphJson)
  46. lgraphs[graphName] = sysMan.getGraph(graphName)
  47. pushThreads = []
  48. sysMan.resetTimer()
  49. t0 = time.time()
  50. for name, gr in lgraphs.items():
  51. th = threading.Thread(target=enqJobThread, args=(name, gr, images[name],))
  52. th.start()
  53. pushThreads.append(th)
  54. for th in pushThreads:
  55. th.join()
  56. sysMan.waitForAllResults()
  57. t1 = time.time()
  58. print("\n[INFO] Overall FPS:", nImages / (t1-t0))
  59. for name, gr in lgraphs.items():
  60. print("\n[INFO] Graph: ", name)
  61. sysMan.report(gr)
  62. print ("")
  63. # Destroy SysMan
  64. sysMan.clear()
  65. if __name__ == "__main__":
  66. if (len(sys.argv) != 3):
  67. print("[ERROR] Invalid Usage!")
  68. usage(sys.argv[0])
  69. exit(1)
  70. imageDirectory = {}
  71. imageDirectory['googlenet_no_runner'] = sys.argv[1]
  72. imageDirectory['tinyyolov3_no_runner'] = sys.argv[2]
  73. # GoogleNet and TinyYolo-v3 graphs
  74. graphs = {}
  75. graphs['googlenet_no_runner'] = 'graph_zoo/graph_googlenet_no_runner.json'
  76. graphs['tinyyolov3_no_runner'] = 'graph_zoo/graph_tinyyolov3_no_runner.json'
  77. # Process graphs
  78. main(imageDirectory, graphs)