首页 文章

如何使用我自己训练的模型与tensnetflow中实现的facenet?

提问于
浏览
1

我使用shell命令训练模型:

python src/facenet_train.py \
           --batch_size 15 \
           --gpu_memory_fraction 0.25 \
           --models_base_dir trained_model_2017_05_15_10_24 \
           --pretrained_model trained_model_2017_05_15_10_24/20170515-121856/model-20170515-121856.ckpt-182784 \
           --model_def models.nn2 \
           --logs_base_dir logs \
           --data_dir /data/user_set/training/2017_05_15_10_24 \
           --lfw_pairs /data/user_set/lfw_pairs.txt \
           --image_size 224 \
           --lfw_dir /data/user_set/lfw \
           --optimizer ADAM \
           --max_nrof_epochs 1000 \
           --learning_rate 0.00001

但是当我使用我自己训练的模型时,我得到这样的错误信息:

2017-05-17 14:23:05.448285:W tensorflow / core / platform / cpu_feature_guard.cc:45] TensorFlow库未编译为使用SSE4.1指令,但这些指令可在您的计算机上使用并且可以加速CPU计算 . 2017-05-17 14:23:05.448318:W tensorflow / core / platform / cpu_feature_guard.cc:45] TensorFlow库未编译为使用SSE4.2指令,但这些指令可在您的计算机上使用,可以加速CPU计算 . 2017-05-17 14:23:05.448324:W tensorflow / core / platform / cpu_feature_guard.cc:45] TensorFlow库未编译为使用AVX指令,但这些指令可在您的计算机上使用,并可加快CPU计算速度 . 2017-05-17 14:23:05.448329:W tensorflow / core / platform / cpu_feature_guard.cc:45] TensorFlow库未编译为使用AVX2指令,但这些指令可在您的计算机上使用,并可加速CPU计算 . 2017-05-17 14:23:05.448334:W tensorflow / core / platform / cpu_feature_guard.cc:45] TensorFlow库未编译为使用FMA指令,但这些指令可在您的计算机上使用,并可加快CPU计算速度 . 2017-05-17 14:23:05.674872:I tensorflow / core / common_runtime / gpu / gpu_device.cc:887]找到具有属性的设备0:名称:Quadro M4000 major:5 minor:2 memoryClockRate(GHz)0.7725 pciBusID 0000: 03:00.0总内存:7.93GiB可用内存:2.89GiB 2017-05-17 14:23:05.674917:I tensorflow / core / common_runtime / gpu / gpu_device.cc:908] DMA:0 2017-05-17 14:23 :05.674935:I tensorflow / core / common_runtime / gpu / gpu_device.cc:918] 0:Y 2017-05-17 14:23:05.674957:I tensorflow / core / common_runtime / gpu / gpu_device.cc:977]创建TensorFlow设备(/ gpu:0) - >(设备:0,名称:Quadro M4000,pci总线ID:0000:03:00.0)回溯(最近一次调用最后一次):文件“forward.py”,第21行,在images_placeholder = tf .get_default_graph() . get_tensor_by_name(“input:0”)文件“/home/chen/.pyenv/versions/anaconda3-4.2.0/lib/python3.5/site-packages/tensorflow/python/framework/ops.py “,第2563行,在get_tensor_by_name中返回self.as_graph_element(name,allow_tensor = True,allow_operation = False)文件”/home/chen/.pyenv/vers离子/ anaconda3-4.2.0 / lib / python3.5 / site-packages / tensorflow / python / framework / ops.py“,第2414行,在as_graph_element中返回self._as_graph_element_locked(obj,allow_tensor,allow_operation)文件”/ home / chen / .pyenv / versions / anaconda3-4.2.0 / lib / python3.5 / site-packages / tensorflow / python / framework / ops.py“,第2456行,在_as_graph_element_locked”图中 . “ %(repr(name),repr(op_name)))KeyError:“名称'input:0'表示不存在的Tensor . 图中不存在'input'操作 . ”

获取功能代码:

import tensorflow as tf
import facenet
w_MODEL_PATH_='/home/chen/demo_dir/facenet_tensorflow_train/trained_model_2017_05_15_10_24/20170515-121856'

with tf.Graph().as_default():
    with tf.Session() as sess:
        # load the model
        meta_file, ckpt_file = facenet.get_model_filenames(w_MODEL_PATH_)
        facenet.load_model(w_MODEL_PATH_, meta_file, ckpt_file)
        # print("model_path:", w_MODEL_PATH_,"meta_file:", meta_file,"ckpt_file:", ckpt_file)

        # Get input and output tensors
        # ops = tf.get_default_graph().get_operations()
        #
        # print(ops)

        images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0")
        embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0")
        phase_train_placeholder = tf.get_default_graph().get_tensor_by_name("phase_train:0")

        image_size = images_placeholder.get_shape()[1]
        embedding_size = embeddings.get_shape()[1]

        # print(image_size)

        paths = ['one.png', 'two.png']

        # Run forward pass to calculate embeddings
        images = facenet.load_data(paths, do_random_crop=False, do_random_flip=False, image_size=image_size,
                                   do_prewhiten=True)
        # print("images:", idx, images)
        feed_dict = {images_placeholder: images, phase_train_placeholder: False}
        # print(idx,"embeddings:", embeddings)
        emb_array = sess.run(embeddings, feed_dict=feed_dict)
        # print(idx, "emb_array:", emb_array)
        print(emb_array)

我不知道如何使用我自己训练的模型,请帮忙 .

1 回答

  • 0

    如果您正在讨论最后一部分,那么请使用此代码查看模型的操作 .

    for i in tf.get_default_graph().get_operations():
        print(i.name)
    

    如果你在谈论优化 .

    您收到此错误是因为您需要在自己的计算机上编译tensorflow . 这很容易做到 .

    您可以阅读文档以获取完整的选项列表,但基本上您需要执行几个步骤 .

    https://www.tensorflow.org/install/install_sources

    • git clone tensorflow

    • repo安装

    • bazel张量流构建系统

    • 配置tensorflow

    • 构建张量流
      如果您使用的是python,那么

    • 在您的环境中安装tensorflow(如果是anaconda或virtualenv)

    就是这样,当然还需要安装其他必需的库 . 在Ubuntu上很容易做到 .

    或者你可以尝试使用anaconda的conda forge版本的tensorflow-gpu,但是我无法验证它是否也为你的cpu进行了优化编译 .

    https://conda-forge.org/

    • 安装anaconda

    • 添加conda forge repo url

    • 更新conda

    • 安装tensorflow-gpu

相关问题