Git Product home page Git Product logo

Comments (7)

galeone avatar galeone commented on July 22, 2024

Hi! Do you mean changing the name in the saved model from StatefulPartitionedCall:1 to B?

from tfgo.

jun-sun avatar jun-sun commented on July 22, 2024

Hi! Do you mean changing the name in the saved model from StatefulPartitionedCall:1 to B?

Just need to match the 4 scores we get from StatefulPartitionedCall:0~3 to the 4 events [A,B,C,D] without running saved_model_cli

from tfgo.

galeone avatar galeone commented on July 22, 2024

🤔 it should be this way. Can you show me:

  1. In python how do you load the saved model, and feed the model to get the values A,B,C,D (and their values)
  2. The same thing, but in Go

Because I expect the behavior to be the same, given the same saved model and the same inputs

from tfgo.

jun-sun avatar jun-sun commented on July 22, 2024

In python, I simply run
model.predict(input)
which gives me the 4 task output in a python list
[array([[0.1545861]], dtype=float32), array([[0.27176663]], dtype=float32), array([[0.04840082]], dtype=float32), array([[0.16918059]], dtype=float32)]

In go, I run

results0 := p.Model.Exec([]tf.Output{
		p.Model.Op("StatefulPartitionedCall", 0),
	}, input)
	results1 := p.Model.Exec([]tf.Output{
		p.Model.Op("StatefulPartitionedCall", 1),
	}, input)
	results2 := p.Model.Exec([]tf.Output{
		p.Model.Op("StatefulPartitionedCall", 2),
	}, input)
	results3 := p.Model.Exec([]tf.Output{
		p.Model.Op("StatefulPartitionedCall", 3),
	}, input)

The order of the output is different

[[0.1691806]]
[[0.04840079]]
[[0.15458608]]
[[0.27176666]]

When I train the model, I name the tasks in the following order

"TaskTypes": [
            "NAVIGATE_IMP",
            "PURCHASE_NAVIGATE",
            "LIKE_NAVIGATE",
            "ADDTOCART_NAVIGATE"
          ],

But running saved_model_cli show ... suggests the output index does not match how I construct the model. The output names seems sorted by alpha order.

outputs['ADDTOCART_NAVIGATE'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 1)
        name: StatefulPartitionedCall:0
    outputs['LIKE_NAVIGATE'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 1)
        name: StatefulPartitionedCall:1
    outputs['NAVIGATE_IMP'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 1)
        name: StatefulPartitionedCall:2
    outputs['PURCHASE_NAVIGATE'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 1)
        name: StatefulPartitionedCall:3

from tfgo.

galeone avatar galeone commented on July 22, 2024

You should first check in Python - after importing the SavedModel with tf.saved_model.load and not with the Keras equivalent - if the output is the expected one.

We need to test this to understand if the SavedModel used in Python in the same way it's used from Go has the same behavior or not. This can give us an hint on where to look (if it's something in common, than there's some pre/post processing to do. If the behavior is different maybe the C library used in Go has some problem 🤔 )

from tfgo.

jun-sun avatar jun-sun commented on July 22, 2024

OK, I am running

        imported = tf.saved_model.load(model_path)
        f = imported.signatures["serving_default"]
        print(f)

which gives me

 Args:
...
 Returns:
    {'ADDTOCART_NAVIGATE': <1>, 'LIKE_NAVIGATE': <2>, 'NAVIGATE_IMP': <3>, 'PURCHASE_NAVIGATE': <4>}
      <1>: float32 Tensor, shape=(None, 1)
      <2>: float32 Tensor, shape=(None, 1)
      <3>: float32 Tensor, shape=(None, 1)
      <4>: float32 Tensor, shape=(None, 1)

The output seems returned as a map, keyed with output tensor name. Then it explains why the order does not match.

from tfgo.

galeone avatar galeone commented on July 22, 2024

I guess, thus, the problem is solved. I mean, you just need to correctly map the p.Model.Op("StatefulPartitionedCall", index), with the index you expect.

Closing since this is not a tfgo problem.

from tfgo.

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.