tensorflow: list index out of range in freeze_graph.py
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow):NO
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04):Linux Ubuntu 16.04.5
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:No
- TensorFlow installed from (source or binary):binary
- TensorFlow version (use command below):1.12.0
- Python version:3.5.2
- Bazel version (if compiling from source):
- GCC/Compiler version (if compiling from source):
- CUDA/cuDNN version:9.0/7.0
- GPU model and memory:GTX 1080 11GB
Describe the current behavior
I try to freeze graph generated by tf.esitimator. esitimator will generate *.pbtxt and ckpt file automatically, so I use following command:
python freeze_graph.py --input_graph=path/to/.pbtxt --input_checkpoint=path/to/model.ckpt-0 --output_graph=path/to/saved/.pb --output_node_name=OutPutOp
Other info / logs
Traceback (most recent call last): File "model_freeze.py", line 494, in <module> run_main() File "model_freeze.py", line 490, in run_main app.run(main=my_main, argv=[sys.argv[0]] + unparsed) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 125, in run _sys.exit(main(argv)) File "model_freeze.py", line 489, in <lambda> my_main = lambda unused_args: main(unused_args, flags) File "model_freeze.py", line 382, in main flags.saved_model_tags, checkpoint_version) File "model_freeze.py", line 364, in freeze_graph checkpoint_version=checkpoint_version) File "model_freeze.py", line 191, in freeze_graph_with_def_protos var_list=var_list, write_version=checkpoint_version) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 1102, in __init__ self.build() File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 1114, in build self._build(self._filename, build_save=True, build_restore=True) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 1151, in _build build_save=build_save, build_restore=build_restore) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 773, in _build_internal saveables = self._ValidateAndSliceInputs(names_to_saveables) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 680, in _ValidateAndSliceInputs for converted_saveable_object in self.SaveableObjectsForOp(op, name): File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 654, in SaveableObjectsForOp variable, "", name) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 128, in __init__ self.handle_op = var.op.inputs[0] File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 2128, in __getitem__ return self._inputs[i] IndexError: list index out of range
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 9
- Comments: 27 (3 by maintainers)
I have the same problem when using keras advanced layers.
same here.
I believe this is still not working with the latest version of tensorflow 2.1.0. The error becomes:
self.handle_op = var.op.inputs[0] IndexError: tuple index out of range
@ymodak Any updates on this?The full stack error is:
@jvishnuvardhan Thank you for checking on this. It links to couple other issues #22029 #5387 #4363
Here I provides a minimal code using tf hub:
Then I encountered the IndexError as I run
python -m tensorflow.python.tools.freeze_graph --input_graph=resnet/model.pb --input_checkpoint=resnet/model --output_graph=resnet/frozen_graph.pb --output_node_names=module/resnet_v2_50/predictions/Reshape_1 --input_binary
At the same time, i have successfully frozen a plain-vanilla single layer CNN. Could you point some directions to check? Thanks!
Do you have any progress?I have the same problem.
I get the same issue when I try to freeze the bidirectional LSTM network from tensor2tensor (https://github.com/tensorflow/tensor2tensor/blob/v.1.12.0/tensor2tensor/models/lstm.py).
I got same issue. Here is the actual script help me to freeze the model. Note that you need to modify the output node name manually. And I successfully loaded the frozen model onto android.
@jiayiliu - yes, I am using the internal
tensorflow.keras
.My workaround has been to use
tf.saved_model.simple_save
instead of aSaver
and have freeze_graph use input_saved_model_dir.It gets me past this problem but I don’t consider the issue resolved. If freeze_graph is not going to support working on normal graphs it should deprecate that api and update the docs, or at least put a note that for keras models you have to used saved_model.
I’m getting the same error on a keras implementation of yolo.
The error occurs in
__init__
of aResourceVariableSaveable
when trying to accessvar.op.inputs[0]
on a tensor:op is a “VarHandleOp” and
var.op.inputs
is atensorflow.python.framework.ops.Operation._InputList
object.The input list in this case is empty. Does the resource variable have to have an input? What should handle_op be in this case?
Any suggestions for how to proceed?