aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2018-10-18 12:54:21 +0100
committerVasil Zlatanov <v@skozl.com>2018-10-18 12:54:21 +0100
commit1afdc762b80613f9ae8c6f35296a883c40fdc375 (patch)
tree501b9b650b447719b5ea6164fe478c40877dfc70
parent1bd5993aeb5cb84657cd1acb72f9b7c6e6c3553d (diff)
downloadvz215_np1915-1afdc762b80613f9ae8c6f35296a883c40fdc375.tar.gz
vz215_np1915-1afdc762b80613f9ae8c6f35296a883c40fdc375.tar.bz2
vz215_np1915-1afdc762b80613f9ae8c6f35296a883c40fdc375.zip
Require -m argument
-rwxr-xr-xtrain.py4
-rwxr-xr-xutil/image-to-array35
2 files changed, 37 insertions, 2 deletions
diff --git a/train.py b/train.py
index b7e9fb0..a0c2a9a 100755
--- a/train.py
+++ b/train.py
@@ -18,13 +18,13 @@ def normalise_faces(average_face, raw_faces):
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--data", help="Input CSV file", required=True)
parser.add_argument("-o", "--model", help="Output model file", required=True)
-parser.add_argument("-m", "--M", help="Number of eigenvalues in model", type=int)
+parser.add_argument("-m", "--eigen", help="Number of eigenvalues in model", required=True, type=int)
args = parser.parse_args()
assert args.data, "No input CSV data (-i, --input-data)"
assert args.model, "No model specified (-o, --model)"
-M = args.M | -1;
+M = args.eigen
raw_faces = genfromtxt(args.data, delimiter=',').T
diff --git a/util/image-to-array b/util/image-to-array
new file mode 100755
index 0000000..72abc5c
--- /dev/null
+++ b/util/image-to-array
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+import numpy as np
+import sys, os
+
+from PIL import Image;
+
+def jpg_image_to_array(image_path):
+ """
+ Loads JPEG image into 3D Numpy array of shape
+ (width, height, channels)
+ """
+ with Image.open(image_path) as image:
+ im_arr = np.frombuffer(image.tobytes(), dtype=np.uint8)
+ # im_arr = im_arr.reshape((image.size[1], image.size[0], 3))
+ return im_arr
+
+def main(files):
+ for i in range(0, len(files)):
+ inputfile = files[i]
+ print(inputfile);
+
+ if not os.path.exists(inputfile):
+ sys.exit('ERROR: File %s was not found!' % inputfile)
+
+ print(jpg_image_to_array(inputfile))
+
+if __name__ == "__main__":
+ if len(sys.argv) > 1:
+ main(sys.argv[1:])
+ else:
+ print("%s: You must specify files to convert to vectors" % sys.argv[0])
+
+# def compute_average_vector
+
+# def compute_covariance_of_normalised_faces