diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc \ No newline at end of file diff --git a/pdm_builder/buildlib/__init__.py b/pdm_builder/buildlib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pdm_builder/buildpatch.py b/pdm_builder/buildlib/buildpatch.py similarity index 99% rename from pdm_builder/buildpatch.py rename to pdm_builder/buildlib/buildpatch.py index db27775..b6ce02e 100644 --- a/pdm_builder/buildpatch.py +++ b/pdm_builder/buildlib/buildpatch.py @@ -1,7 +1,7 @@ from sklearn.svm import SVR, SVC from sklearn.linear_model import LogisticRegression from PIL import Image -import config +import ..config import random from numpy import array, sqrt, square from numpy.linalg import norm diff --git a/pdm_builder/buildpatch_mosse.py b/pdm_builder/buildlib/buildpatch_mosse.py similarity index 99% rename from pdm_builder/buildpatch_mosse.py rename to pdm_builder/buildlib/buildpatch_mosse.py index fae86a3..e060426 100644 --- a/pdm_builder/buildpatch_mosse.py +++ b/pdm_builder/buildlib/buildpatch_mosse.py @@ -1,5 +1,5 @@ from PIL import Image -import config, random +import ..config, random from numpy import array, sqrt, square, fft, mean, zeros from numpy.linalg import norm from numpy.ma import conjugate diff --git a/pdm_builder/buildscore.py b/pdm_builder/buildlib/buildscore.py similarity index 100% rename from pdm_builder/buildscore.py rename to pdm_builder/buildlib/buildscore.py diff --git a/pdm_builder/buildshape.py b/pdm_builder/buildlib/buildshape.py similarity index 100% rename from pdm_builder/buildshape.py rename to pdm_builder/buildlib/buildshape.py diff --git a/pdm_builder/preprocess.py b/pdm_builder/buildlib/preprocess.py similarity index 99% rename from pdm_builder/preprocess.py rename to pdm_builder/buildlib/preprocess.py index 6c8a0c1..fa1c7f3 100644 --- a/pdm_builder/preprocess.py +++ b/pdm_builder/buildlib/preprocess.py @@ -1,7 +1,7 @@ import numpy, os from numpy import vstack, mean from PIL import Image -import config, procrustes +import ..config, procrustes mirror_map = config.mirror_map num_patches = config.num_patches diff --git a/pdm_builder/procrustes.py b/pdm_builder/buildlib/procrustes.py similarity index 100% rename from pdm_builder/procrustes.py rename to pdm_builder/buildlib/procrustes.py diff --git a/pdm_builder/config.py b/pdm_builder/config.py index f1b1d5c..fc5eb73 100644 --- a/pdm_builder/config.py +++ b/pdm_builder/config.py @@ -1,9 +1,4 @@ # mirror scheme -#mirror_map = [14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,19,20,21,22,15,16,17,18,\ -# 28,29,30,31,32,23,24,25,26,27,41,40,39,38,37,36,35,34,33,43,42,50,49,\ -# 48,47,46,45,44,55,54,53,52,51,58,57,56,61,60,59,62,67,68,69,70,63,64,\ -# 65,66] - mirror_map = [14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,19,20,21,22,15,16,17,18,\ 28,29,30,31,32,23,24,25,26,27,33,40,39,38,37,36,35,34,41,43,42,50,49,\ 48,47,46,45,44,55,54,53,52,51,58,57,56,61,60,59,62,67,68,69,70,63,64,\ @@ -17,11 +12,9 @@ [19,20,21,22],\ [23,63,24,64,25,65,26,66,23],\ [28,67,29,68,30,69,31,70,28],\ - #[33,34,35,36,42,37,43,38,39,40,41],\ [34,35,36,42,37,43,38,39,40],\ [33, 41, 62],\ [44,45,46,47,48,49,50,51,52,53,54,55,44,56,57,58,50,59,60,61,44],\ - #62,27,32\ 27,32\ ] \ } @@ -40,8 +33,9 @@ #patch_size = 16 # raw image folder -data_folder = "./newdata/" -#data_folder = "./data/" +data_folder = "./data/" +annotations = "./data/annotations.csv" + # folder image cropped_image_folder = "./cropped/" diff --git a/pdm_builder/average_face/average.py b/pdm_builder/create_average_face.py similarity index 89% rename from pdm_builder/average_face/average.py rename to pdm_builder/create_average_face.py index 8640750..9d3fae0 100644 --- a/pdm_builder/average_face/average.py +++ b/pdm_builder/create_average_face.py @@ -1,11 +1,11 @@ import numpy as np -import preprocess, pickle, skimage +from buildlib import preprocess +import pickle, skimage from skimage.transform import PiecewiseAffineTransform, warp from skimage.io import imread, Image, imsave +import config -coordinate_file = "./data.csv" - -data_pca, data_patches, meanshape, cropsize = preprocess.preprocess(coordinate_file, mirror = True) +data_pca, data_patches, meanshape, cropsize = preprocess.preprocess(config.annotations, mirror = True) dp = {'data_pca' : data_pca, 'data_patches' : data_patches, 'meanshape' : meanshape, 'cropsize' : cropsize} fi = open("out.data", "w") @@ -48,7 +48,7 @@ avim /= imlen avim *= 255 avim = avim.astype(np.uint8) -imsave("./averageface/average.bmp", Image(avim)) +imsave("./average.bmp", Image(avim)) # for all in array # average diff --git a/pdm_builder/emotion_classifier/buildEmotionClass.py b/pdm_builder/create_emotion_classifier.py similarity index 97% rename from pdm_builder/emotion_classifier/buildEmotionClass.py rename to pdm_builder/create_emotion_classifier.py index 46f0b13..507fee1 100644 --- a/pdm_builder/emotion_classifier/buildEmotionClass.py +++ b/pdm_builder/create_emotion_classifier.py @@ -1,9 +1,9 @@ -import preprocess, os +from buildlib import preprocess from sklearn.decomposition import PCA from sklearn.linear_model import LogisticRegression from sklearn.ensemble import RandomForestClassifier from sklearn import cross_validation -import pickle, json +import pickle, json, os from numpy import row_stack, any, isnan, sum, diag, cov, mean, dot, trace from numpy.linalg import qr import numpy, math diff --git a/data/annotations.csv b/pdm_builder/data/annotations.csv similarity index 100% rename from data/annotations.csv rename to pdm_builder/data/annotations.csv diff --git a/data/readme.txt b/pdm_builder/data/readme.txt similarity index 60% rename from data/readme.txt rename to pdm_builder/data/readme.txt index e68808e..5eb4c50 100644 --- a/data/readme.txt +++ b/pdm_builder/data/readme.txt @@ -1,2 +1,3 @@ training images for the annotations can be downloaded from https://code.google.com/p/muct/downloads/list -download muct-e-jpg-v1.tar.gz, muct-c-jpg-v1.tar.gz, muct-b-jpg-v1.tar.gz and muct-a-jpg-v1.tar.gz \ No newline at end of file +download muct-e-jpg-v1.tar.gz, muct-c-jpg-v1.tar.gz, muct-b-jpg-v1.tar.gz and muct-a-jpg-v1.tar.gz +unzip the files and put all training images into the folder "/data/images" \ No newline at end of file diff --git a/pdm_builder/main.py b/pdm_builder/pdm_builder.py similarity index 72% rename from pdm_builder/main.py rename to pdm_builder/pdm_builder.py index a99c3bc..3ed8da3 100644 --- a/pdm_builder/main.py +++ b/pdm_builder/pdm_builder.py @@ -1,35 +1,31 @@ -import preprocess +from buildlib import preprocess, buildshape import config -import buildshape -#from buildpatch_mosse import build_patches -from buildpatch import build_patches +#from buildlab.buildpatch_mosse import build_patches +from buildlab.buildpatch import build_patches +from buildlab.buildscore import getScoring import pickle import numpy, json -from buildscore import getScoring buildPatches = True buildScoring = True -coordinate_file = "./data.csv" - # preprocess data -#data_pca, data_patches, meanshape, cropsize = preprocess.preprocess(coordinate_file, mirror = True) +data_pca, data_patches, meanshape, cropsize = preprocess.preprocess(config.annotations, mirror = True) #dp = {'data_pca' : data_pca, 'data_patches' : data_patches, 'meanshape' : meanshape, 'cropsize' : cropsize} #fi = open("out.data", "w") #pickle.dump(dp, fi) #fi.close() -fi = open("out.data", "r") -data = pickle.load(fi) -fi.close() -data_pca = data['data_pca'] -data_patches = data['data_patches'] -meanshape = data['meanshape'] -cropsize = data['cropsize'] +#fi = open("out.data", "r") +#data = pickle.load(fi) +#fi.close() +#data_pca = data['data_pca'] +#data_patches = data['data_patches'] +#meanshape = data['meanshape'] +#cropsize = data['cropsize'] # build shape model -#eigenVectors, eigenValues = buildshape.pca(data_pca.values(), num_components=7) eigenVectors, eigenValues = buildshape.pca(data_pca.values(), num_components=24) #eigenVectors, eigenValues = buildshape.spca(data_pca.values(), num_components=10, alpha=0.5) mean = [numpy.mean(column) for column in meanshape.T] @@ -59,11 +55,8 @@ model['scoring'] = scoring model['shapeModel'] = {} model['shapeModel']['eigenVectors'] = eigenVectors.T.tolist() -#model['shapeModel']['eigenValues'] = eigenValues.flatten().tolist() model['shapeModel']['eigenValues'] = eigenValues -#model['shapeModel']['eigenValues'] = eigenValues.tolist() model['shapeModel']['meanShape'] = meanshape.tolist() -#model['shapeModel']['numEvalues'] = eigenValues.shape[0] model['shapeModel']['numEvalues'] = len(eigenValues) model['shapeModel']['numPtsPerSample'] = meanshape.shape[0] @@ -78,7 +71,7 @@ model['path'] = config.path -of = open("filter.js","w") +of = open("model.js","w") of.write("var pModel = ") of.write(json.dumps(model, indent=2)) of.write(";\n") diff --git a/readme.md b/readme.md index e69de29..8f72ec9 100644 --- a/readme.md +++ b/readme.md @@ -0,0 +1,7 @@ + +Dependencies for pdmbuilder is: +* numpy +* scipy +* scikit-learn +* scikit-image +* PIL \ No newline at end of file