提交 231cec63 编写于 作者: B BBuf

add pad op

上级 99483205
......@@ -37,6 +37,7 @@ class MathOps(flow.nn.Module):
math_ops = MathOps()
math_ops = math_ops.to("cuda")
class MathOpGraph(flow.nn.Graph):
def __init__(self):
super().__init__()
......@@ -50,7 +51,7 @@ class MathOpGraph(flow.nn.Graph):
def test_math_ops():
math_ops_graph = MathOpGraph()
math_ops_graph._compile(flow.randn(1, 3, 224, 224))
math_ops_graph._compile(flow.randn(1, 3, 224, 224).to("cuda"))
# print(math_ops_graph._full_graph_proto)
with tempfile.TemporaryDirectory() as tmpdirname:
......
......@@ -13,14 +13,35 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import tempfile
import oneflow as flow
import oneflow.typing as tp
from oneflow_onnx.oneflow2onnx.util import convert_to_onnx_and_check
class Pad(flow.nn.Module):
def __init__(self) -> None:
super(Pad, self).__init__()
def test_pad_float():
@flow.global_function()
def pad(x: tp.Numpy.Placeholder((3, 5))):
return flow.pad(x, [(1, 2), (3, 4)], 1)
def forward(self, x: flow.Tensor) -> flow.Tensor:
return flow.nn.functional.pad(x, (1, 1))
convert_to_onnx_and_check(pad)
pad = Pad()
class padOpGraph(flow.nn.Graph):
def __init__(self):
super().__init__()
self.m = pad
def build(self, x):
out = self.m(x)
return out
def test_pad():
pad_graph = padOpGraph()
pad_graph._compile(flow.randn(1, 3, 224, 224))
with tempfile.TemporaryDirectory() as tmpdirname:
flow.save(pad.state_dict(), tmpdirname)
convert_to_onnx_and_check(pad_graph, flow_weight_dir=tmpdirname, onnx_model_path="/tmp")
test_pad()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册