| | |
| | | } |
| | | */ |
| | | |
| | | int mt_seed = 0; |
| | | |
| | | char **get_random_paths(char **paths, int n, int m) |
| | | { |
| | | char **random_paths = calloc(n, sizeof(char*)); |
| | | int i; |
| | | pthread_mutex_lock(&mutex); |
| | | for(i = 0; i < n; ++i){ |
| | | int index = rand()%m; |
| | | if (mt_seed == 0) mt_seed = time(0); |
| | | srand(mt_seed); |
| | | //printf("n = %d \n", n); |
| | | for(i = 0; i < n; ++i){ |
| | | int index = rand()%m; |
| | | random_paths[i] = paths[index]; |
| | | //if(i == 0) printf("%s\n", paths[index]); |
| | | //printf("grp: %s\n", paths[index]); |
| | | } |
| | | mt_seed = rand(); |
| | | pthread_mutex_unlock(&mutex); |
| | | return random_paths; |
| | | } |
| | |
| | | { |
| | | int i; |
| | | for(i = 0; i < n; ++i){ |
| | | if(boxes[i].x == 0 && boxes[i].y == 0) { |
| | | boxes[i].x = 999999; |
| | | boxes[i].y = 999999; |
| | | boxes[i].w = 999999; |
| | | boxes[i].h = 999999; |
| | | continue; |
| | | } |
| | | boxes[i].left = boxes[i].left * sx - dx; |
| | | boxes[i].right = boxes[i].right * sx - dx; |
| | | boxes[i].top = boxes[i].top * sy - dy; |
| | |
| | | find_replace(path, "images", "labels", labelpath); |
| | | find_replace(labelpath, "JPEGImages", "labels", labelpath); |
| | | |
| | | find_replace(labelpath, "raw", "labels", labelpath); |
| | | find_replace(labelpath, ".jpg", ".txt", labelpath); |
| | | find_replace(labelpath, ".png", ".txt", labelpath); |
| | | find_replace(labelpath, ".JPG", ".txt", labelpath); |
| | |
| | | h = boxes[i].h; |
| | | id = boxes[i].id; |
| | | |
| | | if (w < .01 || h < .01) continue; |
| | | if ((w < .01 || h < .01)) continue; |
| | | |
| | | truth[i*5+0] = x; |
| | | truth[i*5+1] = y; |
| | |
| | | if(count != 1) printf("Too many or too few labels: %d, %s\n", count, path); |
| | | } |
| | | |
| | | matrix load_labels_paths(char **paths, int n, char **labels, int k) |
| | | void fill_hierarchy(float *truth, int k, tree *hierarchy) |
| | | { |
| | | int j; |
| | | for(j = 0; j < k; ++j){ |
| | | if(truth[j]){ |
| | | int parent = hierarchy->parent[j]; |
| | | while(parent >= 0){ |
| | | truth[parent] = 1; |
| | | parent = hierarchy->parent[parent]; |
| | | } |
| | | } |
| | | } |
| | | int i; |
| | | int count = 0; |
| | | for(j = 0; j < hierarchy->groups; ++j){ |
| | | //printf("%d\n", count); |
| | | int mask = 1; |
| | | for(i = 0; i < hierarchy->group_size[j]; ++i){ |
| | | if(truth[count + i]){ |
| | | mask = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (mask) { |
| | | for(i = 0; i < hierarchy->group_size[j]; ++i){ |
| | | truth[count + i] = SECRET_NUM; |
| | | } |
| | | } |
| | | count += hierarchy->group_size[j]; |
| | | } |
| | | } |
| | | |
| | | matrix load_labels_paths(char **paths, int n, char **labels, int k, tree *hierarchy) |
| | | { |
| | | matrix y = make_matrix(n, k); |
| | | int i; |
| | | for(i = 0; i < n && labels; ++i){ |
| | | fill_truth(paths[i], labels, k, y.vals[i]); |
| | | if(hierarchy){ |
| | | fill_hierarchy(y.vals[i], k, hierarchy); |
| | | } |
| | | } |
| | | return y; |
| | | } |
| | |
| | | while(fscanf(fp2, "%d %f", &id, &iou) == 2){ |
| | | if (d.y.vals[i][2*id + 1] < iou) d.y.vals[i][2*id + 1] = iou; |
| | | } |
| | | |
| | | |
| | | for (j = 0; j < classes; ++j){ |
| | | if (d.y.vals[i][2*j] > .5 && d.y.vals[i][2*j+1] < .5){ |
| | | d.y.vals[i][2*j] = 1; |
| | |
| | | { |
| | | int index = rand()%n; |
| | | char *random_path = paths[index]; |
| | | |
| | | |
| | | image orig = load_image_color(random_path, 0, 0); |
| | | int h = orig.h; |
| | | int w = orig.w; |
| | |
| | | |
| | | void *load_thread(void *ptr) |
| | | { |
| | | srand(time(0)); |
| | | //printf("Loading data: %d\n", rand()); |
| | | load_args a = *(struct load_args*)ptr; |
| | | if(a.exposure == 0) a.exposure = 1; |
| | |
| | | if (a.type == OLD_CLASSIFICATION_DATA){ |
| | | *a.d = load_data_old(a.paths, a.n, a.m, a.labels, a.classes, a.w, a.h); |
| | | } else if (a.type == CLASSIFICATION_DATA){ |
| | | *a.d = load_data_augment(a.paths, a.n, a.m, a.labels, a.classes, a.min, a.max, a.size, a.angle, a.aspect, a.hue, a.saturation, a.exposure); |
| | | *a.d = load_data_augment(a.paths, a.n, a.m, a.labels, a.classes, a.hierarchy, a.min, a.max, a.size, a.angle, a.aspect, a.hue, a.saturation, a.exposure); |
| | | } else if (a.type == SUPER_DATA){ |
| | | *a.d = load_data_super(a.paths, a.n, a.m, a.w, a.h, a.scale); |
| | | } else if (a.type == WRITING_DATA){ |
| | |
| | | |
| | | void *load_threads(void *ptr) |
| | | { |
| | | srand(time(0)); |
| | | int i; |
| | | load_args args = *(load_args *)ptr; |
| | | if (args.threads == 0) args.threads = 1; |
| | |
| | | data d = {0}; |
| | | d.shallow = 0; |
| | | d.X = load_image_paths(paths, n, w, h); |
| | | d.y = load_labels_paths(paths, n, labels, k); |
| | | d.y = load_labels_paths(paths, n, labels, k, 0); |
| | | if(m) free(paths); |
| | | return d; |
| | | } |
| | | |
| | | /* |
| | | data load_data_study(char **paths, int n, int m, char **labels, int k, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure) |
| | | { |
| | | data d = {0}; |
| | | d.indexes = calloc(n, sizeof(int)); |
| | | if(m) paths = get_random_paths_indexes(paths, n, m, d.indexes); |
| | | d.shallow = 0; |
| | | d.X = load_image_augment_paths(paths, n, min, max, size, angle, aspect, hue, saturation, exposure); |
| | | d.y = load_labels_paths(paths, n, labels, k); |
| | | if(m) free(paths); |
| | | return d; |
| | | } |
| | | */ |
| | | data load_data_study(char **paths, int n, int m, char **labels, int k, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure) |
| | | { |
| | | data d = {0}; |
| | | d.indexes = calloc(n, sizeof(int)); |
| | | if(m) paths = get_random_paths_indexes(paths, n, m, d.indexes); |
| | | d.shallow = 0; |
| | | d.X = load_image_augment_paths(paths, n, min, max, size, angle, aspect, hue, saturation, exposure); |
| | | d.y = load_labels_paths(paths, n, labels, k); |
| | | if(m) free(paths); |
| | | return d; |
| | | } |
| | | */ |
| | | |
| | | data load_data_super(char **paths, int n, int m, int w, int h, int scale) |
| | | { |
| | |
| | | return d; |
| | | } |
| | | |
| | | data load_data_augment(char **paths, int n, int m, char **labels, int k, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure) |
| | | data load_data_augment(char **paths, int n, int m, char **labels, int k, tree *hierarchy, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure) |
| | | { |
| | | if(m) paths = get_random_paths(paths, n, m); |
| | | data d = {0}; |
| | | d.shallow = 0; |
| | | d.X = load_image_augment_paths(paths, n, min, max, size, angle, aspect, hue, saturation, exposure); |
| | | d.y = load_labels_paths(paths, n, labels, k); |
| | | d.y = load_labels_paths(paths, n, labels, k, hierarchy); |
| | | if(m) free(paths); |
| | | return d; |
| | | } |