From 0cd2379e2ccbad07bad3f88f8dc564776605802d Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Sat, 14 Nov 2015 20:34:17 +0000
Subject: [PATCH] some changes
---
src/parser.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/src/parser.c b/src/parser.c
index b095294..277c6e2 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -15,6 +15,7 @@
#include "dropout_layer.h"
#include "detection_layer.h"
#include "avgpool_layer.h"
+#include "local_layer.h"
#include "route_layer.h"
#include "list.h"
#include "option_list.h"
@@ -27,6 +28,7 @@
int is_network(section *s);
int is_convolutional(section *s);
+int is_local(section *s);
int is_deconvolutional(section *s);
int is_connected(section *s);
int is_maxpool(section *s);
@@ -107,6 +109,27 @@
return layer;
}
+local_layer parse_local(list *options, size_params params)
+{
+ int n = option_find_int(options, "filters",1);
+ int size = option_find_int(options, "size",1);
+ int stride = option_find_int(options, "stride",1);
+ int pad = option_find_int(options, "pad",0);
+ char *activation_s = option_find_str(options, "activation", "logistic");
+ ACTIVATION activation = get_activation(activation_s);
+
+ int batch,h,w,c;
+ h = params.h;
+ w = params.w;
+ c = params.c;
+ batch=params.batch;
+ if(!(h && w && c)) error("Layer before local layer must output image.");
+
+ local_layer layer = make_local_layer(batch,h,w,c,n,size,stride,pad,activation);
+
+ return layer;
+}
+
convolutional_layer parse_convolutional(list *options, size_params params)
{
int n = option_find_int(options, "filters",1);
@@ -402,6 +425,8 @@
layer l = {0};
if(is_convolutional(s)){
l = parse_convolutional(options, params);
+ }else if(is_local(s)){
+ l = parse_local(options, params);
}else if(is_deconvolutional(s)){
l = parse_deconvolutional(options, params);
}else if(is_connected(s)){
@@ -465,6 +490,10 @@
{
return (strcmp(s->type, "[detection]")==0);
}
+int is_local(section *s)
+{
+ return (strcmp(s->type, "[local]")==0);
+}
int is_deconvolutional(section *s)
{
return (strcmp(s->type, "[deconv]")==0
@@ -626,6 +655,16 @@
#endif
fwrite(l.biases, sizeof(float), l.outputs, fp);
fwrite(l.weights, sizeof(float), l.outputs*l.inputs, fp);
+ } if(l.type == LOCAL){
+#ifdef GPU
+ if(gpu_index >= 0){
+ pull_local_layer(l);
+ }
+#endif
+ int locations = l.out_w*l.out_h;
+ int size = l.size*l.size*l.c*l.n*locations;
+ fwrite(l.biases, sizeof(float), l.outputs, fp);
+ fwrite(l.filters, sizeof(float), size, fp);
}
}
fclose(fp);
@@ -686,6 +725,17 @@
}
#endif
}
+ if(l.type == LOCAL){
+ int locations = l.out_w*l.out_h;
+ int size = l.size*l.size*l.c*l.n*locations;
+ fread(l.biases, sizeof(float), l.outputs, fp);
+ fread(l.filters, sizeof(float), size, fp);
+#ifdef GPU
+ if(gpu_index >= 0){
+ push_local_layer(l);
+ }
+#endif
+ }
}
fprintf(stderr, "Done!\n");
fclose(fp);
--
Gitblit v1.10.0