tensorflow: Unable to freeze graph for LinearClassifier
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): Windows 10
- TensorFlow installed from (source or binary): Anaconda
- TensorFlow version (use command below): 1.4.0
- Python version: 3.5.4
- Bazel version (if compiling from source): N/A
- GCC/Compiler version (if compiling from source): N/A
- CUDA/cuDNN version: N/A
- GPU model and memory: N/A
- Exact command to reproduce: freeze_graph for LinearClassifier model
I’m trying to freeze my model using the source https://www.tensorflow.org/mobile/prepare_models. So I could use it in Android app (using Tensorflow Mobile).
I have a model created with LinearClassifier. Below is the example of creating it:
gender = tf.feature_column.categorical_column_with_vocabulary_list("gender", ["f", "m"])
goal = tf.feature_column.categorical_column_with_vocabulary_list("goal", ["fit", "lose", "muscle"])
level = tf.feature_column.categorical_column_with_vocabulary_list("level", ["begin", "middle", "advance"])
feature_columns = [gender,goal,level]
input_fn = tf.estimator.inputs.pandas_input_fn(x=x_train, y=y_train, batch_size=100, num_epochs=None, shuffle=True)
model = tf.estimator.LinearClassifier(feature_columns=feature_columns, n_classes=18, model_dir="export")
model.train(input_fn=input_fn, steps=100)
The model is successfully created and saved. It works correctly when it’s evaluated. However, I’m getting the following error, when I try to freeze the graph:
TypeError: names_to_saveables must be a dict mapping string names to Tensors/Variables. Not a variable: Tensor("linear/linear_model/bias_weights:0", shape=(18,), dtype=float32)
I looked on StackOverflow and seems this issue happens to many people and there is no answer to that.
I would appreciate any help, because many people are having similar issue.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 24 (5 by maintainers)
@dkhmelenko I looked into the issue further and there seem to be some alternative ways that you can run the code using your SavedModel.
If you intend to run your code through TensorFlow Lite then you can use either
TocoConverter(Python API) ortflite_convert(command line tool) with your SavedModel. This should be working starting from TensorFlow 1.9. If not, it works on the nightly build. However, this results in the error mentioned above indicating there are some operators that aren’t supported. The solution to that error is mentioned in the comment below.If you just want to run
freeze_graph.pythen you should be able to run it with a SavedModel. The current error you are getting is coming from the code that loads the checkpoints. The command line below should work with your code. The values foroutput_node_namescame from the SignatureDef within your SavedModel.Let me know if one of these solutions suffices. In the meantime I’m looking for a solution to fix the problem in
freeze_graph.py.