提交 90d6e441 编写于 作者: B BBuf

add activation ops

上级 e99bfb25
......@@ -13,14 +13,28 @@ 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
relu = flow.nn.ReLU()
class ReLUOpGraph(flow.nn.Graph):
def __init__(self):
super().__init__()
self.m = relu
def build(self, x):
out = self.m(x)
return out
def test_relu():
@flow.global_function()
def relu(x: tp.Numpy.Placeholder((3, 4, 2, 5))):
return flow.math.relu(x)
relu_graph = ReLUOpGraph()
relu_graph._compile(flow.randn(1, 3, 224, 224))
with tempfile.TemporaryDirectory() as tmpdirname:
flow.save(relu.state_dict(), tmpdirname)
convert_to_onnx_and_check(relu_graph, flow_weight_dir=tmpdirname, onnx_model_path="/tmp")
convert_to_onnx_and_check(relu)
test_relu()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册