[shotwell/wip/phako/enhanced-faces: 30/136] Added DNN torch network file and DBus functions for face2vec



commit 95707eb8585d3b7156019dccd78e8f199f180fa3
Author: NarendraMA <narendra_m_a yahoo com>
Date:   Mon Jul 16 20:30:41 2018 +0530

    Added DNN torch network file and DBus functions for face2vec

 facedetect/openface.nn4.small2.v1.t7 | Bin 0 -> 31510785 bytes
 src/AppDirs.vala                     |   8 ++++++++
 src/db/Db.vala                       |   6 ++++++
 src/faces/Face.vala                  |   2 +-
 src/faces/FaceDetect.vala            |  18 +++++++++++-------
 5 files changed, 26 insertions(+), 8 deletions(-)
---
diff --git a/facedetect/openface.nn4.small2.v1.t7 b/facedetect/openface.nn4.small2.v1.t7
new file mode 100644
index 00000000..8a0d0197
Binary files /dev/null and b/facedetect/openface.nn4.small2.v1.t7 differ
diff --git a/src/AppDirs.vala b/src/AppDirs.vala
index d42b7b32..4d0714fa 100644
--- a/src/AppDirs.vala
+++ b/src/AppDirs.vala
@@ -346,6 +346,14 @@ class AppDirs {
         }
         return get_resources_dir().get_child("facedetect-haarcascade.xml");
     }
+
+    public static File get_openface_dnn_file() {
+        File f = 
File.new_for_path(AppDirs.get_exec_dir().get_parent().get_parent().get_child("facedetect").get_child("openface.nn4.small2.v1.t7").get_path());
+        if (f.query_exists()) {//testing meson builddir
+            return f;
+        }
+        return get_resources_dir().get_child("openface.nn4.small2.v1.t7");
+    }
 #endif
 
 }
diff --git a/src/db/Db.vala b/src/db/Db.vala
index ba565b4b..6facbbc3 100644
--- a/src/db/Db.vala
+++ b/src/db/Db.vala
@@ -354,6 +354,7 @@ private VerifyResult upgrade_database(int input_version) {
     //
     // Version 21:
     // * Added face pixels column to FaceLocationTable
+    // * Added face vector column to FaceTable
     //
     
     if (!DatabaseTable.has_column("FaceLocationTable", "pix")) {
@@ -361,6 +362,11 @@ private VerifyResult upgrade_database(int input_version) {
         if (!DatabaseTable.add_column("FaceLocationTable", "pix", "BLOB"))
             return VerifyResult.UPGRADE_ERROR;
     }
+    if (!DatabaseTable.has_column("FaceTable", "vec")) {
+        message("upgrade_database: adding vec column to FaceTable");
+        if (!DatabaseTable.add_column("FaceTable", "vec", "TEXT"))
+            return VerifyResult.UPGRADE_ERROR;
+    }
     
     version = 21;
 #endif
diff --git a/src/faces/Face.vala b/src/faces/Face.vala
index 2443df03..2f5ce6a8 100644
--- a/src/faces/Face.vala
+++ b/src/faces/Face.vala
@@ -380,7 +380,7 @@ public class Face : DataSource, ContainerSource, Proxyable, Indexable {
     private static void start_facedetect_process() {
         message("Launching facedetect process: %s", AppDirs.get_facedetect_bin().get_path());
         // Start the watcher
-        FaceDetect.init();
+        FaceDetect.init(AppDirs.get_openface_dnn_file().get_path());
         // Start the background process
         string[] argv = {AppDirs.get_facedetect_bin().get_path()};
         int child_pid;
diff --git a/src/faces/FaceDetect.vala b/src/faces/FaceDetect.vala
index 259d11e0..f97ef491 100644
--- a/src/faces/FaceDetect.vala
+++ b/src/faces/FaceDetect.vala
@@ -35,6 +35,10 @@ public struct FaceRect {
 public interface FaceDetectInterface : Object {
     public abstract FaceRect[] detect_faces(string inputName, string cascadeName, double scale)
         throws IOError, DBusError;
+    public abstract bool load_net(string netFile)
+        throws IOError, DBusError;
+    public abstract bool face_to_vec(string inputName)
+        throws IOError, DBusError;
     public abstract void terminate() throws IOError, DBusError;
 }
 
@@ -43,6 +47,7 @@ public class FaceDetect {
     public const string DBUS_NAME = "org.gnome.shotwell.faces";
     public const string DBUS_PATH = "/org/gnome/shotwell/faces";
     public static bool connected = false;
+    public static string net_file;
     
     public static FaceDetectInterface interface;
 
@@ -51,8 +56,10 @@ public class FaceDetect {
         if (bus_name == DBUS_NAME) {
             try {
                 interface = Bus.get_proxy_sync (BusType.SESSION, DBUS_NAME, DBUS_PATH);
+                interface.load_net(net_file);
                 connected = true;
             } catch(IOError e) {
+            } catch(DBusError e) {
             }
         }
     }
@@ -62,12 +69,9 @@ public class FaceDetect {
         connected = false;
     }
     
-    public static void init() {
-        //Bus.watch_name(BusType.SYSTEM, DBUS_NAME, BusNameWatcherFlags.NONE, create_interface, 
interface_gone);
-        try {
-            interface = Bus.get_proxy_sync(BusType.SESSION, DBUS_NAME, DBUS_PATH);
-            connected = true;
-        } catch(IOError e) {
-        }
+    public static void init(string net_file) {
+        FaceDetect.net_file = net_file;
+        Bus.watch_name(BusType.SESSION, DBUS_NAME, BusNameWatcherFlags.NONE,
+                       create_interface, interface_gone);
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]