From f26da0ad5c679936274917c3d1e53821250414f6 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Sun, 28 Dec 2014 17:42:35 +0000
Subject: [PATCH] Need to fix line reads
---
src/data.c | 93 ++++++++++++++++++++++++++++------------------
1 files changed, 56 insertions(+), 37 deletions(-)
diff --git a/src/data.c b/src/data.c
index 86e59ef..12dc101 100644
--- a/src/data.c
+++ b/src/data.c
@@ -6,6 +6,20 @@
#include <stdlib.h>
#include <string.h>
+struct load_args{
+ char **paths;
+ int n;
+ int m;
+ char **labels;
+ int k;
+ int h;
+ int w;
+ int nh;
+ int nw;
+ float scale;
+ data *d;
+};
+
list *get_paths(char *filename)
{
char *path;
@@ -81,6 +95,18 @@
return X;
}
+char **get_random_paths(char **paths, int n, int m)
+{
+ char **random_paths = calloc(n, sizeof(char*));
+ int i;
+ for(i = 0; i < n; ++i){
+ int index = rand()%m;
+ random_paths[i] = paths[index];
+ if(i == 0) printf("%s\n", paths[index]);
+ }
+ return random_paths;
+}
+
matrix load_labels_paths(char **paths, int n, char **labels, int k)
{
matrix y = make_matrix(n, k);
@@ -138,13 +164,8 @@
data load_data_detection_jitter_random(int n, char **paths, int m, int h, int w, int nh, int nw, float scale)
{
- char **random_paths = calloc(n, sizeof(char*));
+ char **random_paths = get_random_paths(paths, n, m);
int i;
- for(i = 0; i < n; ++i){
- int index = rand()%m;
- random_paths[i] = paths[index];
- if(i == 0) printf("%s\n", paths[index]);
- }
data d;
d.shallow = 0;
d.X = load_image_paths(random_paths, n, h, w);
@@ -154,24 +175,44 @@
int dx = rand()%32;
int dy = rand()%32;
fill_truth_detection(random_paths[i], d.y.vals[i], 224, 224, nh, nw, scale, dx, dy);
-
image a = float_to_image(h, w, 3, d.X.vals[i]);
jitter_image(a,224,224,dy,dx);
}
+ d.X.cols = 224*224*3;
free(random_paths);
return d;
}
+void *load_detection_thread(void *ptr)
+{
+ struct load_args a = *(struct load_args*)ptr;
+ *a.d = load_data_detection_jitter_random(a.n, a.paths, a.m, a.h, a.w, a.nh, a.nw, a.scale);
+ free(ptr);
+ return 0;
+}
+
+pthread_t load_data_detection_thread(int n, char **paths, int m, int h, int w, int nh, int nw, float scale, data *d)
+{
+ pthread_t thread;
+ struct load_args *args = calloc(1, sizeof(struct load_args));
+ args->n = n;
+ args->paths = paths;
+ args->m = m;
+ args->h = h;
+ args->w = w;
+ args->nh = nh;
+ args->nw = nw;
+ args->scale = scale;
+ args->d = d;
+ if(pthread_create(&thread, 0, load_detection_thread, args)) {
+ error("Thread creation failed");
+ }
+ return thread;
+}
data load_data_detection_random(int n, char **paths, int m, int h, int w, int nh, int nw, float scale)
{
- char **random_paths = calloc(n, sizeof(char*));
- int i;
- for(i = 0; i < n; ++i){
- int index = rand()%m;
- random_paths[i] = paths[index];
- if(i == 0) printf("%s\n", paths[index]);
- }
+ char **random_paths = get_random_paths(paths, n, m);
data d;
d.shallow = 0;
d.X = load_image_paths(random_paths, n, h, w);
@@ -180,18 +221,6 @@
return d;
}
-char **get_random_paths(char **paths, int n, int m)
-{
- char **random_paths = calloc(n, sizeof(char*));
- int i;
- for(i = 0; i < n; ++i){
- int index = rand()%m;
- random_paths[i] = paths[index];
- if(i == 0) printf("%s\n", paths[index]);
- }
- return random_paths;
-}
-
data load_data(char **paths, int n, int m, char **labels, int k, int h, int w)
{
if(m) paths = get_random_paths(paths, n, m);
@@ -203,21 +232,11 @@
return d;
}
-struct load_args{
- char **paths;
- int n;
- int m;
- char **labels;
- int k;
- int h;
- int w;
- data *d;
-};
-
void *load_in_thread(void *ptr)
{
struct load_args a = *(struct load_args*)ptr;
*a.d = load_data(a.paths, a.n, a.m, a.labels, a.k, a.h, a.w);
+ free(ptr);
return 0;
}
--
Gitblit v1.10.0