relay.Expr
def test_print_expr():
data = relay.var("data", shape=(1, 1, 5, 5))
weight = relay.var("weight")
conv = relay.nn.conv2d(data, weight,
kernel_size=(3, 3),
padding=(1, 1),
channels=1)
z = relay.nn.relu(data=conv)
print(z)
打印出来是这样的
v0.0.4
free_var %data: Tensor[(1, 1, 5, 5), float32]
free_var %weight
%0 = nn.conv2d(%data, %weight, padding=[1, 1], channels=1, kernel_size=[3, 3]);
nn.relu(%0)
relay.Function
def test_print_function():
data = relay.var("data", shape=(1, 1, 5, 5))
weight = relay.var("weight")
conv = relay.nn.conv2d(data, weight,
kernel_size=(3, 3),
padding=(1, 1),
channels=1)
z = relay.nn.relu(data=conv)
#print(z)
f = relay.Function([data,weight],z)
print(f)
打印的结果是这样的
v0.0.4
fn (%data: Tensor[(1, 1, 5, 5), float32], %weight) {
%0 = nn.conv2d(%data, %weight, padding=[1, 1], channels=1, kernel_size=[3, 3]);
nn.relu(%0)
}
relay.Module
def test_print_function():
data = relay.var("data", shape=(1, 1, 5, 5))
weight = relay.var("weight")
conv = relay.nn.conv2d(data, weight,
kernel_size=(3, 3),
padding=(1, 1),
channels=1)
z = relay.nn.relu(data=conv)
# print(z)
# f = relay.Function([data,weight],z)
# print(f)
mod = relay.Module.from_expr(z)
print(mod.astext())
打印的结果是这样的
v0.0.4
def @main(%data: Tensor[(1, 1, 5, 5), float32], %weight: Tensor[(1, 1, 3, 3), float32]) -> Tensor[(1, 1, 5, 5), float32] {
%0 = nn.conv2d(%data, %weight, padding=[1, 1], channels=1, kernel_size=[3, 3]) /* ty=Tensor[(1, 1, 5, 5), float32] */;
nn.relu(%0) /* ty=Tensor[(1, 1, 5, 5), float32] */
}