/alveo/apps/aks/examples/googlenet_tinyyolov3.py
Python | 98 lines | 59 code | 20 blank | 19 comment | 9 complexity | 4194d70d2cd6b8a51d9be2e5f1a1a424 MD5 | raw file
- #!/usr/bin/env python
- # Copyright 2019 Xilinx Inc.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- import sys
- import glob
- import time
- import threading
- from apps.aks.libs import aks
- def usage(exe):
- print("[INFO] Usage: ")
- print("[INFO] ---------------------- ")
- print("[INFO] ", exe, " <img-dir-googlenet> <img-dir-tinyyolov3>")
- def enqJobThread (name, graph, images):
- # Get AKS Sys Manager
- sysMan = aks.SysManager()
- print ("[INFO] Starting Enqueue:", name)
- for img in images:
- sysMan.enqueueJob(graph, img)
- def main(imageDirectory, graphs):
-
- fileExtension = ('*.jpg', '*.JPEG', '*.png')
- images = {}
- nImages = 0
- for g in graphs.keys():
- images[g] = list()
- for ext in fileExtension:
- images[g].extend(glob.glob(imageDirectory[g] + '/' + ext))
- nImages = nImages + len(images[g])
- kernelDir = "kernel_zoo"
- sysMan = aks.SysManager()
- sysMan.loadKernels(kernelDir)
- lgraphs = {}
- # Load graphs
- for graphName, graphJson in graphs.items():
- sysMan.loadGraphs(graphJson)
- lgraphs[graphName] = sysMan.getGraph(graphName)
- pushThreads = []
- sysMan.resetTimer()
- t0 = time.time()
- for name, gr in lgraphs.items():
- th = threading.Thread(target=enqJobThread, args=(name, gr, images[name],))
- th.start()
- pushThreads.append(th)
- for th in pushThreads:
- th.join()
- sysMan.waitForAllResults()
- t1 = time.time()
- print("\n[INFO] Overall FPS:", nImages / (t1-t0))
- for name, gr in lgraphs.items():
- print("\n[INFO] Graph: ", name)
- sysMan.report(gr)
- print ("")
- # Destroy SysMan
- sysMan.clear()
- if __name__ == "__main__":
- if (len(sys.argv) != 3):
- print("[ERROR] Invalid Usage!")
- usage(sys.argv[0])
- exit(1)
- imageDirectory = {}
- imageDirectory['googlenet_no_runner'] = sys.argv[1]
- imageDirectory['tinyyolov3_no_runner'] = sys.argv[2]
- # GoogleNet and TinyYolo-v3 graphs
- graphs = {}
- graphs['googlenet_no_runner'] = 'graph_zoo/graph_googlenet_no_runner.json'
- graphs['tinyyolov3_no_runner'] = 'graph_zoo/graph_tinyyolov3_no_runner.json'
- # Process graphs
- main(imageDirectory, graphs)