Skip to content

Commit

Permalink
modified pdm builder
Browse files Browse the repository at this point in the history
  • Loading branch information
auduno committed Jan 7, 2014
1 parent 9be3163 commit d32fe2b
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
Empty file.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
12 changes: 3 additions & 9 deletions pdm_builder/config.py
Original file line number Diff line number Diff line change
@@ -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,\
Expand All @@ -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\
] \
}
Expand All @@ -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/"

Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion data/readme.txt → pdm_builder/data/readme.txt
Original file line number Diff line number Diff line change
@@ -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
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"
33 changes: 13 additions & 20 deletions pdm_builder/main.py → pdm_builder/pdm_builder.py
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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]

Expand All @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

Dependencies for pdmbuilder is:
* numpy
* scipy
* scikit-learn
* scikit-image
* PIL

0 comments on commit d32fe2b

Please sign in to comment.