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

Ayermolo/yolo v3 fused batch #1122

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Added basic layers so that Yolo V3 can be saved as TF. Still won't be…
… able to run it, since post processing is different.
  • Loading branch information
Alexander Yermolovich committed Jan 10, 2020
commit 631ad9f7af47c295dd56d898a7dcf3e1003982ea
12 changes: 11 additions & 1 deletion darkflow/dark/darkop.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ class reorg_layer(Layer):
def setup(self, stride):
self.stride = stride

class shortcut_layer(Layer):
def setup(self, frmLayer):
self.frmLayer = frmLayer

class upsample_layer(Layer):
def setup(self, strd):
self.strd = strd

"""
Darkop Factory
"""
Expand All @@ -52,7 +60,9 @@ def setup(self, stride):
'reorg': reorg_layer,
'conv-select': conv_select_layer,
'conv-extract': conv_extract_layer,
'extract': extract_layer
'extract': extract_layer,
'shortcut' : shortcut_layer,
'upsample' : upsample_layer,
}

def create_darkop(ltype, num, *args):
Expand Down
5 changes: 4 additions & 1 deletion darkflow/net/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
'route': route,
'reorg': reorg,
'conv-extract': conv_extract,
'extract': extract
'extract': extract,
'shortcut' : shortcut,
'yolo' : yolo,
'upsample' : upsample,
}

def op_create(*args):
Expand Down
30 changes: 30 additions & 0 deletions darkflow/net/ops/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,33 @@ class identity(BaseOp):
def __init__(self, inp):
self.inp = None
self.out = inp

class shortcut(BaseOp):
def forward(self):
inp = self.inp.out
frm = self.lay.frmLayer
this = self.inp
while this.lay.number != frm:
this = this.inp
assert this is not None, \
'Shortcut to non-existence {}'.format(frm)
self.out = inp + this.out

def speak(self): return 'shortcut'

class yolo(BaseOp):
def forward(self):
inp = self.inp.out
self.out = inp

def speak(self): return 'yolo'

class upsample(BaseOp):
def forward(self):
inp = self.inp.out
strd = self.lay.strd
shape = inp.get_shape()
inp = tf.image.resize_nearest_neighbor(inp, (shape[1] * strd, shape[2] * strd))
self.out = inp

def speak(self): return 'upsample'
11 changes: 11 additions & 0 deletions darkflow/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,17 @@ def cfg_yielder(model, binary):
c = c * (stride ** 2)
l = w * h * c
#-----------------------------------------------------
elif d['type'] == '[shortcut]':
frm = d['from']
yield ['shortcut', i, i + frm]
elif d['type'] == '[yolo]':
yield ['yolo', i]
elif d['type'] == '[upsample]':
strd = d['stride']
ly = layers[i]
h *= strd
w *= strd
yield ['upsample', i, strd]
else:
exit('Layer {} not implemented'.format(d['type']))

Expand Down