Skip to content

Commit 09f59f8

Browse files
committed
Merge remote-tracking branch 'origin/develop' into vs/ov_2023_2
2 parents 8ca885c + de0f5ae commit 09f59f8

File tree

5 files changed

+50
-51
lines changed

5 files changed

+50
-51
lines changed

docs/source/guide/get_started/cli_commands.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ With the ``--help`` command, you can list additional information, such as its pa
449449
.. code-block::
450450
451451
(otx) ...$ otx explain --help
452-
usage: otx explain [-h] --explain-data-roots EXPLAIN_DATA_ROOTS [--save-explanation-to SAVE_EXPLANATION] --load-weights LOAD_WEIGHTS [--explain-algorithm EXPLAIN_ALGORITHM] [--overlay-weight OVERLAY_WEIGHT] [template] {params} ...
452+
usage: otx explain [-h] --input INPUT [--output OUTPUT] --load-weights LOAD_WEIGHTS [--explain-algorithm EXPLAIN_ALGORITHM] [--overlay-weight OVERLAY_WEIGHT] [template] {params} ...
453453
454454
positional arguments:
455455
template Enter the path or ID or name of the template file.
@@ -459,9 +459,9 @@ With the ``--help`` command, you can list additional information, such as its pa
459459
460460
optional arguments:
461461
-h, --help show this help message and exit
462-
--explain-data-roots EXPLAIN_DATA_ROOTS
462+
-i INPUT, --input INPUT
463463
Comma-separated paths to explain data folders.
464-
--save-explanation-to SAVE_EXPLANATION_TO
464+
-o OUTPUT, --output OUTPUT
465465
Output path for explanation images.
466466
--load-weights LOAD_WEIGHTS
467467
Load model weights from previously saved checkpoint.
@@ -475,13 +475,13 @@ With the ``--help`` command, you can list additional information, such as its pa
475475
Weight of the saliency map when overlaying the input image with saliency map.
476476
477477
478-
The command below will generate saliency maps (heatmaps with red colored areas of focus) of the trained model on the provided dataset and save the resulting images to ``save-explanation-to`` path:
478+
The command below will generate saliency maps (heatmaps with red colored areas of focus) of the trained model on the provided dataset and save the resulting images to ``output`` path:
479479

480480
.. code-block::
481481
482-
(otx) ...$ otx explain SSD --explain-data-roots <path/to/explain/root> \
482+
(otx) ...$ otx explain SSD --input <path/to/explain/root> \
483483
--load-weights <path/to/model_weights> \
484-
--save-explanation-to <path/to/output/root> \
484+
--output <path/to/output/root> \
485485
--explain-algorithm classwisesaliencymap \
486486
--overlay-weight 0.5
487487
@@ -496,9 +496,9 @@ By default, the model is exported to the OpenVINO™ IR format without extra fea
496496
(otx) ...$ otx export SSD --load-weights <path/to/trained/weights.pth> \
497497
--output outputs/openvino/with_features \
498498
--dump-features
499-
(otx) ...$ otx explain SSD --explain-data-roots <path/to/explain/root> \
499+
(otx) ...$ otx explain SSD --input <path/to/explain/root> \
500500
--load-weights outputs/openvino/with_features \
501-
--save-explanation-to <path/to/output/root> \
501+
--output <path/to/output/root> \
502502
--explain-algorithm classwisesaliencymap \
503503
--overlay-weight 0.5
504504

docs/source/guide/tutorials/base/explain.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ created in the previous step.
2222
. venv/otx/bin/activate
2323
2424
2. ``otx explain`` returns saliency maps (heatmaps with red colored areas of focus)
25-
at the path specified by ``--save-explanation-to``.
25+
at the path specified by ``--output``.
2626

2727
.. code-block::
2828
29-
otx explain --explain-data-roots otx-workspace-DETECTION/splitted_dataset/val/ \
30-
--save-explanation-to outputs/explanation \
29+
otx explain --input otx-workspace-DETECTION/splitted_dataset/val/ \
30+
--output outputs/explanation \
3131
--load-weights outputs/weights.pth
3232
3333
3. To specify the algorithm of saliency map creation for classification,
@@ -48,7 +48,7 @@ For detection task, we can choose between the following methods:
4848

4949

5050
4. As a result we will get a folder with a pair of generated
51-
images for each image in ``--explain-data-roots``:
51+
images for each image in ``--input``:
5252

5353
- saliency map - where red color means more attention of the model
5454
- overlay - where the saliency map is combined with the original image:

src/otx/cli/tools/explain.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ def get_args():
5050
parser, hyper_parameters, params = get_parser_and_hprams_data()
5151

5252
parser.add_argument(
53-
"--explain-data-roots",
53+
"-i",
54+
"--input",
5455
required=True,
5556
help="Comma-separated paths to explain data folders.",
5657
)
5758
parser.add_argument(
58-
"--save-explanation-to",
59+
"-o",
60+
"--output",
5961
default="saliency_dump",
6062
help="Output path for explanation images.",
6163
)
@@ -123,10 +125,7 @@ def _log_after_saving(explain_predicted_classes, explained_image_counter, args,
123125
"Please adjust training pipeline or use different model-data pair."
124126
)
125127
if explained_image_counter > 0:
126-
logger.info(
127-
f"Saliency maps saved to {args.save_explanation_to} for {explained_image_counter} "
128-
f"out of {num_images} images."
129-
)
128+
logger.info(f"Saliency maps saved to {args.output} for {explained_image_counter} out of {num_images} images.")
130129

131130

132131
def main():
@@ -169,10 +168,10 @@ def main():
169168
f"{args.explain_algorithm} currently not supported. \
170169
Currently only support {SUPPORTED_EXPLAIN_ALGORITHMS}"
171170
)
172-
if not Path(args.save_explanation_to).exists():
173-
Path(args.save_explanation_to).mkdir(parents=True)
171+
if not Path(args.output).exists():
172+
Path(args.output).mkdir(parents=True)
174173

175-
image_files = get_image_files(args.explain_data_roots)
174+
image_files = get_image_files(args.input)
176175
dataset_to_explain = get_explain_dataset_from_filelist(image_files)
177176
explain_predicted_classes = not args.explain_all_classes
178177
explain_parameters = ExplainParameters(
@@ -201,7 +200,7 @@ def main():
201200
process_saliency_maps=explain_parameters.process_saliency_maps,
202201
img=explained_data.numpy,
203202
saliency_map=saliency_data.numpy,
204-
save_dir=args.save_explanation_to,
203+
save_dir=args.output,
205204
fname=fname,
206205
weight=args.overlay_weight,
207206
)

src/otx/cli/tools/utils/demo/visualization.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def draw_masks(frame: Mat, predictions, put_object_count: bool = False):
7171
cv2.drawContours(frame, contours, -1, color, 1)
7272
rect = cv2.boundingRect(contours[0])
7373
cv2.rectangle(frame, (rect[0], rect[1]), (rect[0] + rect[2], rect[1] + rect[3]), color, 1)
74-
put_text_on_rect_bg(frame, label.name, (rect[0], rect[1]), color=color)
74+
put_text_on_rect_bg(frame, f"{label.name} {label.probability*100:.1f}%", (rect[0], rect[1]), color=color)
7575
cv2.bitwise_or(aggregated_mask, mask, dst=aggregated_mask)
7676
cv2.bitwise_or(
7777
aggregated_colored_mask,
@@ -110,7 +110,7 @@ def put_labels(frame: Mat, predictions: List[Annotation]):
110110
assert len(predictions[0].get_labels()) == 1
111111
label = predictions[0].get_labels()[0]
112112
color = tuple(getattr(label.color, x) for x in ("blue", "green", "red"))
113-
put_text_on_rect_bg(frame, label.name, (0, 0), color=color)
113+
put_text_on_rect_bg(frame, f"{label.name} {label.probability*100:.1f}%", (0, 0), color=color)
114114
return frame
115115

116116

@@ -129,7 +129,7 @@ def draw_bounding_boxes(frame: Mat, predictions: List[Annotation], put_object_co
129129
label = prediction.get_labels()[0]
130130
color = tuple(getattr(label.color, x) for x in ("blue", "green", "red"))
131131
cv2.rectangle(frame, (x1, y1), (x2, y2), color, thickness=2)
132-
put_text_on_rect_bg(frame, label.name, (x1, y1), color=color)
132+
put_text_on_rect_bg(frame, f"{label.name} {label.probability*100:.1f}%", (x1, y1), color=color)
133133
else:
134134
warn(
135135
f"Predictions called on Annotations with shape {type(prediction.shape)}."

tests/test_suite/run_test_command.py

+26-26
Original file line numberDiff line numberDiff line change
@@ -859,16 +859,16 @@ def otx_explain_testing(template, root, otx_dir, args, trained=False):
859859

860860
save_dir = f"explain_{template.model_template_id}/{test_algorithm}/{train_type}/"
861861
output_dir = os.path.join(template_work_dir, save_dir)
862-
explain_data_root = os.path.join(otx_dir, args["--input"])
862+
data_input = os.path.join(otx_dir, args["--input"])
863863
command_line = [
864864
"otx",
865865
"explain",
866866
template.model_template_path,
867867
"--load-weights",
868868
weights_path,
869-
"--explain-data-root",
870-
explain_data_root,
871-
"--save-explanation-to",
869+
"--input",
870+
data_input,
871+
"--output",
872872
output_dir,
873873
"--explain-algorithm",
874874
test_algorithm,
@@ -899,16 +899,16 @@ def otx_explain_testing_all_classes(template, root, otx_dir, args):
899899

900900
save_dir = f"explain_all_classes_{template.model_template_id}/{test_algorithm}/{train_type}/"
901901
output_dir = os.path.join(template_work_dir, save_dir)
902-
explain_data_root = os.path.join(otx_dir, args["--input"])
902+
data_input = os.path.join(otx_dir, args["--input"])
903903
command_line = [
904904
"otx",
905905
"explain",
906906
template.model_template_path,
907907
"--load-weights",
908908
weights_path,
909-
"--explain-data-root",
910-
explain_data_root,
911-
"--save-explanation-to",
909+
"--input",
910+
data_input,
911+
"--output",
912912
output_dir,
913913
"--explain-algorithm",
914914
test_algorithm,
@@ -923,7 +923,7 @@ def otx_explain_testing_all_classes(template, root, otx_dir, args):
923923
assert len(os.listdir(output_dir)) == len(os.listdir(output_dir_explain_only_predicted_classes))
924924
else:
925925
assert len(os.listdir(output_dir)) >= len(os.listdir(output_dir_explain_only_predicted_classes))
926-
assert all([os.path.splitext(fname)[1] == ".tiff" for fname in os.listdir(output_dir)])
926+
assert all([os.path.splitext(fname)[1] in [".tiff", ".log"] for fname in os.listdir(output_dir)])
927927

928928

929929
def otx_explain_testing_process_saliency_maps(template, root, otx_dir, args, trained=False):
@@ -945,16 +945,16 @@ def otx_explain_testing_process_saliency_maps(template, root, otx_dir, args, tra
945945

946946
save_dir = f"explain_process_saliency_maps_{template.model_template_id}/{test_algorithm}/{train_type}/"
947947
output_dir = os.path.join(template_work_dir, save_dir)
948-
explain_data_root = os.path.join(otx_dir, args["--input"])
948+
data_input = os.path.join(otx_dir, args["--input"])
949949
command_line = [
950950
"otx",
951951
"explain",
952952
template.model_template_path,
953953
"--load-weights",
954954
weights_path,
955-
"--explain-data-root",
956-
explain_data_root,
957-
"--save-explanation-to",
955+
"--input",
956+
data_input,
957+
"--output",
958958
output_dir,
959959
"--explain-algorithm",
960960
test_algorithm,
@@ -986,16 +986,16 @@ def otx_explain_openvino_testing(template, root, otx_dir, args, trained=False):
986986

987987
save_dir = f"explain_ov_{template.model_template_id}/{test_algorithm}/{train_type}/"
988988
output_dir = os.path.join(template_work_dir, save_dir)
989-
explain_data_root = os.path.join(otx_dir, args["--input"])
989+
data_input = os.path.join(otx_dir, args["--input"])
990990
command_line = [
991991
"otx",
992992
"explain",
993993
template.model_template_path,
994994
"--load-weights",
995995
weights_path,
996-
"--explain-data-root",
997-
explain_data_root,
998-
"--save-explanation-to",
996+
"--input",
997+
data_input,
998+
"--output",
999999
output_dir,
10001000
"--explain-algorithm",
10011001
test_algorithm,
@@ -1027,16 +1027,16 @@ def otx_explain_all_classes_openvino_testing(template, root, otx_dir, args):
10271027

10281028
save_dir = f"explain_ov_all_classes_{template.model_template_id}/{test_algorithm}/{train_type}/"
10291029
output_dir = os.path.join(template_work_dir, save_dir)
1030-
explain_data_root = os.path.join(otx_dir, args["--input"])
1030+
data_input = os.path.join(otx_dir, args["--input"])
10311031
command_line = [
10321032
"otx",
10331033
"explain",
10341034
template.model_template_path,
10351035
"--load-weights",
10361036
weights_path,
1037-
"--explain-data-root",
1038-
explain_data_root,
1039-
"--save-explanation-to",
1037+
"--input",
1038+
data_input,
1039+
"--output",
10401040
output_dir,
10411041
"--explain-algorithm",
10421042
test_algorithm,
@@ -1052,7 +1052,7 @@ def otx_explain_all_classes_openvino_testing(template, root, otx_dir, args):
10521052
assert len(os.listdir(output_dir)) == len(os.listdir(output_dir_explain_only_predicted_classes))
10531053
else:
10541054
assert len(os.listdir(output_dir)) >= len(os.listdir(output_dir_explain_only_predicted_classes))
1055-
assert all([os.path.splitext(fname)[1] == ".tiff" for fname in os.listdir(output_dir)])
1055+
assert all([os.path.splitext(fname)[1] in [".tiff", ".log"] for fname in os.listdir(output_dir)])
10561056

10571057

10581058
def otx_explain_process_saliency_maps_openvino_testing(template, root, otx_dir, args, trained=False):
@@ -1074,16 +1074,16 @@ def otx_explain_process_saliency_maps_openvino_testing(template, root, otx_dir,
10741074

10751075
save_dir = f"explain_ov_process_saliency_maps_{template.model_template_id}/{test_algorithm}/{train_type}/"
10761076
output_dir = os.path.join(template_work_dir, save_dir)
1077-
explain_data_root = os.path.join(otx_dir, args["--input"])
1077+
data_input = os.path.join(otx_dir, args["--input"])
10781078
command_line = [
10791079
"otx",
10801080
"explain",
10811081
template.model_template_path,
10821082
"--load-weights",
10831083
weights_path,
1084-
"--explain-data-root",
1085-
explain_data_root,
1086-
"--save-explanation-to",
1084+
"--input",
1085+
data_input,
1086+
"--output",
10871087
output_dir,
10881088
"--explain-algorithm",
10891089
test_algorithm,

0 commit comments

Comments
 (0)