This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blocks = parse_cfg(cfgfile) | |
details,modules = model_initialization(blocks) | |
modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modulelist.append(seq) | |
output_filters.append(filters) | |
channels = filters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DetectionLayer(nn.Module): | |
def __init__(self, anchors): | |
super(DetectionLayer, self).__init__() | |
self.anchors = anchors |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |