in Education by
In the tensorflow documentation at the autograph section we have the following code snippet @tf.function def train(model, optimizer): train_ds = mnist_dataset() step = 0 loss = 0.0 accuracy = 0.0 for x, y in train_ds: step += 1 loss = train_one_step(model, optimizer, x, y) if tf.equal(step % 10, 0): tf.print('Step', step, ': loss', loss, '; accuracy', compute_accuracy.result()) return step, loss, accuracy step, loss, accuracy = train(model, optimizer) print('Final step', step, ': loss', loss, '; accuracy', compute_accuracy.result()) I have a small question concerning the step variable, it's an integer and not a tensor, autograph supports built-in python type such as integer. Therefore the tf.equal(step%10,0) could be changed to simply step%10 == 0 right ? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Yes, you're right. The integer variable step remains a Python variable even when converted to its graph representation. You can see the conversion result by calling tf.autograph.to_code(train.python_function). Without reporting all the code but only the step variable related part, you'll see that def loop_body(loop_vars, loss_1, step_1): with ag__.function_scope('loop_body'): x, y = loop_vars step_1 += 1 Is still a python operation (otherwise it will be step_1.assign_add(1) if step 1 was a tf.Tensor). For more information about autograph and tf.function I suggest reading the article https://pgaleone.eu/tensorflow/tf.function/2019/03/21/dissecting-tf-function-part-1/ that explains easily what happens when a function is converted.

Related questions

0 votes
    I created an LSTM with Keras API. Now I am facing an issue while I try to test different values ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I am trying to implement the tutorial given on Tensorflow tutorial on custom training. Due to some reason ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I'm using TensorFlow Alpha 2.0. I have TFRecords files I'm reading from, each one holding a short ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    What does the following function do? Should I consider it as a lookup table like in skip-gram model? tf.nn. ... mod', name=None) Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    In the chapter seven of this book "TensorFlow Machine Learning Cookbook" the author in pre-processing data ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I have a DQN all set up and working, but I can't figure out how to display the loss without ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    In the MNIST beginner tutorial, there is the statement accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) tf ... (x,1)? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I was looking at the docs of TensorFlow about tf.nn.conv2d here. But I can't understand what it does or ... it raised the question. Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    Is tf.contrib.layers.flatten(x) the same as tf.reshape(x, [n, 1])? Can anyone help me with this? Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    In tf.nn.max_pool of tensorflow what is the difference between 'SAME' and 'VALID'? I read in here that ... pool means in tensorflow? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    Convert the Boolean function, F(x, y, z) = ∏(0, 2, 6, 7) in sum of minterm form. Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    FIbonacci Series Program function fibonacciSequence(input) { var a=0;b=1;c=0; var array1=[0,1]; for(var i=2;i...
asked Feb 24, 2021 in Technology by JackTerrance
...