Exemplo n.º 1
0
def get_predict_file(args):
    assert (os.path.exists(args.lfw_align))
    pairs = load_pairs(args.pairs)
    _, model_args, model_auxs = mx.model.load_checkpoint(
        args.model_prefix, args.epoch)
    symbol = lightened_cnn_b_feature()
    with open(args.predict_file, 'w') as f:
        for pair in pairs:
            name1, name2, same = pairs_info(pair, args.suffix)
            logging.info("processing name1:{} <---> name2:{}".format(
                name1, name2))
            model_args['data'] = mx.nd.array(
                read2img(args.lfw_align, name1, name2, args.size, ctx), ctx)
            exector = symbol.bind(ctx,
                                  model_args,
                                  args_grad=None,
                                  grad_req="null",
                                  aux_states=model_auxs)
            exector.forward(is_train=False)
            exector.outputs[0].wait_to_read()
            output = exector.outputs[0].asnumpy()
            dis = np.dot(output[0], output[1]) / np.linalg.norm(
                output[0]) / np.linalg.norm(output[1])
            f.write(name1 + '\t' + name2 + '\t' + str(dis) + '\t' + str(same) +
                    '\n')
Exemplo n.º 2
0
def get_predict_file(args):
    # assert(os.path.exists(args.lfw_align))
    # pairs = load_pairs(args.pairs)
    _, model_args, model_auxs = mx.model.load_checkpoint(args.model_prefix, args.epoch)
    symbol = lightened_cnn_b_feature()
    print("processing id image")
    with open("id.txt", "w") as f:
        for fname in os.listdir(args.idimage_align):
            print(fname)
            model_args['data'] = mx.nd.array(readimg(args.idimage_align, fname, args.size, ctx), ctx)
            exector = symbol.bind(ctx, model_args ,args_grad=None, grad_req="null", aux_states=model_auxs)
            exector.forward(is_train=False)
            exector.outputs[0].wait_to_read()
            output = exector.outputs[0].asnumpy()
            f.write(fname + ' ')
            output.tofile(f, ' ')
            f.write('\n')

    print("processing normal image")

    with open("normal.txt", "w") as f:
        for fname in os.listdir(args.normalimage_align):
            print(fname)
            model_args['data'] = mx.nd.array(readimg(args.normalimage_align, fname, args.size, ctx), ctx)
            exector = symbol.bind(ctx, model_args ,args_grad=None, grad_req="null", aux_states=model_auxs)
            exector.forward(is_train=False)
            exector.outputs[0].wait_to_read()
            output = exector.outputs[0].asnumpy()
            f.write(fname + ' ')
            output.tofile(f, ' ')
            f.write('\n')
Exemplo n.º 3
0
def get_predict_file(args):
    assert(os.path.exists(args.lfw_align))
    pairs = load_pairs(args.pairs)
    _, model_args, model_auxs = mx.model.load_checkpoint(args.model_prefix, args.epoch)
    symbol = lightened_cnn_b_feature()
    with open(args.predict_file, 'w') as f:
        for pair in pairs:
            name1, name2, same = pairs_info(pair, args.suffix)
            logging.info("processing name1:{} <---> name2:{}".format(name1, name2))
            model_args['data'] = mx.nd.array(read2img(args.lfw_align, name1, name2, args.size, ctx), ctx)
            exector = symbol.bind(ctx, model_args ,args_grad=None, grad_req="null", aux_states=model_auxs)
            exector.forward(is_train=False)
            exector.outputs[0].wait_to_read()
            output = exector.outputs[0].asnumpy()
            dis = np.dot(output[0], output[1])/np.linalg.norm(output[0])/np.linalg.norm(output[1])
            f.write(name1 + '\t' + name2 + '\t' + str(dis) + '\t' + str(same) + '\n')
Exemplo n.º 4
0
def load_exector(model_prefix, epoch, size):
    _, model_args, model_auxs = mx.model.load_checkpoint(model_prefix, epoch)
    symbol = lightened_cnn_b_feature()
    return symbol, model_args, model_auxs
Exemplo n.º 5
0
def load_exector(model_prefix, epoch, size):
    _, model_args, model_auxs = mx.model.load_checkpoint(model_prefix, epoch)
    symbol = lightened_cnn_b_feature()
    return symbol, model_args, model_auxs
 def __load_exector(self):
     _, model_args, model_auxs = mx.model.load_checkpoint(
         config.model_prefix, config.epoch)
     symbol = lightened_cnn_b_feature()
     return symbol, model_args, model_auxs
Exemplo n.º 7
0
import logging
import os
import sys

import cv2
import mxnet as mx
import numpy as np
from sklearn.cross_validation import KFold
from sklearn.metrics import accuracy_score

from lightened_cnn import lightened_cnn_b_feature

# load model
ctx = mx.gpu(0)
_, model_args, model_auxs = mx.model.load_checkpoint("./lightened_cnn/lightened_cnn", 166)
symbol = lightened_cnn_b_feature()

# load data0
size = 128
img_arr = np.zeros((1, 1, size, size), dtype=float)
img = np.expand_dims(cv2.imread("test.png", 0), axis=0)
img_arr[0][:] = img / 255.0

# caculate feature0
model_args["data"] = mx.nd.array(img_arr, ctx)
exector = symbol.bind(ctx, model_args, args_grad=None, grad_req="null", aux_states=model_auxs)
exector.forward(is_train=False)
output0 = exector.outputs[0].asnumpy()

# load data1
img = np.expand_dims(cv2.imread("test1.png", 0), axis=0)
Exemplo n.º 8
0
 def load_model(self, model_prefix="model/lightened_cnn/lightened_cnn"):
     _, self.model_args, self.model_auxs = mx.model.load_checkpoint(
         model_prefix, self.epoch)
     self.symbol = lightened_cnn_b_feature()
     print "MXNet-Face loaded."