Beispiel #1
0
def main(_):
    args = parser.parse_args()
    log.init("FaceNeural", logging.DEBUG, log_path="output/log.txt")

    with tf.Session() as sess:
        if args.phase == "train":
            model = Face(sess, args)
            model.train(args)
            log.info('train mode')
        elif args.phase == "inference":
            log.info("inference")
            model = Face(sess, args)
            model.inference(args)
        elif args.phase == "lightcnn":
            log.info("light cnn test")
        elif args.phase == "faceparsing":
            log.info("faceparsing")
        elif args.phase == "net":
            log.info("net start with ports (%d, %d)", 5010, 5011)
            net = Net(5010, 5011)
            while True:
                r_input = raw_input("command: \n")
                if r_input == "s":
                    msg = raw_input("input: ")
                    net.only_send(msg)
                elif r_input == 'r':
                    msg = raw_input("input: ")
                    net.send_recv(msg)
                elif r_input == "q":
                    net.only_send("quit")
                    net.close()
                    break
                else:
                    log.error("unknown code, quit")
                    net.close()
                    break
Beispiel #2
0
    if support_gpu and arguments.use_gpu:
        if not arguments.gpuid:
            arguments.gpuid = 0
        dev = torch.device("cuda:%d" % arguments.gpuid)
        return True, dev
    else:
        dev = torch.device("cpu")
        return False, dev


if __name__ == '__main__':
    """
    程序入口函数
    """
    args = parser.parse_args()
    log.init("FaceNeural", logging.INFO, log_path="./output/neural_log.txt")
    cuda, device = init_device(args)

    if args.phase == "train_imitator":
        log.info('imitator train mode')
        imitator = Imitator("neural imitator", args)
        if cuda:
            imitator.cuda()
        imitator.batch_train(cuda)
    elif args.phase == "train_extractor":
        log.info('feature extractor train mode')
        extractor = Extractor("neural extractor", args)
        if cuda:
            extractor.cuda()
        extractor.batch_train(cuda)
    elif args.phase == "inference_imitator":
Beispiel #3
0
            cv2.imwrite(path_save.replace("align_", "align2_"), scaled)
        return scaled
    except Exception as e:
        log.error(e)


def clean(path):
    for root, dirs, files in os.walk(path):
        for file in files:
            if file.startswith("align"):
                path = os.path.join(root, file)
                os.remove(path)


def export(path):
    for root, dirs, files in os.walk(path):
        for file in files:
            path1 = os.path.join(root, file)
            path2 = os.path.join(root, "align_" + file)
            face_features(path1, path2)


if __name__ == '__main__':
    log.init("align")
    pwd = os.getcwd()
    project_path = os.path.abspath(os.path.dirname(pwd) + os.path.sep + ".")
    model_path = os.path.join(project_path, "neural/output/image/")
    log.info(model_path)
    clean(model_path)
    export(model_path)
Beispiel #4
0
        """
        count = len(self.losses)
        if count > 0:
            plt.style.use('seaborn-whitegrid')
            x = range(count)
            y1 = []
            y2 = []
            for it in self.losses:
                y1.append(it[0])
                y2.append(it[1])
            plt.plot(x, y1, color='r', label='l1')
            plt.plot(x, y2, color='g', label='l2')
            plt.ylabel("loss")
            plt.xlabel('step')
            plt.legend()
            path = os.path.join(self.prev_path, "loss.png")
            plt.savefig(path)
            plt.close('all')


if __name__ == '__main__':
    import logging
    from parse import parser

    log.info("evaluation mode start")
    args = parser.parse_args()
    log.init("FaceNeural", logging.INFO, log_path="./output/evaluate.txt")
    evl = Evaluate(args, cuda=torch.cuda.is_available())
    img = cv2.imread(args.eval_image).astype(np.float32)
    evl.itr_train(img)