Skip to content

Commit

Permalink
Add yolov3-tiny to the tutorial. (#3674)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbalint13 authored and tmoreau89 committed Jul 31, 2019
1 parent f0b4c46 commit 5968eef
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tutorials/frontend/from_darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
import tvm.relay.testing.yolo_detection
import tvm.relay.testing.darknet

######################################################################
# Choose the model
# -----------------------
# Models are: 'yolov2', 'yolov3' or 'yolov3-tiny'

# Model name
MODEL_NAME = 'yolov3'

Expand Down Expand Up @@ -124,6 +129,11 @@
# execute
print("Running the test image...")

# detection
# thresholds
thresh = 0.5
nms_thresh = 0.45

m.run()
# get outputs
tvm_out = []
Expand Down Expand Up @@ -155,9 +165,22 @@
layer_out['classes'] = layer_attr[4]
tvm_out.append(layer_out)

elif MODEL_NAME == 'yolov3-tiny':
for i in range(2):
layer_out = {}
layer_out['type'] = 'Yolo'
# Get the yolo layer attributes (n, out_c, out_h, out_w, classes, total)
layer_attr = m.get_output(i*4+3).asnumpy()
layer_out['biases'] = m.get_output(i*4+2).asnumpy()
layer_out['mask'] = m.get_output(i*4+1).asnumpy()
out_shape = (layer_attr[0], layer_attr[1]//layer_attr[0],
layer_attr[2], layer_attr[3])
layer_out['output'] = m.get_output(i*4).asnumpy().reshape(out_shape)
layer_out['classes'] = layer_attr[4]
tvm_out.append(layer_out)
thresh = 0.560

# do the detection and bring up the bounding boxes
thresh = 0.5
nms_thresh = 0.45
img = tvm.relay.testing.darknet.load_image_color(img_path)
_, im_h, im_w = img.shape
dets = tvm.relay.testing.yolo_detection.fill_network_boxes((netw, neth), (im_w, im_h), thresh,
Expand Down

2 comments on commit 5968eef

@apivovarov
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbalint13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbalint13 Looks like we also need to add yolov3-tiny cfg and weight files to https://github.com/dmlc/web-data/tree/main/darknet/cfg
Related discussion https://discuss.tvm.apache.org/t/yolov2-tutorial-overflowerror/10495

I tried once , no response received: dmlc/web-data#201

Please sign in to comment.