GithubHelp home page GithubHelp logo

Comments (10)

andresusanopinto avatar andresusanopinto commented on September 28, 2024 2

For now one has to do it manually, example:

import tensorflow as tf
import tensorflow_hub as hub

with tf.Graph().as_default():
  module = hub.Module("http://tfhub.dev/google/universal-sentence-encoder/2")
  text = tf.placeholder(tf.string, [None])
  embedding = module(text)
  
  init_op = tf.group([tf.global_variables_initializer(), tf.tables_initializer()])
  with tf.Session() as session:
    session.run(init_op)
    tf.saved_model.simple_save(
        session,
        "/tmp/serving_saved_model",
        inputs = {"text": text},
        outputs = {"embedding": embedding}        
    )

Each modules differs slightly from others in input/output names, additionally each serving use case might have different requirements (e.g. raw features in vs serialized tf.Example protos). By having users creating the graph they want to serve (e.g. as done above) seems more flexible than require users to guess what Servo config to use and/or modify the client side each time they change the module being served.

from hub.

navneetrao avatar navneetrao commented on September 28, 2024

+1
Making hub modules consumable by Tensorflow Serving would be very helpful.

from hub.

warynice avatar warynice commented on September 28, 2024

Any workarounds for this currently? I want to serve a hub module using Tensorflow Serving.

from hub.

samsends avatar samsends commented on September 28, 2024

I have not tested this, but I that suspect you could load the module into an empty graph and then export with savedmodelbuilder. We could build an automated tool.

from hub.

andresusanopinto avatar andresusanopinto commented on September 28, 2024

Closing as this is now obsolete.

In TF-2 users should create reusable saved models with tf.saved_model.save().

from hub.

chenliu0831 avatar chenliu0831 commented on September 28, 2024

@andresusanopinto quick question, does it mean the pre-trained model on tensorflow hub won't have the serving_default signature by default and the user need to re-export it? Thanks

from hub.

arnoegw avatar arnoegw commented on September 28, 2024

A TF2 SavedModel can both have signatures for deployment to TensorFlow Serving and tf.functions for reuse in a Python TensorFlow program.

See https://www.tensorflow.org/hub/tf2_saved_model#advanced_topic_what_to_expect_from_the_savedmodel_after_loading and https://www.tensorflow.org/guide/saved_model

from hub.

chenliu0831 avatar chenliu0831 commented on September 28, 2024

@arnoegw thanks for the pointer. I noticed some inconsistency of some TF2 models that some have serving_default signature while some does not. For example:

My understanding is if serving_default is not present, the model cannot be served as-is in TF serving. Should all TF2 models have this signature? Let me know if I should open a new issue to track this.

from hub.

arnoegw avatar arnoegw commented on September 28, 2024

@chenliu0831, there's nothing wrong with those examples:

from hub.

chenliu0831 avatar chenliu0831 commented on September 28, 2024

@arnoegw Ah thanks for clarifying. I give a bad example for the second case since that's a feature vector.

I spot check another few on TF hub with the TF2 filter and with classification variants and looks like their signature map is empty as well:

In the detail page of above models I think they all show up as "TF2.0 Saved Model" format.

from hub.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.