Skip to content

Commit

Permalink
Fixed Dropout logic when is_test == 1 and opset < 7 (#774)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
pluradj authored Nov 10, 2020
1 parent 52fbf7b commit 7e4802c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions onnx_tf/handlers/backend/dropout.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ def _common(cls, node, **kwargs):
x = tensor_dict[node.inputs[0]]
attrs = copy.deepcopy(node.attrs)

if cls.SINCE_VERSION < 7:
if cls.SINCE_VERSION < 7 and attrs.pop("is_test", 0) == 0:
attrs["keep_prob"] = 1 - attrs.pop("ratio", 0.5)
return [cls.make_tensor_from_onnx_node(node, attrs=attrs, **kwargs)]
elif cls.SINCE_VERSION < 12 or attrs.pop("is_test", 0) == 1: # for Opset 7, 10
elif cls.SINCE_VERSION < 12 : # for Opset 7, 10
# at inference mode, is_test attribute is always set to 1
# dropout at inference mode is a no-op
return [x]
else: # for Opset 12, 13
# ratio and training_mode are optional and passed as inputs
Expand All @@ -30,7 +32,7 @@ def _common(cls, node, **kwargs):
training_mode = False # default is false
if len(node.inputs) == 3:
training_mode = tensor_dict[node.inputs[2]]

return_mask = len(node.outputs) == 2 # if there are 2 outputs, mask is requested
if ratio == 0 or training_mode is False: # Inferencing
if return_mask is True:
Expand Down

0 comments on commit 7e4802c

Please sign in to comment.