Skip to content

Instantly share code, notes, and snippets.

View arunm8489's full-sized avatar

Arun Mohan arunm8489

View GitHub Profile
def detection_preprocess(x,inp_dim,anchors,num_classes,CUDA=False):
"""
This function will take input_dimension_of_image,anchors and number of classes as input
"""
# x --> 4D feature map
batch_size = x.size(0)
grid_size = x.size(2)
stride = inp_dim // x.size(2) # factor by which current feature map reduced from input
#grid_size = inp_dim // stride
elif module_type == 'yolo':
anchors = self.module_list[i][0].anchors
#Get the input dimensions
inp_dim = int(self.net_info["height"])
#Get the number of classes
num_classes = int(module["classes"])
#Transform
x = x.data # get the data at that point
if module_type == "convolutional" or module_type == "upsample":
x = self.module_list[i](x)
outputs[i] = x
elif module_type == "route":
layers = module["layers"]
layers = [int(a) for a in layers]
if len(layers) == 1:
x = outputs[layers[0]]
if len(layers) > 1:
def forward(self, x, CUDA=False):
modules = self.blocks[1:]
#We cache the outputs for the route layer
outputs = {}
write = 0
for i, module in enumerate(modules):
module_type = (module["type"])
class Darknet(nn.Module):
def __init__(self, cfgfile):
super(Darknet, self).__init__()
self.blocks = parse_cfg(cfgfile)
self.net_info, self.module_list = model_initialization(self.blocks)
blocks = parse_cfg(cfgfile)
details,modules = model_initialization(blocks)
modules
class DummyLayer(nn.Module):
def __init__(self):
super(DummyLayer, self).__init__()
class DetectionLayer(nn.Module):
def __init__(self, anchors):
super(DetectionLayer, self).__init__()
self.anchors = anchors
modulelist.append(seq)
output_filters.append(filters)
channels = filters
class DetectionLayer(nn.Module):
def __init__(self, anchors):
super(DetectionLayer, self).__init__()
self.anchors = anchors
elif block["type"] == "yolo":
mask = block["mask"].split(",")
mask = [int(m) for m in mask]
anchors = block["anchors"].split(",")
anchors = [(int(anchors[i]), int(anchors[i + 1])) for i in range(0, len(anchors), 2)]
anchors = [anchors[i] for i in mask]
block["anchors"] = anchors
detectorLayer = DetectionLayer(anchors)
seq.add_module("Detection_{0}".format(i),detectorLayer)