Giter Site home page Giter Site logo

Comments (4)

vahidk avatar vahidk commented on July 22, 2024 1

This get_shape() function is not designed to be used for printing shapes. If you want to do that just use session.run(tf.shape(x)). The output of get_shape() is useful for creating other tensors. What it does is that it tries to keep the shape static if possible otherwise dynamic which can be useful at times.

from effectivetensorflow.

vahidk avatar vahidk commented on July 22, 2024

Try print(tf.Session().run(shape))

from effectivetensorflow.

JenkinsY94 avatar JenkinsY94 commented on July 22, 2024

Hi vahidk. It seems not working because get_shape() returns a list of mixture of integer and tensor object.

Here's a working example:

def get_dyn_shape(tensor):
    dynamic_shape = tf.unstack(tf.shape(tensor))
    return dynamic_shape
a = tf.placeholder(tf.float32, [None, 128])
dyn_shape = get_dyn_shape(a)
print(tf.Session().run(dyn_shape, feed_dict={a:np.random.random((3, 128))}))

But When I replace get_dyn_shape with get_shape in your article, it failed. Tensorflow says:

TypeError: Fetch argument 128 has invalid type <class 'int'>, must be a string or Tensor. (Can not 
convert a int into a Tensor or Operation.)

Any suggestions?

Also, I'm confused about when to use this get_shape, as get_dyn_shape returns exactly same result?

from effectivetensorflow.

Shunsuke-1994 avatar Shunsuke-1994 commented on July 22, 2024

".values().get_shape()" or ".outputs.get_chape()" method worked!
https://www.tensorflow.org/api_docs/python/tf/Operation

from effectivetensorflow.

Related Issues (18)

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.