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

Compute padding when pad: 1 #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
14 changes: 10 additions & 4 deletions create_yolo_prototxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def write(self, f):

class CaffeReluLayer(CaffeLayerGenerator):
def __init__(self, name, negslope=None):
super(CaffeReluLayer, self).__init__(name, 'Relu')
super(CaffeReluLayer, self).__init__(name, 'ReLU')
self.negslope = negslope
def write(self, f):
param_str = ""
Expand Down Expand Up @@ -152,14 +152,17 @@ def add_input_layer(self, items):
self.layer = CaffeInputLayer(lname, items['channels'], items['width'], items['height'])
self.layer.top.append( lname )
self.add_layer( self.layer )
def add_convolution_layer(self, items):
def add_convolution_layer(self, items, padding=False):
self.lnum += 1
prev_blob = self.layer.top[0]
lname = "conv"+str(self.lnum)
filters = items['filters']
ksize = items['size'] if 'size' in items else None
stride = items['stride'] if 'stride' in items else None
pad = items['pad'] if 'pad' in items else None
if padding:
pad = str((int(ksize)-1)/2)
else:
pad = None
bias = not bool(items['batch_normalize']) if 'batch_normalize' in items else True
self.layer = CaffeConvolutionLayer( lname, filters, ksize=ksize, stride=stride, pad=pad, bias=bias )
self.layer.bottom.append( prev_blob )
Expand Down Expand Up @@ -251,16 +254,19 @@ def convert(cfgfile, ptxtfile):
#
batchnorm_followed = False
relu_followed = False
padding = False
items = dict(parser.items(section))
if 'batch_normalize' in items and items['batch_normalize']:
batchnorm_followed = True
if 'activation' in items and items['activation'] != 'linear':
relu_followed = True
if 'pad' in items and items['pad'] == '1':
padding = True
#
if _section == 'net':
gen.add_input_layer(items)
elif _section == 'convolutional':
gen.add_convolution_layer(items)
gen.add_convolution_layer(items, padding)
if batchnorm_followed:
gen.add_batchnorm_layer(items)
gen.add_scale_layer(items)
Expand Down