Skip to content

Commit 7e4802c

Browse files
authored
Fixed Dropout logic when is_test == 1 and opset < 7 (#774)
* Fixed Dropout logic when is_test == 1 and opset < 7 A recent change incorrectly moved the is_test check later in the conditional logic, causing failures in several model zoo models, like caffenet-3 and squeezenet1.0-6. Signed-off-by: Jason Plurad <[email protected]> * Improved Dropout logic when is_test == 1 and opset < 7 Signed-off-by: Jason Plurad <[email protected]>
1 parent 52fbf7b commit 7e4802c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

onnx_tf/handlers/backend/dropout.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ def _common(cls, node, **kwargs):
1717
x = tensor_dict[node.inputs[0]]
1818
attrs = copy.deepcopy(node.attrs)
1919

20-
if cls.SINCE_VERSION < 7:
20+
if cls.SINCE_VERSION < 7 and attrs.pop("is_test", 0) == 0:
2121
attrs["keep_prob"] = 1 - attrs.pop("ratio", 0.5)
2222
return [cls.make_tensor_from_onnx_node(node, attrs=attrs, **kwargs)]
23-
elif cls.SINCE_VERSION < 12 or attrs.pop("is_test", 0) == 1: # for Opset 7, 10
23+
elif cls.SINCE_VERSION < 12 : # for Opset 7, 10
24+
# at inference mode, is_test attribute is always set to 1
25+
# dropout at inference mode is a no-op
2426
return [x]
2527
else: # for Opset 12, 13
2628
# ratio and training_mode are optional and passed as inputs
@@ -30,7 +32,7 @@ def _common(cls, node, **kwargs):
3032
training_mode = False # default is false
3133
if len(node.inputs) == 3:
3234
training_mode = tensor_dict[node.inputs[2]]
33-
35+
3436
return_mask = len(node.outputs) == 2 # if there are 2 outputs, mask is requested
3537
if ratio == 0 or training_mode is False: # Inferencing
3638
if return_mask is True:

0 commit comments

Comments
 (0)