Skip to content

Commit

Permalink
Fix unit tests for Relay padding layer translation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jornt-xilinx committed Apr 27, 2021
1 parent f69c345 commit bc290a5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,12 @@ def test_padding(self):
xg = xf_relay.from_relay(mod, {})
layers = xg.get_layers()

assert len(layers) == 3
assert len(layers) == 2

assert layers[0].type[0] == "Constant"
assert layers[0].type[0] == "Input"
assert "relay_id" in layers[0].attrs

assert layers[1].type[0] == "Input"
assert "relay_id" in layers[1].attrs

X = layers[2]
X = layers[1]
assert X.type[0] == "Pad"
assert X.bottoms == ["var"]
assert X.shapes == [-1, 2, 5, 5]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def test_reshape(self):
# 1
c = relay.expr.const(np.ones((2, 3, 4), dtype=np.float32))
net = relay.reshape(c, (4, 0, 2))
net = relay.Tuple([net])
net = relay.Function([], net)
mod = tvm.IRModule.from_expr(net)
mod = relay.transform.InferType()(mod)
Expand All @@ -188,6 +189,7 @@ def test_reshape(self):
# 2
c = relay.expr.const(np.ones((2, 3, 4), dtype=np.float32))
net = relay.reshape(c, (6, 1, -1))
net = relay.Tuple([net])
net = relay.Function([], net)
mod = tvm.IRModule.from_expr(net)
mod = relay.transform.InferType()(mod)
Expand All @@ -201,6 +203,7 @@ def test_reshape(self):
# 3
c = relay.expr.const(np.ones((2, 3, 4), dtype=np.float32))
net = relay.reshape(c, (-2,))
net = relay.Tuple([net])
net = relay.Function([], net)
mod = tvm.IRModule.from_expr(net)
mod = relay.transform.InferType()(mod)
Expand All @@ -214,6 +217,7 @@ def test_reshape(self):
# 4
c = relay.expr.const(np.ones((2, 3, 4, 5), dtype=np.float32))
net = relay.reshape(c, (-3, -3))
net = relay.Tuple([net])
net = relay.Function([], net)
mod = tvm.IRModule.from_expr(net)
mod = relay.transform.InferType()(mod)
Expand Down Expand Up @@ -343,7 +347,7 @@ def test_transpose_constant(self):
data = relay.var("data", relay.TensorType((1, 3, 2, 2), "float32"))

net = relay.transpose(data, axes=(0, 2, 3, 1))

net = relay.Tuple([net])
net = relay.Function(relay.analysis.free_vars(net), net)

mod = tvm.IRModule.from_expr(net)
Expand Down
47 changes: 23 additions & 24 deletions tests/unit/frontend/tvm/test_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,17 @@ def test_simple_network(self):

layers = xgraph.get_layers()

assert layers[0].type[0] == "Constant"
assert layers[1].type[0] == "Input"
assert layers[2].type[0] == "Pad"
assert layers[3].type[0] == "Convolution"
assert layers[4].type[0] == "BatchNorm"
assert layers[5].type[0] == "ReLU"
assert layers[6].type[0] == "Mean"
assert layers[7].type[0] == "Reshape"
assert layers[8].type[0] == "Dense"
assert layers[9].type[0] == "BiasAdd"
assert layers[10].type[0] == "Softmax"
assert layers[11].type[0] == "Reshape"
assert layers[0].type[0] == "Input"
assert layers[1].type[0] == "Pad"
assert layers[2].type[0] == "Convolution"
assert layers[3].type[0] == "BatchNorm"
assert layers[4].type[0] == "ReLU"
assert layers[5].type[0] == "Mean"
assert layers[6].type[0] == "Reshape"
assert layers[7].type[0] == "Dense"
assert layers[8].type[0] == "BiasAdd"
assert layers[9].type[0] == "Softmax"
assert layers[10].type[0] == "Reshape"

@unittest.skipIf(skip, "Could not import TVM and/or TVM frontend")
def test_simple_network_cvx(self):
Expand Down Expand Up @@ -118,18 +117,18 @@ def test_simple_network_cvx(self):
assert len(xgraph.get_input_names()) == 1
layers = xgraph.get_layers()

assert layers[0].type[0] == "Constant"
assert layers[1].type[0] == "StrInput"
assert layers[1].shapes == [-1]
assert layers[2].type[0] == "Cvx"
assert layers[2].shapes == [-1, 3, 224, 224]
assert layers[3].type[0] == "Pad"
assert layers[4].type[0] == "Convolution"
assert layers[5].type[0] == "ReLU"

assert layers[1].tops == ["data_cvx"]
assert layers[2].bottoms == ["data"]
assert layers[2].tops[0][:7] == "nn.pad-"
# assert layers[0].type[0] == "Constant"
assert layers[0].type[0] == "StrInput"
assert layers[0].shapes == [-1]
assert layers[1].type[0] == "Cvx"
assert layers[1].shapes == [-1, 3, 224, 224]
assert layers[2].type[0] == "Pad"
assert layers[3].type[0] == "Convolution"
assert layers[4].type[0] == "ReLU"

assert layers[0].tops == ["data_cvx"]
assert layers[1].bottoms == ["data"]
assert layers[1].tops[0][:7] == "nn.pad-"

@unittest.skipIf(skip, "Could not import TVM and/or TVM frontend")
def test_conv2d_transpose(self):
Expand Down
23 changes: 11 additions & 12 deletions tests/unit/frontend/tvm/test_relay_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,17 @@ def test_simple_network(self):

layers = xgraph.get_layers()

assert layers[0].type[0] == "Constant"
assert layers[1].type[0] == "Input"
assert layers[2].type[0] == "Pad"
assert layers[3].type[0] == "Convolution"
assert layers[4].type[0] == "BatchNorm"
assert layers[5].type[0] == "ReLU"
assert layers[6].type[0] == "Mean"
assert layers[7].type[0] == "Reshape"
assert layers[8].type[0] == "Dense"
assert layers[9].type[0] == "BiasAdd"
assert layers[10].type[0] == "Softmax"
assert layers[11].type[0] == "Reshape"
assert layers[0].type[0] == "Input"
assert layers[1].type[0] == "Pad"
assert layers[2].type[0] == "Convolution"
assert layers[3].type[0] == "BatchNorm"
assert layers[4].type[0] == "ReLU"
assert layers[5].type[0] == "Mean"
assert layers[6].type[0] == "Reshape"
assert layers[7].type[0] == "Dense"
assert layers[8].type[0] == "BiasAdd"
assert layers[9].type[0] == "Softmax"
assert layers[10].type[0] == "Reshape"

os.remove(json_file)
os.remove(params_file)

0 comments on commit bc290a5

Please sign in to comment.