【问题标题】:TensorFlow Slim Exporting Transfer Learning to tensorflow serving issueTensorFlow Slim 将迁移学习导出到 tensorflow 服务问题
【发布时间】:2017-07-12 06:04:07
【问题描述】:

任何帮助将不胜感激。

我已经关注了这个tutorial 然后我使用这个简单的脚本来验证我的模型是否可以正常工作:

import tensorflow as tf
from nets import inception_v3
from preprocessing import inception_preprocessing
from matplotlib.pyplot import imshow, imread

slim = tf.contrib.slim


batch_size = 5
image_size = 299

with tf.Graph().as_default():
    with slim.arg_scope(inception_v3.inception_v3_arg_scope()):

        imgPath = 'dandelion.jpg'

        #imgPath = '/tmp/rose.jpg'
        testImage_string = tf.gfile.FastGFile(imgPath, 'rb').read()
        testImage = tf.image.decode_jpeg(testImage_string, channels=3)
        processed_image = inception_preprocessing.preprocess_image(testImage, image_size, image_size, is_training=False)
        processed_images = tf.expand_dims(processed_image, 0)



        logits, _ = inception_v3.inception_v3(processed_images, num_classes=5, is_training=False)
        probabilities = tf.nn.softmax(logits)
        checkpoint_path = tf.train.latest_checkpoint('/tmp/flowers-models/inception_v3')
        init_fn = slim.assign_from_checkpoint_fn(
        checkpoint_path, slim.get_model_variables('InceptionV3'))

        with tf.Session() as sess:
            init_fn(sess)

            np_image, probabilities = sess.run([processed_images, probabilities])

            probabilities = probabilities[0, 0:]
            sorted_inds = [i[0] for i in sorted(enumerate(-probabilities), key=lambda x: x[1])]

            names = ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']
            for i in range(5):
                index = sorted_inds[i]
                print((probabilities[index], names[index]))

但是我的最终目标是在 tensorflow 服务中加载这个模型,我不确定下一步将我的模型转换为服务可以理解的格式是什么?

【问题讨论】:

    标签: python machine-learning tensorflow tensorflow-serving


    【解决方案1】:

    Tensorflow Slim 使用已弃用的“SessionBundle”。我目前正在将 tensorflow/slim (tf.train.saver) 生成的检查点转换为 SavedModel 格式 (tf.saved_model)。

    “tensorflow/contrib/session_bundle/session_bundle.py”中的“session_bundle.load_session_bundle_from_path”返回会话和 meta_graph_def。意图是手动构建 savedModel (https://www.tensorflow.org/programmers_guide/saved_model),但无法从 meta_graph_def 获取输入。

    目前使用 Tensorflow 1.7,降级看看是否有什么不同。

    【讨论】:

      猜你喜欢
      • 2021-08-16
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-08
      • 2020-08-06
      • 2022-11-27
      • 2016-05-18
      相关资源
      最近更新 更多