Skip to content

Commit

Permalink
convert avgpool and softmax layers, support classification mode in demo
Browse files Browse the repository at this point in the history
The conversion script supports the global average pooling (avgpool) and
softmax layers required to convert the darknet and tiny networks.
In the demo the --coco option has been replaced by the more generic
'mode'; the 'darknet' mode implements classification on the 1k Imagenet
classes.
  • Loading branch information
Banus committed Apr 19, 2017
1 parent 272ae19 commit aa993ef
Show file tree
Hide file tree
Showing 3 changed files with 1,087 additions and 37 deletions.
12 changes: 11 additions & 1 deletion create_yolo_prototxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ def max_pooling_layer(previous, name, params):
kernel_size=int(params["size"]), stride=int(params["stride"]))


def global_pooling_layer(previous, name, mode="avg"):
""" create a Global Pooling Layer """
pool = cp.Pooling.AVE if mode == "avg" else cp.Pooling.MAX
return cl.Pooling(previous, name=name, pool=pool, global_pooling=True)


def dense_layer(previous, name, params, train=False):
""" create a densse layer """
fields = dict(num_output=int(params["output"]))
Expand Down Expand Up @@ -191,6 +197,10 @@ def convert_configuration(config, train=False, loc_layer=False):
elif section == "maxpool":
layers.append(max_pooling_layer(layers[-1], "pool{0}".format(count),
params))
elif section == "avgpool":
layers.append(global_pooling_layer(layers[-1], "pool{0}".format(count)))
elif section == "softmax":
layers.append(cl.Softmax(layers[-1], name="softmax{0}".format(count)))
elif section == "connected":
count += 1
add_dense_layer(layers, count, params, train)
Expand All @@ -207,7 +217,7 @@ def convert_configuration(config, train=False, loc_layer=False):
model = caffe.NetSpec()
for layer in layers:
setattr(model, layer.fn.params["name"], layer)
model.result = layers[-1]
model.result = layers[-1]

return model

Expand Down
Loading

0 comments on commit aa993ef

Please sign in to comment.