Display values of a dictionary in Tensorlow












0















Hello i'm new to TensorFlow and i'm trying to create a dictionary of weigths per layer for my ANN implementation.



The issue is that although i create the dictionary with strings as keys and tensors as values i don't know how to display them when i call the init_weight method



def init_weights(topology):
#topology: dimensions of the network

for i in range(1,len(topology)):
parameters['W' + str(i)] = tf.Variable(tf.random_normal([topology[i-1],topology[i]]))


the output of the method shows the following:



{'W1': <tf.Variable 'Variable_1:0' shape=(2, 5) dtype=float32_ref>,
'W2': <tf.Variable 'Variable_3:0' shape=(5, 5) dtype=float32_ref>,
'W3': <tf.Variable 'Variable_5:0' shape=(5, 5) dtype=float32_ref>,
'W4': <tf.Variable 'Variable_7:0' shape=(5, 10) dtype=float32_ref>}


My question is how can print the weights matrices?










share|improve this question



























    0















    Hello i'm new to TensorFlow and i'm trying to create a dictionary of weigths per layer for my ANN implementation.



    The issue is that although i create the dictionary with strings as keys and tensors as values i don't know how to display them when i call the init_weight method



    def init_weights(topology):
    #topology: dimensions of the network

    for i in range(1,len(topology)):
    parameters['W' + str(i)] = tf.Variable(tf.random_normal([topology[i-1],topology[i]]))


    the output of the method shows the following:



    {'W1': <tf.Variable 'Variable_1:0' shape=(2, 5) dtype=float32_ref>,
    'W2': <tf.Variable 'Variable_3:0' shape=(5, 5) dtype=float32_ref>,
    'W3': <tf.Variable 'Variable_5:0' shape=(5, 5) dtype=float32_ref>,
    'W4': <tf.Variable 'Variable_7:0' shape=(5, 10) dtype=float32_ref>}


    My question is how can print the weights matrices?










    share|improve this question

























      0












      0








      0








      Hello i'm new to TensorFlow and i'm trying to create a dictionary of weigths per layer for my ANN implementation.



      The issue is that although i create the dictionary with strings as keys and tensors as values i don't know how to display them when i call the init_weight method



      def init_weights(topology):
      #topology: dimensions of the network

      for i in range(1,len(topology)):
      parameters['W' + str(i)] = tf.Variable(tf.random_normal([topology[i-1],topology[i]]))


      the output of the method shows the following:



      {'W1': <tf.Variable 'Variable_1:0' shape=(2, 5) dtype=float32_ref>,
      'W2': <tf.Variable 'Variable_3:0' shape=(5, 5) dtype=float32_ref>,
      'W3': <tf.Variable 'Variable_5:0' shape=(5, 5) dtype=float32_ref>,
      'W4': <tf.Variable 'Variable_7:0' shape=(5, 10) dtype=float32_ref>}


      My question is how can print the weights matrices?










      share|improve this question














      Hello i'm new to TensorFlow and i'm trying to create a dictionary of weigths per layer for my ANN implementation.



      The issue is that although i create the dictionary with strings as keys and tensors as values i don't know how to display them when i call the init_weight method



      def init_weights(topology):
      #topology: dimensions of the network

      for i in range(1,len(topology)):
      parameters['W' + str(i)] = tf.Variable(tf.random_normal([topology[i-1],topology[i]]))


      the output of the method shows the following:



      {'W1': <tf.Variable 'Variable_1:0' shape=(2, 5) dtype=float32_ref>,
      'W2': <tf.Variable 'Variable_3:0' shape=(5, 5) dtype=float32_ref>,
      'W3': <tf.Variable 'Variable_5:0' shape=(5, 5) dtype=float32_ref>,
      'W4': <tf.Variable 'Variable_7:0' shape=(5, 10) dtype=float32_ref>}


      My question is how can print the weights matrices?







      python dictionary tensorflow neural-network weight






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 0:22









      max thundermax thunder

      51




      51
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Tensorflow is a statically typed framework (guess this is changing in 2.0). Meaning, you first build a static graph and the graph has values only when run using Tf.Session(). Now to answer your question. There are two ways to get what you want.




          1. Add tf.enable_eager_execution() at the start of your script. This creates a dynamic graph (similar to Pytorch). Your same code without any extra addition will give you what you want.


          2. Wrap everything into a tf.Session() and run it. You will get the weight matrices







          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53329708%2fdisplay-values-of-a-dictionary-in-tensorlow%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Tensorflow is a statically typed framework (guess this is changing in 2.0). Meaning, you first build a static graph and the graph has values only when run using Tf.Session(). Now to answer your question. There are two ways to get what you want.




            1. Add tf.enable_eager_execution() at the start of your script. This creates a dynamic graph (similar to Pytorch). Your same code without any extra addition will give you what you want.


            2. Wrap everything into a tf.Session() and run it. You will get the weight matrices







            share|improve this answer




























              0














              Tensorflow is a statically typed framework (guess this is changing in 2.0). Meaning, you first build a static graph and the graph has values only when run using Tf.Session(). Now to answer your question. There are two ways to get what you want.




              1. Add tf.enable_eager_execution() at the start of your script. This creates a dynamic graph (similar to Pytorch). Your same code without any extra addition will give you what you want.


              2. Wrap everything into a tf.Session() and run it. You will get the weight matrices







              share|improve this answer


























                0












                0








                0







                Tensorflow is a statically typed framework (guess this is changing in 2.0). Meaning, you first build a static graph and the graph has values only when run using Tf.Session(). Now to answer your question. There are two ways to get what you want.




                1. Add tf.enable_eager_execution() at the start of your script. This creates a dynamic graph (similar to Pytorch). Your same code without any extra addition will give you what you want.


                2. Wrap everything into a tf.Session() and run it. You will get the weight matrices







                share|improve this answer













                Tensorflow is a statically typed framework (guess this is changing in 2.0). Meaning, you first build a static graph and the graph has values only when run using Tf.Session(). Now to answer your question. There are two ways to get what you want.




                1. Add tf.enable_eager_execution() at the start of your script. This creates a dynamic graph (similar to Pytorch). Your same code without any extra addition will give you what you want.


                2. Wrap everything into a tf.Session() and run it. You will get the weight matrices








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 16 '18 at 0:31









                Abhijit BalajiAbhijit Balaji

                545421




                545421
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53329708%2fdisplay-values-of-a-dictionary-in-tensorlow%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python