Skip to content
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

[Frontend][Relay][Parser] fix unparsable yolo formals #6963

Merged
merged 3 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion python/tvm/relay/frontend/darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _darknet_not_support(attr, op="relay"):

def _get_params_prefix(opname, layer_num):
"""Makes the params prefix name from opname and layer number."""
return str(opname) + str(layer_num)
return str(opname).replace(".", "_") + str(layer_num)


def _get_params_name(prefix, item):
Expand Down
51 changes: 48 additions & 3 deletions tests/python/relay/test_ir_text_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import numpy as np
from tvm.relay import Expr
from tvm.relay.analysis import free_vars
import pytest
import sys

DEBUG_PRINT = False

Expand All @@ -46,6 +48,46 @@ def show(text):
print(text)


def get_darknet(model_name):
hypercubestart marked this conversation as resolved.
Show resolved Hide resolved
from tvm.contrib.download import download_testdata
from tvm.relay.testing.darknet import __darknetffi__
import tvm.relay.testing.yolo_detection
import tvm.relay.testing.darknet

CFG_NAME = model_name + ".cfg"
WEIGHTS_NAME = model_name + ".weights"
REPO_URL = "https://github.com/dmlc/web-data/blob/main/darknet/"
CFG_URL = REPO_URL + "cfg/" + CFG_NAME + "?raw=true"
WEIGHTS_URL = "https://pjreddie.com/media/files/" + WEIGHTS_NAME

cfg_path = download_testdata(CFG_URL, CFG_NAME, module="darknet")
weights_path = download_testdata(WEIGHTS_URL, WEIGHTS_NAME, module="darknet")

# Download and Load darknet library
if sys.platform in ["linux", "linux2"]:
DARKNET_LIB = "libdarknet2.0.so"
DARKNET_URL = REPO_URL + "lib/" + DARKNET_LIB + "?raw=true"
elif sys.platform == "darwin":
DARKNET_LIB = "libdarknet_mac2.0.so"
DARKNET_URL = REPO_URL + "lib_osx/" + DARKNET_LIB + "?raw=true"
else:
err = "Darknet lib is not supported on {} platform".format(sys.platform)
raise NotImplementedError(err)

lib_path = download_testdata(DARKNET_URL, DARKNET_LIB, module="darknet")

DARKNET_LIB = __darknetffi__.dlopen(lib_path)
net = DARKNET_LIB.load_network(cfg_path.encode("utf-8"), weights_path.encode("utf-8"), 0)
dtype = "float32"
batch_size = 1

data = np.empty([batch_size, net.c, net.h, net.w], dtype)
shape_dict = {"data": data.shape}
mod, params = relay.frontend.from_darknet(net, dtype=dtype, shape=data.shape)
mod = relay.transform.InferType()(mod)
return mod, params


def test_func():
x = relay.var("x", shape=(3, 2))
y = relay.var("y")
Expand Down Expand Up @@ -190,6 +232,11 @@ def test_densenet():
astext(net)


def test_yolov3():
net, _ = get_darknet("yolov3")
astext(net)


def test_call_node_order():
x = relay.var("x")
y = relay.var("y")
Expand Down Expand Up @@ -269,6 +316,4 @@ def test_span():


if __name__ == "__main__":
import sys

pytext.argv(sys.argv)
pytest.main(sys.argv)