def __init__(self, target_dynamic_path, target_static_path, config):
        Optimizer.__init__(self, tf.Graph(), 256, 8, target_dynamic_path,
                           target_static_path, config)

        with self.graph.as_default():
            with tf.device('/gpu:' + str(self.user_config['gpu'])):
                # load dynamic texture
                imgs = load_images(target_dynamic_path,
                                   size=(self.input_frame_count,
                                         self.input_dimension,
                                         self.input_dimension))
                self.target_dynamic_texture = [
                    tf.to_float(
                        tf.constant(
                            img.reshape(1, self.input_dimension,
                                        self.input_dimension, 3)))
                    for img in imgs
                ]

                # load static texture (for dynamics style transfer)
                img = load_image(target_static_path,
                                 size=(self.input_dimension,
                                       self.input_dimension))
                self.target_static_texture = tf.to_float(
                    tf.constant(
                        img.reshape(1, self.input_dimension,
                                    self.input_dimension, 3)))

                # TODO: check for b/w input
                # initialize noise
                initial_noise = tf.random_normal([
                    self.user_config['batch_size'], self.input_frame_count,
                    self.input_dimension, self.input_dimension, 3
                ])
                self.output = tf.Variable(initial_noise, name='output')

                # TODO: let weight be user-definable
                # build appearance descriptors (one for each frame)
                self.appearance_loss = \
                    self.build_appearance_descriptors(
                        'appearance_descriptors', 1e9)

                # TODO: let weight be user-definable
                # build dynamics descriptors (one for each pair of
                # frames)
                self.dynamics_loss = \
                    self.build_dynamics_descriptors('dynamics_descriptors',
                                                    1e15)

                # evaluate dynamic texture loss
                self.dyntex_loss = tf.add(self.appearance_loss,
                                          self.dynamics_loss)

                # averaging loss over batch
                self.dyntex_loss = tf.div(self.dyntex_loss,
                                          self.user_config['batch_size'])

                # attach summaries
                self.attach_summaries('summaries')
예제 #2
0
def test_preprocessing():

    images = u.load_images("test_images")

    clf = u.load_pretrained_model(
          "disc_feature_approach_face_model.caffemodel",
          "disc_feature_approach_face_deploy.prototxt"
    )

    embeddings, timings = u.calc_embeddings_from_imgs(clf, images)
def save_depth():
    # Custom object needed for inference and training
    custom_objects = {
        'BilinearUpSampling2D': BilinearUpSampling2D,
        'depth_loss_function': None
    }
    print('Loading model...')
    # Load model into GPU / CPU
    model = load_model(args.model,
                       custom_objects=custom_objects,
                       compile=False)
    print('\nModel loaded ({0}).'.format(args.model))
    # Input images
    inputs = load_images(glob.glob(args.input))
    print('\nLoaded ({0}) images of size {1}.'.format(inputs.shape[0],
                                                      inputs.shape[1:]))
    # Compute results
    outputs = predict(model, inputs)
    save_images('result.png', outputs, is_colormap=False)
예제 #4
0
import utilities as ut
import pca
import os

path = '../data/'

database = 'orl_faces'
subspace = 'orl_subspace.npz'
components = 400
rows = 112
columns = 92

if not os.path.exists(path + subspace):
   M = ut.load_images(database) 
   eigenvalues, W, mu = pca.create_subspace(M, components)
   pca.save_subspace(path + subspace, eigenvalues, W, mu)
else:
   eigenvalues, W, mu = pca.load_subspace(path + subspace)

img = ut.create_image(rows,columns, 3)

x = pca.project_image(img,W,mu)
y = pca.reverse_projection(x,W,mu)
image = ut.normalize_image(ut.unflatten_image(y,rows,columns))

original = ut.unflatten_image(img,rows,columns)

ut.display_image(image)
ut.display_image(original)
예제 #5
0
# test.py
# used to quickly test functionality of code
# requires orl_faces images to be saved in data folder
import utilities as utils
import pca

components = 400
rows = 112
columns = 92

M = utils.load_images('orl_faces')
img = utils.create_image(rows, columns, 2)

eigenvalues, W, mu = pca.create_subspace(M,components)
print W.shape, img.shape, mu.shape
x = pca.project_image(img,W,mu)
print x.shape
y = pca.reverse_projection(x,W,mu)
print y.shape 
image = utils.normalize_image(utils.unflatten_image(y,rows,columns))
for i in range(1):
    print 'eigenface ' + str(i) + ': ', utils.normalize_image(utils.unflatten_image(W[:,i],rows,columns)).shape
    utils.display_image(utils.normalize_image(utils.unflatten_image(W[:,i],rows,columns)))
utils.display_image(image)
utils.display_image(utils.unflatten_image(img,rows,columns))
예제 #6
0
        else:
            name = "Unknown"
            prediction = 0
            # Draw box
            cv.rectangle(test_image, (left, top), (right, bottom), (255, 0, 0), 2)
            # Draw label
            y = top - 15 if top - 15 > 15 else top + 15
            cv.putText(test_image, name, (left, y), cv.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)

    # Return labeled images
    return correct, test_image, prediction


if __name__ == '__main__':
    readid_encodings = get_face_encodings(READID)
    readid_image = load_images(READID, single=True)

    unknown_faces = load_images(CALTECH)
    known_faces = load_images(ME)
    test_images = known_faces + unknown_faces

    me = []
    not_me = []

    y_true = [1]*len(known_faces)+[0]*len(unknown_faces)
    y_pred = []

    for img in test_images:
        check, image, pred = predict(readid_encodings, img)
        y_pred.append(pred)
        if check: