shamangary / FSA-Net

[CVPR19] FSA-Net: Learning Fine-Grained Structure Aggregation for Head Pose Estimation from a Single Image
Apache License 2.0
608 stars 155 forks source link

Conversion to tensorflow frozen graph #36

Closed liam800 closed 4 years ago

liam800 commented 4 years ago

Hi, when i run "keras_to_tf.py" to convert to tensorflow frozen graph, i enconter this error: File "keras_to_tf.py", line 173, in main tf.io.write_graph(frozen_graph, tf_dir_path, module 'tensorflow.io' has no attribute 'write_graph' my tensorflow version is 1.10.0. so i am confused whether i need to upgrade tensorflow? thanks.

leviethung2103 commented 4 years ago

You can try to upgrade to Tensorflow 1.14 version that I am using. I think you need to set up the package versions correctly accordingly the authors.

liam800 commented 4 years ago

When updated Tensorflow to 1.14.0, then raise error like this: raise ValueError("Cannot find the variable that is an input " ValueError: Cannot find the variable that is an input to the ReadVariableOp. look forward to a reply,thanks!

leviethung2103 commented 4 years ago

I haven't encountered this error.

Here are my suggestions: 1/ Replace the the line 173

tf.io.write_graph(frozen_graph, tf_dir_path,
                      f"{model_name}.pb", as_text=False)

with tf.train.write_graph(frozen_graph, tf_dir_path, f"{model_name}.pb", as_text=False)

2/ Create a new python virtual environment, install TF2.0 and try to convert.

I think there is no problem with the author's code. You can use pip freeze to watch out the versions of installed package. Make sure that your tensorflow and keras versions are correctly installed.

liam800 commented 4 years ago

I haven't encountered this error.

Here are my suggestions: 1/ Replace the the line 173

tf.io.write_graph(frozen_graph, tf_dir_path,
                      f"{model_name}.pb", as_text=False)

with tf.train.write_graph(frozen_graph, tf_dir_path, f"{model_name}.pb", as_text=False)

2/ Create a new python virtual environment, install TF2.0 and try to convert.

I think there is no problem with the author's code. You can use pip freeze to watch out the versions of installed package. Make sure that your tensorflow and keras versions are correctly installed.

gabrielibagon commented 4 years ago

When updated Tensorflow to 1.14.0, then raise error like this: raise ValueError("Cannot find the variable that is an input " ValueError: Cannot find the variable that is an input to the ReadVariableOp. look forward to a reply,thanks!

I'm still facing this same error as @liam800. The solutions @leviethung2103 posted above doesn't work for me.

Suggestion 1 - The error above is not involved with this line. It occurs with the previous line: frozen_graph = freeze_session(sess, output_names=[out.op.name for out in model.outputs])

Suggestion 2 - The repository is not compatible with TensorFlow 2.0. Both the model and keras_to_tf.py break with TF2.0.

Has anybody gotten keras_to_tf.py to work for TensorFlow==1.14.0 and Keras==2.3.1?

gabrielibagon commented 4 years ago

Update: the keras_to_tf.py script works correctly with Tensorflow 1.15.0