From 471503c3cf5d7ad2a2368387ac8aaccf8bd209a2 Mon Sep 17 00:00:00 2001 From: Jason Parham Date: Tue, 4 Oct 2022 15:37:00 -0700 Subject: [PATCH] Update documentation to add supported species, and update the two Gradio apps --- README.rst | 4 +- app.py | 61 +++++++++++++++++++--------- app2.py | 69 ++++++++++++++++++++++---------- docs/_static/theme.css | 85 ++++++++++++++++++++++++++++++++++++++++ docs/colors.rst | 25 ++++++++++++ docs/onnx.rst | 30 ++++++++------ scoutbot/agg/__init__.py | 10 ++--- scoutbot/loc/__init__.py | 8 ++-- scoutbot/scoutbot.py | 4 +- scoutbot/wic/__init__.py | 2 +- 10 files changed, 232 insertions(+), 66 deletions(-) create mode 100644 docs/colors.rst diff --git a/README.rst b/README.rst index f405327..e5dcdf7 100644 --- a/README.rst +++ b/README.rst @@ -34,13 +34,13 @@ To then add GPU acceleration, you need to replace `onnxruntime` with `onnxruntim How to Run ---------- -You can run the tile-base Gradio demo with: +You can run the tile-based Gradio demo with: .. code-block:: console (.venv) $ python app.py -or, you can run the image-base Gradio demo with: +or, you can run the image-based Gradio demo with: .. code-block:: console diff --git a/app.py b/app.py index 516f5d4..093c4cf 100644 --- a/app.py +++ b/app.py @@ -7,13 +7,26 @@ from scoutbot import loc, wic +PHASE1 = [ + 'Phase 1', + int(wic.CONFIGS['phase1']['thresh'] * 100), + int(loc.CONFIGS['phase1']['thresh'] * 100), + int(loc.CONFIGS['phase1']['nms'] * 100), +] +MVP = [ + 'MVP', + int(wic.CONFIGS['mvp']['thresh'] * 100), + int(loc.CONFIGS['mvp']['thresh'] * 100), + int(loc.CONFIGS['mvp']['nms'] * 100), +] + def predict(filepath, config, wic_thresh, loc_thresh, nms_thresh): start = time.time() - if config == 'MVP': + if config == MVP[0]: config = 'mvp' - elif config == 'Phase 1': + elif config == PHASE1[0]: config = 'phase1' else: raise ValueError() @@ -22,8 +35,6 @@ def predict(filepath, config, wic_thresh, loc_thresh, nms_thresh): loc_thresh /= 100.0 nms_thresh /= 100.0 - nms_thresh = 1.0 - nms_thresh - # Load data img = cv2.imread(filepath) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) @@ -80,12 +91,12 @@ def predict(filepath, config, wic_thresh, loc_thresh, nms_thresh): gr.Radio( label='Model Configuration', type='value', - choices=['Phase 1', 'MVP'], - value='MVP', + choices=[PHASE1[0], MVP[0]], + value=MVP[0], ), - gr.Slider(label='WIC Confidence Threshold', value=7), - gr.Slider(label='Localizer Confidence Threshold', value=14), - gr.Slider(label='Localizer NMS Threshold', value=80), + gr.Slider(label='WIC Confidence Threshold', value=MVP[1]), + gr.Slider(label='Localizer Confidence Threshold', value=MVP[2]), + gr.Slider(label='Localizer NMS Threshold', value=MVP[3]), ], outputs=[ gr.Image(type='numpy'), @@ -94,16 +105,28 @@ def predict(filepath, config, wic_thresh, loc_thresh, nms_thresh): gr.Textbox(label='Predicted Localizer Detections', interactive=False), ], examples=[ - ['examples/07a4b8db-f31c-261d-4580-e9402768fd45.true.jpg', 'MVP', 7, 14, 80], - ['examples/15e815d9-5aad-fa53-d1ed-33429020e15e.true.jpg', 'MVP', 7, 14, 80], - ['examples/1bb79811-3149-7a60-2d88-613dc3eeb261.true.jpg', 'MVP', 7, 14, 80], - ['examples/1e8372e4-357d-26e6-d7fd-0e0ae402463a.true.jpg', 'MVP', 7, 14, 80], - ['examples/201bc65e-d64e-80d3-2610-5865a22d04b4.false.jpg', 'MVP', 7, 14, 80], - ['examples/3affd8b6-9722-f2d5-9171-639615b4c38f.true.jpg', 'MVP', 7, 14, 80], - ['examples/4aedb818-f2f4-e462-8b75-5c8e34a01a59.false.jpg', 'MVP', 7, 14, 80], - ['examples/474bc2b6-dc51-c1b5-4612-efe810bbe091.true.jpg', 'MVP', 7, 14, 80], - ['examples/c3014107-3464-60b5-e04a-e4bfafdf8809.false.jpg', 'MVP', 7, 14, 80], - ['examples/f835ce33-292a-9116-794e-f8859b5956ec.true.jpg', 'MVP', 7, 14, 80], + # Phase 1 + ['examples/07a4b8db-f31c-261d-4580-e9402768fd45.true.jpg'] + PHASE1, + ['examples/15e815d9-5aad-fa53-d1ed-33429020e15e.true.jpg'] + PHASE1, + ['examples/1bb79811-3149-7a60-2d88-613dc3eeb261.true.jpg'] + PHASE1, + ['examples/1e8372e4-357d-26e6-d7fd-0e0ae402463a.true.jpg'] + PHASE1, + ['examples/201bc65e-d64e-80d3-2610-5865a22d04b4.false.jpg'] + PHASE1, + ['examples/3affd8b6-9722-f2d5-9171-639615b4c38f.true.jpg'] + PHASE1, + ['examples/4aedb818-f2f4-e462-8b75-5c8e34a01a59.false.jpg'] + PHASE1, + ['examples/474bc2b6-dc51-c1b5-4612-efe810bbe091.true.jpg'] + PHASE1, + ['examples/c3014107-3464-60b5-e04a-e4bfafdf8809.false.jpg'] + PHASE1, + ['examples/f835ce33-292a-9116-794e-f8859b5956ec.true.jpg'] + PHASE1, + # MVP + ['examples/07a4b8db-f31c-261d-4580-e9402768fd45.true.jpg'] + MVP, + ['examples/15e815d9-5aad-fa53-d1ed-33429020e15e.true.jpg'] + MVP, + ['examples/1bb79811-3149-7a60-2d88-613dc3eeb261.true.jpg'] + MVP, + ['examples/1e8372e4-357d-26e6-d7fd-0e0ae402463a.true.jpg'] + MVP, + ['examples/201bc65e-d64e-80d3-2610-5865a22d04b4.false.jpg'] + MVP, + ['examples/3affd8b6-9722-f2d5-9171-639615b4c38f.true.jpg'] + MVP, + ['examples/4aedb818-f2f4-e462-8b75-5c8e34a01a59.false.jpg'] + MVP, + ['examples/474bc2b6-dc51-c1b5-4612-efe810bbe091.true.jpg'] + MVP, + ['examples/c3014107-3464-60b5-e04a-e4bfafdf8809.false.jpg'] + MVP, + ['examples/f835ce33-292a-9116-794e-f8859b5956ec.true.jpg'] + MVP, ], cache_examples=True, allow_flagging='never', diff --git a/app2.py b/app2.py index 82c8e13..4891c6f 100644 --- a/app2.py +++ b/app2.py @@ -6,10 +6,28 @@ import numpy as np import scoutbot +from scoutbot import agg, loc, wic + +PHASE1 = [ + 'Phase 1', + int(wic.CONFIGS['phase1']['thresh'] * 100), + int(loc.CONFIGS['phase1']['thresh'] * 100), + int(loc.CONFIGS['phase1']['nms'] * 100), + int(agg.CONFIGS['phase1']['thresh'] * 100), + int(agg.CONFIGS['phase1']['nms'] * 100), +] +MVP = [ + 'MVP', + int(wic.CONFIGS['mvp']['thresh'] * 100), + int(loc.CONFIGS['mvp']['thresh'] * 100), + int(loc.CONFIGS['mvp']['nms'] * 100), + int(agg.CONFIGS['mvp']['thresh'] * 100), + int(agg.CONFIGS['mvp']['nms'] * 100), +] def predict( - filepath, config, wic_thresh, loc_thresh, agg_thresh, loc_nms_thresh, agg_nms_thresh + filepath, config, wic_thresh, loc_thresh, loc_nms_thresh, agg_thresh, agg_nms_thresh ): start = time.time() @@ -26,9 +44,6 @@ def predict( agg_thresh /= 100.0 agg_nms_thresh /= 100.0 - loc_nms_thresh = 1.0 - loc_nms_thresh - agg_nms_thresh = 1.0 - agg_nms_thresh - # Load data img = cv2.imread(filepath) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) @@ -81,14 +96,14 @@ def predict( gr.Radio( label='Model Configuration', type='value', - choices=['Phase 1', 'MVP'], - value='MVP', + choices=[PHASE1[0], MVP[0]], + value=MVP[0], ), - gr.Slider(label='WIC Confidence Threshold', value=7), - gr.Slider(label='Localizer Confidence Threshold', value=14), - gr.Slider(label='Aggregation Confidence Threshold', value=51), - gr.Slider(label='Localizer NMS Threshold', value=80), - gr.Slider(label='Aggregation NMS Threshold', value=80), + gr.Slider(label='WIC Confidence Threshold', value=MVP[1]), + gr.Slider(label='Localizer Confidence Threshold', value=MVP[2]), + gr.Slider(label='Localizer NMS Threshold', value=MVP[3]), + gr.Slider(label='Aggregation Confidence Threshold', value=MVP[4]), + gr.Slider(label='Aggregation NMS Threshold', value=MVP[5]), ], outputs=[ gr.Image(type='numpy'), @@ -97,16 +112,28 @@ def predict( gr.Textbox(label='Predicted Detections', interactive=False), ], examples=[ - ['examples/0d4e4df2-7b69-91b1-1985-c8421f2f3253.jpg', 'MVP', 7, 14, 51, 80, 80], - ['examples/18cef191-74ed-2b5e-55a5-f58bd3d483ff.jpg', 'MVP', 7, 14, 51, 80, 80], - ['examples/1be4d40a-6fd0-42ce-da6c-294e45781f41.jpg', 'MVP', 7, 14, 51, 80, 80], - ['examples/1d3c85e9-ee24-f290-e7e1-6e338f2eaebb.jpg', 'MVP', 7, 14, 51, 80, 80], - ['examples/3e043302-af1c-75a7-4057-3a2f25c123bf.jpg', 'MVP', 7, 14, 51, 80, 80], - ['examples/43ecc08d-502a-7a51-9d68-3e40a76439a2.jpg', 'MVP', 7, 14, 51, 80, 80], - ['examples/479058af-e774-e6aa-a2b0-9a42dd6ff8b1.jpg', 'MVP', 7, 14, 51, 80, 80], - ['examples/7c910b87-ae3a-f580-d431-03cd89793803.jpg', 'MVP', 7, 14, 51, 80, 80], - ['examples/8fa04489-cd94-7d8f-7e2e-5f0fe2f7ae76.jpg', 'MVP', 7, 14, 51, 80, 80], - ['examples/bb7b4345-b98a-c727-4c94-6090f0aa4355.jpg', 'MVP', 7, 14, 51, 80, 80], + # Phase 1 + ['examples/0d4e4df2-7b69-91b1-1985-c8421f2f3253.jpg'] + PHASE1, + ['examples/18cef191-74ed-2b5e-55a5-f58bd3d483ff.jpg'] + PHASE1, + ['examples/1be4d40a-6fd0-42ce-da6c-294e45781f41.jpg'] + PHASE1, + ['examples/1d3c85e9-ee24-f290-e7e1-6e338f2eaebb.jpg'] + PHASE1, + ['examples/3e043302-af1c-75a7-4057-3a2f25c123bf.jpg'] + PHASE1, + ['examples/43ecc08d-502a-7a51-9d68-3e40a76439a2.jpg'] + PHASE1, + ['examples/479058af-e774-e6aa-a2b0-9a42dd6ff8b1.jpg'] + PHASE1, + ['examples/7c910b87-ae3a-f580-d431-03cd89793803.jpg'] + PHASE1, + ['examples/8fa04489-cd94-7d8f-7e2e-5f0fe2f7ae76.jpg'] + PHASE1, + ['examples/bb7b4345-b98a-c727-4c94-6090f0aa4355.jpg'] + PHASE1, + # MVP + ['examples/0d4e4df2-7b69-91b1-1985-c8421f2f3253.jpg'] + MVP, + ['examples/18cef191-74ed-2b5e-55a5-f58bd3d483ff.jpg'] + MVP, + ['examples/1be4d40a-6fd0-42ce-da6c-294e45781f41.jpg'] + MVP, + ['examples/1d3c85e9-ee24-f290-e7e1-6e338f2eaebb.jpg'] + MVP, + ['examples/3e043302-af1c-75a7-4057-3a2f25c123bf.jpg'] + MVP, + ['examples/43ecc08d-502a-7a51-9d68-3e40a76439a2.jpg'] + MVP, + ['examples/479058af-e774-e6aa-a2b0-9a42dd6ff8b1.jpg'] + MVP, + ['examples/7c910b87-ae3a-f580-d431-03cd89793803.jpg'] + MVP, + ['examples/8fa04489-cd94-7d8f-7e2e-5f0fe2f7ae76.jpg'] + MVP, + ['examples/bb7b4345-b98a-c727-4c94-6090f0aa4355.jpg'] + MVP, ], cache_examples=True, allow_flagging='never', diff --git a/docs/_static/theme.css b/docs/_static/theme.css index 1a089c2..4e93b95 100644 --- a/docs/_static/theme.css +++ b/docs/_static/theme.css @@ -1,3 +1,88 @@ .wy-nav-content { max-width: 900px !important; } + +.black { + color: black; +} + +.gray { + color: gray; +} + +.grey { + color: gray; +} + +.silver { + color: silver; +} + +.white { + color: white; +} + +.maroon { + color: maroon; +} + +.red { + color: red; +} + +.magenta { + color: magenta; +} + +.fuchsia { + color: fuchsia; +} + +.pink { + color: pink; +} + +.orange { + color: orange; +} + +.yellow { + color: yellow; +} + +.lime { + color: lime; +} + +.green { + color: green; + font-weight: bold; +} + +.olive { + color: olive; +} + +.teal { + color: teal; +} + +.cyan { + color: cyan; +} + +.aqua { + color: aqua; +} + +.blue { + color: blue; +} + +.navy { + color: navy; +} + +.purple { + color: purple; +} diff --git a/docs/colors.rst b/docs/colors.rst new file mode 100644 index 0000000..30fbb2c --- /dev/null +++ b/docs/colors.rst @@ -0,0 +1,25 @@ +.. Color profiles for Sphinx. + +.. role:: black +.. role:: gray +.. role:: grey +.. role:: silver +.. role:: white +.. role:: maroon +.. role:: red +.. role:: magenta +.. role:: fuchsia +.. role:: pink +.. role:: orange +.. role:: yellow +.. role:: lime +.. role:: green +.. role:: olive +.. role:: teal +.. role:: cyan +.. role:: aqua +.. role:: blue +.. role:: navy +.. role:: purple + +.. (c) Lilian Besson, 2011-2016, https://bitbucket.org/lbesson/web-sphinx/ diff --git a/docs/onnx.rst b/docs/onnx.rst index 6815303..ad67516 100644 --- a/docs/onnx.rst +++ b/docs/onnx.rst @@ -1,3 +1,5 @@ +.. include:: colors.rst + CDN Model Download (ONNX) ------------------------- @@ -39,15 +41,15 @@ are not clean and are mapped, for convience, when the final detection labels are supported species for each model: - Phase 1: ``phase1`` - - `elephant_savanna` + - :green:`elephant_savanna` - - mapped to: `elephant` - MVP: ``mvp`` - - `buffalo` + - :green:`buffalo` - `camel` - `canoe` - `car` - - `cow` + - :green:`cow` - `crocodile` - `dead_animalwhite_bones` - - mapped to: `white_bones` @@ -56,7 +58,7 @@ supported species for each model: - `eland` - `elecarcass_old` - - mapped to: `white_bones` - - `elephant` + - :green:`elephant` - `gazelle_gr` - - mapped to: `gazelle_grants` - `gazelle_grants` @@ -65,25 +67,27 @@ supported species for each model: - `gazelle_thomsons` - `gerenuk` - `giant_forest_hog` - - `giraffe` + - :green:`giraffe` - `goat` - - `hartebeest` - - `hippo` + - :green:`hartebeest` + - :green:`hippo` - `impala` - - `kob` + - :green:`kob` - `kudu` - `motorcycle` - `oribi` - - `oryx` + - :green:`oryx` - `ostrich` - `roof_grass` - `roof_mabati` - `sheep` - `test` - - `topi` + - :green:`topi` - `vehicle` - - `warthog` - - `waterbuck` + - :green:`warthog` + - :green:`waterbuck` - `white_bones` - `wildebeest` - - `zebra` + - :green:`zebra` + +All species above that are highlighted in green have an Average Precision (AP) of at least 50%. The other species are supported in a preliminary sense and should not be heavily relied on. diff --git a/scoutbot/agg/__init__.py b/scoutbot/agg/__init__.py index e3c2967..b1b7956 100644 --- a/scoutbot/agg/__init__.py +++ b/scoutbot/agg/__init__.py @@ -18,12 +18,12 @@ DEFAULT_CONFIG = os.getenv('AGG_CONFIG', os.getenv('CONFIG', 'mvp')).strip().lower() CONFIGS = { 'phase1': { - 'thresh': 0.4, - 'nms': 0.2, + 'thresh': 0.5077, + 'nms': 0.8, }, 'mvp': { - 'thresh': 0.4, - 'nms': 0.2, + 'thresh': 0.0, # Disabled: pending validation + 'nms': 0.8, }, } CONFIGS[None] = CONFIGS[DEFAULT_CONFIG] @@ -249,7 +249,7 @@ def compute( ) confs = np.array([detect['c'] for detect in detects]) - keeps = py_cpu_nms(coords, confs, nms_thresh) + keeps = py_cpu_nms(coords, confs, 1.0 - nms_thresh) final = ut.take(detects, keeps) final.sort(key=lambda val: val['c'], reverse=True) diff --git a/scoutbot/loc/__init__.py b/scoutbot/loc/__init__.py index 26f5c1a..8058c61 100644 --- a/scoutbot/loc/__init__.py +++ b/scoutbot/loc/__init__.py @@ -45,8 +45,8 @@ 'path': join(PWD, 'models', 'onnx', 'scout.loc.5fbfff26.0.onnx'), 'hash': '85a9378311d42b5143f74570136f32f50bf97c548135921b178b46ba7612b216', 'classes': ['elephant_savanna'], - 'thresh': 0.4, - 'nms': 0.8, + 'thresh': 0.0, + 'nms': 0.4, 'anchors': [ (1.3221, 1.73145), (3.19275, 4.00944), @@ -101,8 +101,8 @@ 'wildebeest', 'zebra', ], - 'thresh': 0.14, - 'nms': 0.8, + 'thresh': 0.38, + 'nms': 0.6, 'anchors': [ (1.3221, 1.73145), (3.19275, 4.00944), diff --git a/scoutbot/scoutbot.py b/scoutbot/scoutbot.py index 764c602..ef182e1 100755 --- a/scoutbot/scoutbot.py +++ b/scoutbot/scoutbot.py @@ -141,6 +141,7 @@ def pipeline( } } + log.debug('Outputting results...') if output: with open(output, 'w') as outfile: json.dump(data, outfile) @@ -268,10 +269,11 @@ def batch( data = {} for filepath, wic_, detects in results: data[filepath] = { - 'wic': wic, + 'wic': wic_, 'loc': detects, } + log.debug('Outputting results...') if output: with open(output, 'w') as outfile: json.dump(data, outfile) diff --git a/scoutbot/wic/__init__.py b/scoutbot/wic/__init__.py index 336b8a3..902dd1d 100644 --- a/scoutbot/wic/__init__.py +++ b/scoutbot/wic/__init__.py @@ -36,7 +36,7 @@ 'path': join(PWD, 'models', 'onnx', 'scout.wic.5fbfff26.3.0.onnx'), 'hash': 'cbc7f381fa58504e03b6510245b6b2742d63049429337465d95663a6468df4c1', 'classes': ['negative', 'positive'], - 'thresh': 0.2, + 'thresh': 0.4, }, 'mvp': { 'name': 'scout.wic.mvp.2.0.onnx',