WARNING: This property should not be used in TensorFlow 2.0, as updates are applied automatically

2.6k views Asked by At

I was running some code in Google Colab. I defined my own model "MyModel()" and some functions (not shown because it's too long), which is inherited from 'tf.keras.Model'.

'''

save_model_path='./models' # path to save trained model
save_mat_folder='./results' # path to save reconstruction examples
log_path='./tensorboard_log' # path to log training process
load_model_path = save_model_path

model = MyModel()

summary_writer = tf.summary.create_file_writer(log_path)
tf.summary.trace_on(graph = True,profiler = False)

variables = [model.phi1,model.phi2] # write variables in a list

# define optimizer
optimizer =  tf.keras.optimizers.Adam(learning_rate= 1e-3)
for i in tf.range(50):
    # print(i)
    # below for TF 1.x:
    # loss,summary,_=sess.run([L,merged,train_op],feed_dict) #run(fetches, feed_dict=None, options=None, run_metadata=None)
    # model1_writer.add_summary(summary,global_step = i)
    # below for TF2.x:
    with tf.GradientTape() as tape:
        # loss function
        loss = model.call(Ein)
    # The tape is automatically erased immediately after you call its gradient() method
    grads = tape.gradient(loss, variables) ## auto-differentiation,powerful !!
    # TensorFlow will update parameters automatically
    optimizer.apply_gradients(grads_and_vars=zip(grads, variables))
    # train_op = optimizer.minimize(L) # calculates gradients automatically
    with summary_writer.as_default():
        tf.summary.scalar('loss', loss, step = tf.cast(i,tf.int64))
    if i % 10 == 0:
        print(loss)
# export trace 
with summary_writer.as_default():
    tf.summary.trace_export(name ='model_trace',step=0 ) #, profiler_outdir = log_path) 
    tf.saved_model.save(model, save_model_path)
# save_path=saver.save(sess,save_model_path)

'''

The code looks worked, but got unexpected warnings. Can anyone tell me source of the warning?

Below are the running outputs: **

tf.Tensor(-8.2480165e-06, shape=(), dtype=float32)
tf.Tensor(-8.653108e-06, shape=(), dtype=float32)
tf.Tensor(-9.343687e-06, shape=(), dtype=float32)
tf.Tensor(-1.0216764e-05, shape=(), dtype=float32)
tf.Tensor(-1.1233077e-05, shape=(), dtype=float32)
WARNING:tensorflow:Skipping full serialization of Keras layer <__main__.MyModel object at 0x7fea4a9e9e48>, because it is not built.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/tracking.py:111: Model.state_updates (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.
Instructions for updating:
This property should not be used in TensorFlow 2.0, as updates are applied automatically.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/tracking.py:111: Layer.updates (from tensorflow.python.keras.engine.base_layer) is deprecated and will be removed in a future version.
Instructions for updating:
This property should not be used in TensorFlow 2.0, as updates are applied automatically.
INFO:tensorflow:Assets written to: ./models/assets

**

1

There are 1 answers

0
AudioBubble On

These are the Deprecation Warnings, which we can suppress using one of the below code snippets

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' 
import tensorflow as tf