Removing more conflicts

This commit is contained in:
Anup Rajput
2017-01-23 10:34:07 +05:30
parent b22a113952
commit 9dbf87a263
16 changed files with 180 additions and 89 deletions

View File

@@ -1,7 +1,7 @@
classes= 80
train = /home/pjreddie/data/coco/trainvalno5k.txt
valid = coco_testdev
#valid = data/coco_val_5k.list
#valid = coco_testdev
valid = data/coco_val_5k.list
names = data/coco.names
backup = /home/pjreddie/backup/
eval=coco

View File

@@ -2,5 +2,5 @@ classes= 20
train = /home/pjreddie/data/voc/train.txt
valid = /home/pjreddie/data/voc/2007_test.txt
names = data/voc.names
backup = /home/pjreddie/backup/
backup = backup

View File

@@ -246,6 +246,34 @@ int nms_comparator(const void *pa, const void *pb)
return 0;
}
void do_nms_obj(box *boxes, float **probs, int total, int classes, float thresh)
{
int i, j, k;
sortable_bbox *s = calloc(total, sizeof(sortable_bbox));
for(i = 0; i < total; ++i){
s[i].index = i;
s[i].class = classes;
s[i].probs = probs;
}
qsort(s, total, sizeof(sortable_bbox), nms_comparator);
for(i = 0; i < total; ++i){
if(probs[s[i].index][classes] == 0) continue;
box a = boxes[s[i].index];
for(j = i+1; j < total; ++j){
box b = boxes[s[j].index];
if (box_iou(a, b) > thresh){
for(k = 0; k < classes+1; ++k){
probs[s[j].index][k] = 0;
}
}
}
}
free(s);
}
void do_nms_sort(box *boxes, float **probs, int total, int classes, float thresh)
{
int i, j, k;

View File

@@ -15,6 +15,7 @@ float box_rmse(box a, box b);
dbox diou(box a, box b);
void do_nms(box *boxes, float **probs, int total, int classes, float thresh);
void do_nms_sort(box *boxes, float **probs, int total, int classes, float thresh);
void do_nms_obj(box *boxes, float **probs, int total, int classes, float thresh);
box decode_box(box b, box anchor);
box encode_box(box b, box anchor);

View File

@@ -384,5 +384,5 @@ void run_coco(int argc, char **argv)
else if(0==strcmp(argv[2], "train")) train_coco(cfg, weights);
else if(0==strcmp(argv[2], "valid")) validate_coco(cfg, weights);
else if(0==strcmp(argv[2], "recall")) validate_coco_recall(cfg, weights);
else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, coco_classes, 80, frame_skip, prefix);
else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, coco_classes, 80, frame_skip, prefix, .5);
}

View File

@@ -133,6 +133,7 @@ void forward_convolutional_layer_gpu(convolutional_layer l, network_state state)
void backward_convolutional_layer_gpu(convolutional_layer l, network_state state)
{
//constrain_ongpu(l.outputs*l.batch, 1, l.delta_gpu, 1);
gradient_array_ongpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu);
backward_bias_gpu(l.bias_updates_gpu, l.delta_gpu, l.batch, l.n, l.out_w*l.out_h);

View File

@@ -13,7 +13,7 @@
#endif
extern void predict_classifier(char *datacfg, char *cfgfile, char *weightfile, char *filename, int top);
extern void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filename, float thresh);
extern void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filename, float thresh, float hier_thresh);
extern void run_voxel(int argc, char **argv);
extern void run_yolo(int argc, char **argv);
extern void run_detector(int argc, char **argv);
@@ -129,7 +129,9 @@ void oneoff(char *cfgfile, char *weightfile, char *outfile)
network net = parse_network_cfg(cfgfile);
int oldn = net.layers[net.n - 2].n;
int c = net.layers[net.n - 2].c;
net.layers[net.n - 2].n = 9372;
scal_cpu(oldn*c, .1, net.layers[net.n - 2].weights, 1);
scal_cpu(oldn, 0, net.layers[net.n - 2].biases, 1);
net.layers[net.n - 2].n = 9418;
net.layers[net.n - 2].biases += 5;
net.layers[net.n - 2].weights += 5*c;
if(weightfile){
@@ -383,7 +385,7 @@ int main(int argc, char **argv)
} else if (0 == strcmp(argv[1], "detect")){
float thresh = find_float_arg(argc, argv, "-thresh", .24);
char *filename = (argc > 4) ? argv[4]: 0;
test_detector("cfg/coco.data", argv[2], argv[3], filename, thresh);
test_detector("cfg/coco.data", argv[2], argv[3], filename, thresh, .5);
} else if (0 == strcmp(argv[1], "cifar")){
run_cifar(argc, argv);
} else if (0 == strcmp(argv[1], "go")){

View File

@@ -267,7 +267,7 @@ void fill_truth_region(char *path, float *truth, int classes, int num_boxes, int
h = boxes[i].h;
id = boxes[i].id;
if (w < .01 || h < .01) continue;
if (w < .005 || h < .005) continue;
int col = (int)(x*num_boxes);
int row = (int)(y*num_boxes);
@@ -317,7 +317,7 @@ void fill_truth_detection(char *path, int num_boxes, float *truth, int classes,
h = boxes[i].h;
id = boxes[i].id;
if ((w < .01 || h < .01)) continue;
if ((w < .005 || h < .005)) continue;
truth[i*5+0] = x;
truth[i*5+1] = y;

View File

@@ -31,6 +31,7 @@ static image disp = {0};
static CvCapture * cap;
static float fps = 0;
static float demo_thresh = 0;
static float demo_hier_thresh = .5;
static float *predictions[FRAMES];
static int demo_index = 0;
@@ -63,7 +64,7 @@ void *detect_in_thread(void *ptr)
if(l.type == DETECTION){
get_detection_boxes(l, 1, 1, demo_thresh, probs, boxes, 0);
} else if (l.type == REGION){
get_region_boxes(l, 1, 1, demo_thresh, probs, boxes, 0, 0);
get_region_boxes(l, 1, 1, demo_thresh, probs, boxes, 0, 0, demo_hier_thresh);
} else {
error("Last layer must produce detections\n");
}
@@ -91,7 +92,7 @@ double get_wall_time()
return (double)time.tv_sec + (double)time.tv_usec * .000001;
}
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix)
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, float hier_thresh)
{
//skip = frame_skip;
image **alphabet = load_alphabet();
@@ -100,6 +101,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch
demo_alphabet = alphabet;
demo_classes = classes;
demo_thresh = thresh;
demo_hier_thresh = hier_thresh;
printf("Demo\n");
net = parse_network_cfg(cfgfile);
if(weightfile){
@@ -127,7 +129,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch
boxes = (box *)calloc(l.w*l.h*l.n, sizeof(box));
probs = (float **)calloc(l.w*l.h*l.n, sizeof(float *));
for(j = 0; j < l.w*l.h*l.n; ++j) probs[j] = (float *)calloc(l.classes, sizeof(float *));
for(j = 0; j < l.w*l.h*l.n; ++j) probs[j] = (float *)calloc(l.classes, sizeof(float));
pthread_t fetch_thread;
pthread_t detect_thread;
@@ -213,7 +215,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch
}
}
#else
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix)
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, float hier_thresh)
{
fprintf(stderr, "Demo needs OpenCV for webcam images.\n");
}

View File

@@ -2,6 +2,6 @@
#define DEMO
#include "image.h"
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix);
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, float hier_thresh);
#endif

View File

@@ -11,34 +11,88 @@ void free_layer(layer l)
#endif
return;
}
if(l.indexes) free(l.indexes);
if(l.rand) free(l.rand);
if(l.cost) free(l.cost);
if(l.biases) free(l.biases);
if(l.bias_updates) free(l.bias_updates);
if(l.weights) free(l.weights);
if(l.weight_updates) free(l.weight_updates);
if(l.col_image) free(l.col_image);
if(l.input_layers) free(l.input_layers);
if(l.input_sizes) free(l.input_sizes);
if(l.delta) free(l.delta);
if(l.output) free(l.output);
if(l.squared) free(l.squared);
if(l.norms) free(l.norms);
if(l.cweights) free(l.cweights);
if(l.indexes) free(l.indexes);
if(l.input_layers) free(l.input_layers);
if(l.input_sizes) free(l.input_sizes);
if(l.map) free(l.map);
if(l.rand) free(l.rand);
if(l.cost) free(l.cost);
if(l.state) free(l.state);
if(l.prev_state) free(l.prev_state);
if(l.forgot_state) free(l.forgot_state);
if(l.forgot_delta) free(l.forgot_delta);
if(l.state_delta) free(l.state_delta);
if(l.concat) free(l.concat);
if(l.concat_delta) free(l.concat_delta);
if(l.binary_weights) free(l.binary_weights);
if(l.biases) free(l.biases);
if(l.bias_updates) free(l.bias_updates);
if(l.scales) free(l.scales);
if(l.scale_updates) free(l.scale_updates);
if(l.weights) free(l.weights);
if(l.weight_updates) free(l.weight_updates);
if(l.col_image) free(l.col_image);
if(l.delta) free(l.delta);
if(l.output) free(l.output);
if(l.squared) free(l.squared);
if(l.norms) free(l.norms);
if(l.spatial_mean) free(l.spatial_mean);
if(l.mean) free(l.mean);
if(l.variance) free(l.variance);
if(l.mean_delta) free(l.mean_delta);
if(l.variance_delta) free(l.variance_delta);
if(l.rolling_mean) free(l.rolling_mean);
if(l.rolling_variance) free(l.rolling_variance);
if(l.x) free(l.x);
if(l.x_norm) free(l.x_norm);
if(l.m) free(l.m);
if(l.v) free(l.v);
if(l.z_cpu) free(l.z_cpu);
if(l.r_cpu) free(l.r_cpu);
if(l.h_cpu) free(l.h_cpu);
if(l.binary_input) free(l.binary_input);
#ifdef GPU
if(l.indexes_gpu) cuda_free((float *)l.indexes_gpu);
if(l.weights_gpu) cuda_free(l.weights_gpu);
if(l.weight_updates_gpu) cuda_free(l.weight_updates_gpu);
if(l.col_image_gpu) cuda_free(l.col_image_gpu);
if(l.weights_gpu) cuda_free(l.weights_gpu);
if(l.biases_gpu) cuda_free(l.biases_gpu);
if(l.weight_updates_gpu) cuda_free(l.weight_updates_gpu);
if(l.bias_updates_gpu) cuda_free(l.bias_updates_gpu);
if(l.output_gpu) cuda_free(l.output_gpu);
if(l.delta_gpu) cuda_free(l.delta_gpu);
if(l.rand_gpu) cuda_free(l.rand_gpu);
if(l.squared_gpu) cuda_free(l.squared_gpu);
if(l.norms_gpu) cuda_free(l.norms_gpu);
if(l.indexes_gpu) cuda_free((float *)l.indexes_gpu);
if(l.z_gpu) cuda_free(l.z_gpu);
if(l.r_gpu) cuda_free(l.r_gpu);
if(l.h_gpu) cuda_free(l.h_gpu);
if(l.m_gpu) cuda_free(l.m_gpu);
if(l.v_gpu) cuda_free(l.v_gpu);
if(l.prev_state_gpu) cuda_free(l.prev_state_gpu);
if(l.forgot_state_gpu) cuda_free(l.forgot_state_gpu);
if(l.forgot_delta_gpu) cuda_free(l.forgot_delta_gpu);
if(l.state_gpu) cuda_free(l.state_gpu);
if(l.state_delta_gpu) cuda_free(l.state_delta_gpu);
if(l.gate_gpu) cuda_free(l.gate_gpu);
if(l.gate_delta_gpu) cuda_free(l.gate_delta_gpu);
if(l.save_gpu) cuda_free(l.save_gpu);
if(l.save_delta_gpu) cuda_free(l.save_delta_gpu);
if(l.concat_gpu) cuda_free(l.concat_gpu);
if(l.concat_delta_gpu) cuda_free(l.concat_delta_gpu);
if(l.binary_input_gpu) cuda_free(l.binary_input_gpu);
if(l.binary_weights_gpu) cuda_free(l.binary_weights_gpu);
if(l.mean_gpu) cuda_free(l.mean_gpu);
if(l.variance_gpu) cuda_free(l.variance_gpu);
if(l.rolling_mean_gpu) cuda_free(l.rolling_mean_gpu);
if(l.rolling_variance_gpu) cuda_free(l.rolling_variance_gpu);
if(l.variance_delta_gpu) cuda_free(l.variance_delta_gpu);
if(l.mean_delta_gpu) cuda_free(l.mean_delta_gpu);
if(l.col_image_gpu) cuda_free(l.col_image_gpu);
if(l.x_gpu) cuda_free(l.x_gpu);
if(l.x_norm_gpu) cuda_free(l.x_norm_gpu);
if(l.weights_gpu) cuda_free(l.weights_gpu);
if(l.weight_updates_gpu) cuda_free(l.weight_updates_gpu);
if(l.biases_gpu) cuda_free(l.biases_gpu);
if(l.bias_updates_gpu) cuda_free(l.bias_updates_gpu);
if(l.scales_gpu) cuda_free(l.scales_gpu);
if(l.scale_updates_gpu) cuda_free(l.scale_updates_gpu);
if(l.output_gpu) cuda_free(l.output_gpu);
if(l.delta_gpu) cuda_free(l.delta_gpu);
if(l.rand_gpu) cuda_free(l.rand_gpu);
if(l.squared_gpu) cuda_free(l.squared_gpu);
if(l.norms_gpu) cuda_free(l.norms_gpu);
#endif
}

View File

@@ -99,14 +99,7 @@ struct layer{
float B1;
float B2;
float eps;
float *m_gpu;
float *v_gpu;
int t;
float *m;
float *v;
tree *softmax_tree;
int *map;
float alpha;
float beta;
@@ -129,33 +122,34 @@ struct layer{
float probability;
float scale;
int *indexes;
float *rand;
float *cost;
char *cweights;
float *state;
float *prev_state;
float *forgot_state;
float *forgot_delta;
float *state_delta;
float *concat;
float *concat_delta;
float *binary_weights;
float *biases;
float *bias_updates;
float *scales;
float *scale_updates;
float *weights;
float *weight_updates;
float *col_image;
char * cweights;
int * indexes;
int * input_layers;
int * input_sizes;
int * map;
float * rand;
float * cost;
float * state;
float * prev_state;
float * forgot_state;
float * forgot_delta;
float * state_delta;
float * concat;
float * concat_delta;
float * binary_weights;
float * biases;
float * bias_updates;
float * scales;
float * scale_updates;
float * weights;
float * weight_updates;
float * col_image;
float * delta;
float * output;
float * squared;
@@ -174,6 +168,15 @@ struct layer{
float * x;
float * x_norm;
float * m;
float * v;
float * z_cpu;
float * r_cpu;
float * h_cpu;
float * binary_input;
struct layer *input_layer;
struct layer *self_layer;
struct layer *output_layer;
@@ -194,20 +197,20 @@ struct layer{
struct layer *input_h_layer;
struct layer *state_h_layer;
float *z_cpu;
float *r_cpu;
float *h_cpu;
float *binary_input;
tree *softmax_tree;
size_t workspace_size;
#ifdef GPU
int *indexes_gpu;
float *z_gpu;
float *r_gpu;
float *h_gpu;
int *indexes_gpu;
float *m_gpu;
float *v_gpu;
float * prev_state_gpu;
float * forgot_state_gpu;
float * forgot_delta_gpu;

View File

@@ -826,7 +826,7 @@ void save_weights_upto(network net, char *filename, int cutoff)
}
#endif
fprintf(stderr, "Saving weights to %s\n", filename);
FILE *fp = fopen(filename, "w");
FILE *fp = fopen(filename, "wb");
if(!fp) file_error(filename);
int major = 0;

View File

@@ -4,17 +4,15 @@
#include "layer.h"
#include "network.h"
typedef layer region_layer;
region_layer make_region_layer(int batch, int h, int w, int n, int classes, int coords);
void forward_region_layer(const region_layer l, network_state state);
void backward_region_layer(const region_layer l, network_state state);
void get_region_boxes(layer l, int w, int h, float thresh, float **probs, box *boxes, int only_objectness, int *map);
layer make_region_layer(int batch, int h, int w, int n, int classes, int coords);
void forward_region_layer(const layer l, network_state state);
void backward_region_layer(const layer l, network_state state);
void get_region_boxes(layer l, int w, int h, float thresh, float **probs, box *boxes, int only_objectness, int *map, float tree_thresh);
void resize_region_layer(layer *l, int w, int h);
#ifdef GPU
void forward_region_layer_gpu(const region_layer l, network_state state);
void backward_region_layer_gpu(region_layer l, network_state state);
void forward_region_layer_gpu(const layer l, network_state state);
void backward_region_layer_gpu(layer l, network_state state);
#endif
#endif

View File

@@ -5,6 +5,7 @@ typedef struct{
int *leaf;
int n;
int *parent;
int *child;
int *group;
char **name;
@@ -16,6 +17,7 @@ typedef struct{
tree *read_tree(char *filename);
void hierarchy_predictions(float *predictions, int n, tree *hier, int only_leaves);
void change_leaves(tree *t, char *leaf_list);
int hierarchy_top_prediction(float *predictions, tree *hier, float thresh);
float get_hierarchy_probability(float *x, tree *hier, int c);
#endif

View File

@@ -351,5 +351,5 @@ void run_yolo(int argc, char **argv)
else if(0==strcmp(argv[2], "train")) train_yolo(cfg, weights);
else if(0==strcmp(argv[2], "valid")) validate_yolo(cfg, weights);
else if(0==strcmp(argv[2], "recall")) validate_yolo_recall(cfg, weights);
else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, voc_names, 20, frame_skip, prefix);
else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, voc_names, 20, frame_skip, prefix, .5);
}