8000 Fixed keyword argument issue with Pad by piyush-J · Pull Request #46 · Talmaj/onnx2pytorch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixed keyword argument issue with Pad #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion onnx2pytorch/convert/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ def extract_attributes(node):
elif attr.name == "transA":
kwargs["transpose_activation"] = bool(extract_attr_values(attr))
elif attr.name == "value":
kwargs["constant"] = extract_attr_values(attr)
if node.op_type == "Pad":
kwargs["value"] = extract_attr_values(attr)
else:
kwargs["constant"] = extract_attr_values(attr)
elif attr.name == "value_float":
kwargs["constant"] = extract_attr_values(attr)
elif attr.name == "value_floats":
Expand Down
4 changes: 4 additions & 0 deletions onnx2pytorch/convert/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from torch import nn
from torch.jit import TracerWarning
from torch.nn.modules.linear import Identity
from torch.nn import Dropout

from onnx2pytorch.constants import (
COMPOSITE_LAYERS,
Expand Down Expand Up @@ -221,6 +222,9 @@ def forward(self, *input_list, **input_dict):
for out_op_id, output in zip(node.output, op(*in_activations)):
activations[out_op_id] = output
else:
if 'dropout' in out_op_id:
op = Dropout()

activations[out_op_id] = op(*in_activations)

# Remove activations that are no longer needed
Expand Down
7 changes: 5 additions & 2 deletions onnx2pytorch/operations/pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@


class Pad(Operator):
def __init__(self, mode="constant", padding=None):
def __init__(self, mode="constant", padding=None, value=0):
self.mode = mode
self.padding = padding
self.value = value
super().__init__()

def forward(self, input, pads=None, value=0):
def forward(self, input, pads=None, value=None):
if value is None:
value = self.value
if self.padding is not None:
pads = self.padding
elif pads is None:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ torchvision>=0.9.0
onnx>=1.6.0
onnxruntime>=1.5.0
numpy>=1.18.1
protobuf==3.20.0
0