Hello everybody! I am new to topic creation in general so I would request a bit of patience if I do not do everything correctly from the start
Background
I use trainer.get_policy().export_model()
export to get a TFModel. The model is exported succesfully.
What’s the problem?
I am unable to load with tf.saved_model.load()
or use the model with SavedModel CLI.
Script
ray.init()
trainer = DQNTrainer(env="CartPole-v0")
for i in range(2):
result = trainer.train()
print(pretty_print(result))
if i % 1 == 0:
checkpoint = trainer.save()
print("checkpoint saved at", checkpoint)
trainer.get_policy().export_model('test_model')
predict_fn = tf.saved_model.load('test_model')
Error message
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.utils.build_tensor_info or tf.compat.v1.saved_model.build_tensor_info.
WARNING:tensorflow:Unable to create a python object for variable <tf.Variable 'default_policy/lr:0' shape=() dtype=float32_ref> because it is a reference variable. It may not be visible to training APIs. If this is a problem, consider rebuilding the SavedModel after running tf.compat.v1.enable_resource_variables().
WARNING:tensorflow:Unable to create a python object for variable <tf.Variable 'default_policy/timestep_1:0' shape=() dtype=int64_ref> because it is a reference variable. It may not be visible to training APIs. If this is a problem, consider rebuilding the SavedModel after running tf.compat.v1.enable_resource_variables().
WARNING:tensorflow:Unable to create a python object for variable <tf.Variable 'default_policy/global_step:0' shape=() dtype=int64_ref> because it is a reference variable. It may not be visible to training APIs. If this is a problem, consider rebuilding the SavedModel after running tf.compat.v1.enable_resource_variables().
WARNING:tensorflow:Unable to create a python object for variable <tf.Variable 'default_policy/lr:0' shape=() dtype=float32_ref> because it is a reference variable. It may not be visible to training APIs. If this is a problem, consider rebuilding the SavedModel after running tf.compat.v1.enable_resource_variables().
WARNING:tensorflow:Unable to create a python object for variable <tf.Variable 'default_policy/timestep_1:0' shape=() dtype=int64_ref> because it is a reference variable. It may not be visible to training APIs. If this is a problem, consider rebuilding the SavedModel after running tf.compat.v1.enable_resource_variables().
WARNING:tensorflow:Unable to create a python object for variable <tf.Variable 'default_policy/global_step:0' shape=() dtype=int64_ref> because it is a reference variable. It may not be visible to training APIs. If this is a problem, consider rebuilding the SavedModel after running tf.compat.v1.enable_resource_variables().
WARNING:tensorflow:Some variables could not be lifted out of a loaded function. Run the tf.initializers.tables_initializer() operation to restore these variables.
WARNING:tensorflow:Unable to create a python object for variable <tf.Variable 'default_policy/lr:0' shape=() dtype=float32_ref> because it is a reference variable. It may not be visible to training APIs. If this is a problem, consider rebuilding the SavedModel after running tf.compat.v1.enable_resource_variables().
WARNING:tensorflow:Unable to create a python object for variable <tf.Variable 'default_policy/timestep_1:0' shape=() dtype=int64_ref> because it is a reference variable. It may not be visible to training APIs. If this is a problem, consider rebuilding the SavedModel after running tf.compat.v1.enable_resource_variables().
WARNING:tensorflow:Unable to create a python object for variable <tf.Variable 'default_policy/global_step:0' shape=() dtype=int64_ref> because it is a reference variable. It may not be visible to training APIs. If this is a problem, consider rebuilding the SavedModel after running tf.compat.v1.enable_resource_variables().
Traceback (most recent call last):
File "Python36\python.exe\lib\code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "test.py", line 64, in <module>
predict_fn = tf.saved_model.load('test_model')
File "\venv\lib\site-packages\tensorflow\python\saved_model\load.py", line 859, in load
return load_internal(export_dir, tags, options)["root"]
File "\venv\lib\site-packages\tensorflow\python\saved_model\load.py", line 909, in load_internal
root = load_v1_in_v2.load(export_dir, tags)
File "\venv\lib\site-packages\tensorflow\python\saved_model\load_v1_in_v2.py", line 279, in load
return loader.load(tags=tags)
File "\venv\lib\site-packages\tensorflow\python\saved_model\load_v1_in_v2.py", line 262, in load
signature_functions = self._extract_signatures(wrapped, meta_graph_def)
File "\venv\lib\site-packages\tensorflow\python\saved_model\load_v1_in_v2.py", line 169, in _extract_signatures
signature_fn = wrapped.prune(feeds=feeds, fetches=fetches)
File "\venv\lib\site-packages\tensorflow\python\eager\wrap_function.py", line 338, in prune
base_graph=self._func_graph)
File "\venv\lib\site-packages\tensorflow\python\eager\lift_to_graph.py", line 260, in lift_to_graph
add_sources=add_sources))
File "\venv\lib\site-packages\tensorflow\python\ops\op_selector.py", line 413, in map_subgraph
% (repr(init_tensor), repr(op), _path_from(op, init_tensor, sources)))
tensorflow.python.ops.op_selector.UnliftableError: A SavedModel signature needs an input for each placeholder the signature's outputs use. An output for signature 'serving_default' depends on a placeholder which is not an input (i.e. the placeholder is not fed a value).
Unable to lift tensor <tf.Tensor 'default_policy/zeros_like_1:0' shape=(?,) dtype=float32> because it depends transitively on placeholder <tf.Operation 'default_policy/timestep' type=Placeholder> via at least one path, e.g.: default_policy/zeros_like_1 (Fill) <- default_policy/zeros_like_1/Const (Const) <- default_policy/Assign (Assign) <- default_policy/timestep (Placeholder)
Additional info for SavedModel CLI
I also tried using this example and again have a problem loading the model created.
Finally I tried using the model with SavedModel CLI of tensorflow following this. The input I used was:
saved_model_cli run --dir test_model --tag_set serve --signature_def serving_default --inputs observations=test.npy
The test.npy
has a simple numpy array created by np.array([[0.1, 0.2, 0.3, 0.4]])
The resulting error essentially was (I removed most of the error meassge I can add it later if wanted):
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'default_policy/timestep' with dtype int64
[[node default_policy/timestep (defined at C:\Users\lgravias\PycharmProjects\RL_lib_tester\venv\Scripts\saved_model_cli.exe\__main__.py:7) ]]
Which to my understanding means that there needs to be an input for the timestep which however is not included in the iputs of the model.
Am I understanding something incorrectly? Do I use the framework incorrectly? Or is this a bug?
Thanks to anyone who may take the time to help!