From 38bd6ae6ba24fc8c14fd61d1238ae94a983434b3 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Mon, 20 Jul 2015 23:16:26 +0000
Subject: [PATCH] Better partial function

---
 src/data.c |   37 ++++++++++++++++++++++++++++++++-----
 1 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/src/data.c b/src/data.c
index 425d216..982ef21 100644
--- a/src/data.c
+++ b/src/data.c
@@ -8,7 +8,7 @@
 
 unsigned int data_seed;
 
-struct load_args{
+typedef struct load_args{
     char **paths;
     int n;
     int m;
@@ -22,7 +22,10 @@
     int classes;
     int background;
     data *d;
-};
+    char *path;
+    image *im;
+    image *resized;
+} load_args;
 
 list *get_paths(char *filename)
 {
@@ -69,7 +72,7 @@
     X.cols = 0;
 
     for(i = 0; i < n; ++i){
-        image im = load_image(paths[i], w, h);
+        image im = load_image(paths[i], w, h, 1);
         X.vals[i] = im.data;
         X.cols = im.h*im.w*im.c;
     }
@@ -137,7 +140,7 @@
 
 void fill_truth_detection(char *path, float *truth, int classes, int num_boxes, int flip, int background, float dx, float dy, float sx, float sy)
 {
-    char *labelpath = find_replace(path, "detection_images", "labels");
+    char *labelpath = find_replace(path, "JPEGImages", "labels");
     labelpath = find_replace(labelpath, ".jpg", ".txt");
     labelpath = find_replace(labelpath, ".JPEG", ".txt");
     int count = 0;
@@ -329,7 +332,7 @@
             ++count;
         }
     }
-    if(count != 1) printf("%d, %s\n", count, path);
+    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)
@@ -468,6 +471,30 @@
     return d;
 }
 
+void *load_image_in_thread(void *ptr)
+{
+    load_args a = *(load_args*)ptr;
+    free(ptr);
+    *(a.im) = load_image_color(a.path, 0, 0);
+    *(a.resized) = resize_image(*(a.im), a.w, a.h);
+    return 0;
+}
+
+pthread_t load_image_thread(char *path, image *im, image *resized, int w, int h)
+{
+    pthread_t thread;
+    struct load_args *args = calloc(1, sizeof(struct load_args));
+    args->path = path;
+    args->w = w;
+    args->h = h;
+    args->im = im;
+    args->resized = resized;
+    if(pthread_create(&thread, 0, load_image_in_thread, args)) {
+        error("Thread creation failed");
+    }
+    return thread;
+}
+
 void *load_localization_thread(void *ptr)
 {
     printf("Loading data: %d\n", rand_r(&data_seed));

--
Gitblit v1.10.0