|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import sys |
| 4 | +import subprocess |
| 5 | +import re |
| 6 | +from enum import Enum |
| 7 | + |
| 8 | +## Helper functions ################################################## |
| 9 | +## |
| 10 | +def fmt_bool(x): |
| 11 | + return ("true" if x else "false") |
| 12 | + |
| 13 | +def fmt_bin(base, prec, model): |
| 14 | + return "%s/%s/%s/%s.xml" % (base, model, prec, model) |
| 15 | + |
| 16 | +## The script itself ################################################# |
| 17 | +## |
| 18 | +if len(sys.argv) != 3: |
| 19 | + print("Usage: %s /path/to/input/video /path/to/models" % sys.argv[0]) |
| 20 | + exit(1) |
| 21 | + |
| 22 | +input_file_path = sys.argv[1] |
| 23 | +intel_models_path = sys.argv[2] |
| 24 | + |
| 25 | +app = "bin/example_gapi_privacy_masking_camera" |
| 26 | +intel_fd_model = "face-detection-retail-0005" |
| 27 | +intel_lpd_model = "vehicle-license-plate-detection-barrier-0106" |
| 28 | +output_file = "out_results.csv" |
| 29 | + |
| 30 | +tgts = [ ("CPU", "INT8") |
| 31 | + , ("CPU", "FP32") |
| 32 | + , ("GPU", "FP16") |
| 33 | + ] |
| 34 | + |
| 35 | +class Policy(Enum): |
| 36 | + Traditional = 1 |
| 37 | + Streaming = 2 |
| 38 | + |
| 39 | +# From mode to cmd arg |
| 40 | +mods = [ (Policy.Traditional, True) |
| 41 | + , (Policy.Streaming, False) |
| 42 | + ] |
| 43 | + |
| 44 | +class UI(Enum): |
| 45 | + With = 1 |
| 46 | + Without = 2 |
| 47 | + |
| 48 | +# From mode to cmd arg |
| 49 | +ui = [ (UI.With, False) |
| 50 | + , (UI.Without, True) |
| 51 | + ] |
| 52 | + |
| 53 | +fd_fmt_bin = lambda prec : fmt_bin(intel_models_path, prec, intel_fd_model) |
| 54 | +lpd_fmt_bin = lambda prec : fmt_bin(intel_models_path, prec, intel_lpd_model) |
| 55 | + |
| 56 | +# Performance comparison table |
| 57 | +table={} |
| 58 | + |
| 59 | +# Collect the performance data |
| 60 | +for m in mods: # Execution mode (trad/stream) |
| 61 | + for u in ui: # UI mode (on/off) |
| 62 | + for f in tgts: # FD model |
| 63 | + for p in tgts: # LPD model |
| 64 | + cmd = [ app |
| 65 | + , ("--input=%s" % input_file_path) # input file |
| 66 | + , ("--faced=%s" % f[0]) # FD device target |
| 67 | + , ("--facem=%s" % fd_fmt_bin(f[1])) # FD model @ precision |
| 68 | + , ("--platd=%s" % p[0]) # LPD device target |
| 69 | + , ("--platm=%s" % lpd_fmt_bin(p[1])) # LPD model @ precision |
| 70 | + , ("--trad=%s" % fmt_bool(m[1])) # Execution policy |
| 71 | + , ("--noshow=%s" % fmt_bool(u[1])) # UI mode (show/no show) |
| 72 | + ] |
| 73 | + out = str(subprocess.check_output(cmd)) |
| 74 | + match = re.search('Processed [0-9]+ frames \(([0-9]+\.[0-9]+) FPS\)', out) |
| 75 | + fps = float(match.group(1)) |
| 76 | + print(cmd, fps, "FPS") |
| 77 | + table[m[0],u[0],f,p] = fps |
| 78 | + |
| 79 | +# Write the performance summary |
| 80 | +# Columns: all other components (mode, ui) |
| 81 | +with open(output_file, 'w') as csv: |
| 82 | + # CSV header |
| 83 | + csv.write("FD,LPD,Serial(UI),Serial(no-UI),Streaming(UI),Streaming(no-UI),Effect(UI),Effect(no-UI)\n") |
| 84 | + |
| 85 | + for f in tgts: # FD model |
| 86 | + for p in tgts: # LPD model |
| 87 | + row = "%s/%s,%s/%s" % (f[0], f[1], p[0], p[1]) # FD precision, LPD precision |
| 88 | + row += ",%f" % table[Policy.Traditional,UI.With, f,p] # Serial/UI |
| 89 | + row += ",%f" % table[Policy.Traditional,UI.Without,f,p] # Serial/no UI |
| 90 | + row += ",%f" % table[Policy.Streaming, UI.With, f,p] # Streaming/UI |
| 91 | + row += ",%f" % table[Policy.Streaming, UI.Without,f,p] # Streaming/no UI |
| 92 | + |
| 93 | + effect_ui = table[Policy.Streaming,UI.With, f,p] / table[Policy.Traditional,UI.With, f,p] |
| 94 | + effect_noui = table[Policy.Streaming,UI.Without,f,p] / table[Policy.Traditional,UI.Without,f,p] |
| 95 | + row += ",%f,%f" % (effect_ui,effect_noui) |
| 96 | + row += "\n" |
| 97 | + csv.write(row) |
| 98 | + |
| 99 | +print("DONE: ", output_file) |
0 commit comments