Skip to content

Commit

Permalink
CI test file updated & CI error fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
siju-samuel committed Apr 17, 2019
1 parent c1785ff commit 1987bec
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 178 deletions.
1 change: 0 additions & 1 deletion nnvm/python/nnvm/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
from . import inception_v3
from . import dcgan
from . import dqn
from . import yolo_detection
from . import check_computation
4 changes: 2 additions & 2 deletions nnvm/tests/python/frontend/darknet/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from tvm.contrib.download import download_testdata
download_testdata.__test__ = False
from nnvm import frontend
from nnvm.testing.darknet import LAYERTYPE
from nnvm.testing.darknet import __darknetffi__
from tvm.relay.testing.darknet import LAYERTYPE
from tvm.relay.testing.darknet import __darknetffi__
import nnvm.compiler

DARKNET_LIB = 'libdarknet2.0.so'
Expand Down
16 changes: 8 additions & 8 deletions nnvm/tutorials/from_darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@

import nnvm
import nnvm.frontend.darknet
import nnvm.testing.yolo_detection
import nnvm.testing.darknet
import tvm.relay.testing.yolo_detection
import tvm.relay.testing.darknet
import matplotlib.pyplot as plt
import numpy as np
import tvm
import sys

from ctypes import *
from tvm.contrib.download import download_testdata
from nnvm.testing.darknet import __darknetffi__
from tvm.relay.testing.darknet import __darknetffi__

# Model name
MODEL_NAME = 'yolov3'
Expand Down Expand Up @@ -104,7 +104,7 @@
test_image + '?raw=true'
img_path = download_testdata(img_url, test_image, "data")

data = nnvm.testing.darknet.load_image(img_path, netw, neth)
data = tvm.relay.testing.darknet.load_image(img_path, netw, neth)
######################################################################
# Execute on TVM Runtime
# ----------------------
Expand Down Expand Up @@ -153,12 +153,12 @@
# do the detection and bring up the bounding boxes
thresh = 0.5
nms_thresh = 0.45
img = nnvm.testing.darknet.load_image_color(test_image)
img = tvm.relay.testing.darknet.load_image_color(test_image)
_, im_h, im_w = img.shape
dets = nnvm.testing.yolo_detection.fill_network_boxes((netw, neth), (im_w, im_h), thresh,
dets = tvm.relay.testing.yolo_detection.fill_network_boxes((netw, neth), (im_w, im_h), thresh,
1, tvm_out)
last_layer = net.layers[net.n - 1]
nnvm.testing.yolo_detection.do_nms_sort(dets, last_layer.classes, nms_thresh)
tvm.relay.testing.yolo_detection.do_nms_sort(dets, last_layer.classes, nms_thresh)

coco_name = 'coco.names'
coco_url = 'https://github.com/siju-samuel/darknet/blob/master/data/' + coco_name + '?raw=true'
Expand All @@ -172,6 +172,6 @@

names = [x.strip() for x in content]

nnvm.testing.yolo_detection.draw_detections(img, dets, thresh, names, last_layer.classes)
tvm.relay.testing.yolo_detection.draw_detections(img, dets, thresh, names, last_layer.classes)
plt.imshow(img.transpose(1, 2, 0))
plt.show()
68 changes: 22 additions & 46 deletions python/tvm/relay/frontend/darknet.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, 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.
# pylint: disable=unused-argument
"""
DarkNet symbol frontend for Relay.
Expand Down Expand Up @@ -61,15 +77,6 @@ def _darknet_avgpooling(inputs, params, attrs, prefix):
new_attrs['padding'] = (pads, pads)
return get_relay_op('avg_pool2d')(*inputs, **new_attrs)

def _darknet_batch_norm(inputs, params, attrs, prefix):
"""Process the batchnormalization operation."""
new_attrs = {}
new_attrs['axis'] = attrs.get('axis', 1)
new_attrs['epsilon'] = attrs.get('eps', 0.000001)
new_attrs['center'] = True
new_attrs['scale'] = True
return get_relay_op('batch_norm')(*inputs, **new_attrs)

def _darknet_conv2d(inputs, params, attrs, prefix):
"""Process the convolution 2d operation."""
new_attrs = {}
Expand All @@ -85,14 +92,14 @@ def _darknet_conv2d(inputs, params, attrs, prefix):
new_attrs['groups'] = attrs.get('num_group', 1)

weight = _get_param_var(params, prefix, 'weight')
out = get_relay_op('conv2d')(*inputs, weight, **new_attrs)
out = get_relay_op('conv2d')(*inputs, weight=weight, **new_attrs)

use_bias = not attrs.get('use_batchNorm', False)
if use_bias:
new_attrs = {}
new_attrs['axis'] = 1
bias = _get_param_var(params, prefix, 'bias')
out = get_relay_op('bias_add')(out, bias, **new_attrs)
out = get_relay_op('bias_add')(out, bias=bias, **new_attrs)
else:
new_attrs = {}
new_attrs['epsilon'] = 0.000001
Expand All @@ -109,32 +116,6 @@ def _darknet_conv2d(inputs, params, attrs, prefix):
out = _darknet_activations(out, None, new_attrs)
return out

def _darknet_conv2d_transpose(inputs, params, attrs, prefix):
"""Process the convolution 2d transpose operation."""
new_attrs = {}
kernel = attrs.get('kernel')
strides = attrs.get('stride', 1)
pads = attrs.get('pad', 0)

new_attrs['channels'] = attrs.get('num_filter')
new_attrs['kernel_size'] = (kernel, kernel)
new_attrs['strides'] = (strides, strides)
new_attrs['padding'] = (pads, pads)
new_attrs['dilation'] = attrs.get('dilate', (1, 1))
new_attrs['groups'] = attrs.get('num_group', 1)
new_attrs['output_padding'] = attrs.get('adj', (0, 0))

weight = _get_param_var(params, prefix, 'weight')
out = get_relay_op('conv2d_transpose')(*inputs, weight, **new_attrs)

use_bias = not attrs.get(attrs, 'no_bias')
if use_bias:
new_attrs = {}
new_attrs['axis'] = 1
bias = _get_param_var(params, prefix, 'bias')
out = get_relay_op('bias_add')(out, bias, **new_attrs)
return out

def _darknet_shortcut(inputs, params, attrs, prefix):
"""Process the shortcut operation."""
input_0 = inputs[0]
Expand Down Expand Up @@ -266,12 +247,8 @@ def _darknet_region(inputs, params, attrs, prefix):
split_indices = (2, 4, 5)
split_res = get_relay_op('split')(data_block, indices_or_sections=split_indices, axis=2)
split_res0 = get_relay_op('sigmoid')(split_res[0])
if not background:
split_res2 = get_relay_op('sigmoid')(split_res[2])
else:
split_res2 = split_res[2]
if softmax:
split_res3 = get_relay_op('softmax')(split_res[3], axis=2)
split_res2 = split_res[2] if background else get_relay_op('sigmoid')(split_res[2])
split_res3 = get_relay_op('softmax')(split_res[3], axis=2) if softmax else split_res[3]
out = get_relay_op('concatenate')((split_res0, split_res[1], split_res2, split_res3), axis=2)
return get_relay_op('reshape')(out, newshape=input_shape)

Expand Down Expand Up @@ -385,20 +362,20 @@ class LAYERTYPE(Enum):

_DARKNET_CONVERT_MAP = {
LAYERTYPE.CONVOLUTIONAL : _darknet_conv2d,
LAYERTYPE.DECONVOLUTIONAL : _darknet_conv2d_transpose,
LAYERTYPE.CONNECTED : _darknet_dense,
LAYERTYPE.MAXPOOL : _darknet_maxpooling,
LAYERTYPE.SOFTMAX : _darknet_softmax_output,
LAYERTYPE.DROPOUT : _darknet_dropout,
LAYERTYPE.AVGPOOL : _darknet_avgpooling,
LAYERTYPE.BATCHNORM : _darknet_batch_norm,
LAYERTYPE.ROUTE : _darknet_route,
LAYERTYPE.REORG : _darknet_reorg,
LAYERTYPE.REGION : _darknet_region,
LAYERTYPE.SHORTCUT : _darknet_shortcut,
LAYERTYPE.UPSAMPLE : _darknet_upsampling,
LAYERTYPE.L2NORM : _darknet_l2normalize,
LAYERTYPE.YOLO : _darknet_yolo,
LAYERTYPE.DECONVOLUTIONAL : _darknet_not_support,
LAYERTYPE.BATCHNORM : _darknet_not_support,
LAYERTYPE.DETECTION : _darknet_not_support,
LAYERTYPE.CROP : _darknet_not_support,
LAYERTYPE.COST : _darknet_not_support,
Expand Down Expand Up @@ -757,7 +734,6 @@ def _handle_darknet_rnn_layers(self, layer_num, sym):
attr.update({'n' : layer.n})
attr.update({'batch' : layer.batch})
attr.update({'num_hidden' : str(layer.outputs)})

state = self._get_rnn_state_buffer(layer, 'rnn')
for _ in range(layer.steps):
input_layer = layer.input_layer
Expand Down
1 change: 1 addition & 0 deletions python/tvm/relay/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from . import squeezenet
from . import vgg
from . import densenet
from . import yolo_detection

from .config import ctx_list
from .init import create_workload
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1987bec

Please sign in to comment.