measure_privacy_masking.py 3.5 KB

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