Converting a TensorFlow* Model - tensorflow

I want to convert my 1 tensorflow model to IR currently I am following the instructions here:
https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_convert_model_Convert_Model_From_TensorFlow.html
The model I use is meta graph and ubuntu 16.04
I ran the line deflected:
python3 mo_tf.py --input_meta_graph .meta
then it will get an error:
[ERROR] Exception occurred during running replacer "None" (): Data flow edge coming out of AssignSub node model_0 / resnet_v1_50 / block4 / unit_1 / bottleneck_v1 / shortcut / BatchNorm / AssignMovingAvg
Can you guys please help me? thanks everyone

Did you freeze the model before conversion? Please look at how to freeze your model using instructions from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py and retry.

Related

Unable to convert tensorflow Mask-Rcnn to IR with Open Vino toolkit

python mo_tf.py
--saved_model_dir C:\DATASETS\mask50000\exports\saved_model
--output_dir C:\DATASETS\mask50000
--reverse_input_channels
--tensorflow_custom_operations_config extensions\front\tf\mask_rcnn_support_api_v2.0.json
--tensorflow_object_detection_api_pipeline_config C:\DATASETS\mask50000\exports\pipeline.config
--log_level=DEBUG
I have been trying to convert the model using the above script, but every time I got the error:
"Exception: Exception occurred during running replacer "REPLACEMENT_ID (<class'extensions.front.tf.tensorflow_custom_operations_config_update.TensorflowCustomOperationsConfigUpdate'>)": The function 'update_custom_layer_attributes' must be implemented in the sub-class."
I have exported the graph using exporter_main_v2.py. If more information is needed please inform me.
EDIT:
I was able to convert the model by changing the file mask_rcnn_support_api_v2.4.json.
first change:
"custom_attributes": {
"operation_to_add": "Proposal",
"clip_before_nms": false,
"clip_after_nms": true
}
second change:
"start_points": [
"StatefulPartitionedCall/concat/concat",
"StatefulPartitionedCall/concat_1/concat",
"StatefulPartitionedCall/GridAnchorGenerator/Identity",
"StatefulPartitionedCall/Cast",
"StatefulPartitionedCall/Cast_1",
"StatefulPartitionedCall/Shape"
]
that solved the problme.
OpenVINO 2020.4 is not compatible with TensorFlow 2. Support for TF 2.0 Object Detection API models was fully enabled only in OpenVINO 2021.3.
I’ve successfully converted the model mask_rcnn_inception_resnet_v2_1024x1024_coco17 to IR using the latest OpenVINO release (2021.4.752).
I share the MO conversion command here:
python mo_tf.py --saved_model_dir <model_dir>\saved_model --tensorflow_object_detection_api_pipeline_config <pipeline_dir>\pipeline.config --transformations_config <installed_dir>\extensions\front\tf\mask_rcnn_support_api_v2.0.json"

How can i fix the error tensorflow has not attribute 'ConfigProto' witthout deprecating?

i'm trying to train a Retinanet on my Dataset with this command line :
retinanet-train --batch-size 4 --steps 349 --epochs 50 --weights logos/resnet50_coco_best_v2.1.0.h5 --snapshot-path logos/snapshots csv logos/retinanet_train.csv logos/retinanet_classes.csv
And I get this Error :
AttributeError: module 'tensorflow' has no attribute 'ConfigProto'
I know that , this is related to the version of Tensorlow , in the new version ConfigProto disappeared , but i want to fix it without 're-installing' the old version the 1.14, cause otherwise it will be a mess.
Any suggestion would be super appreciated , thank you.
Since tf.ConfigProto is deprecated in TF 2.0, use tf.compat.v1.ConfigProto() instead by replacing the occurences of tf.ConfigProto() in the retinanet-train code (assuming that's where tf.ConfigProto() is being called). Link to tensorflow doc here.

"No graph definition files were found" - TensorBoard error

I used the following code in Pycharm:
import tensorflow as tf
sess = tf.Session()
a = tf.constant(value=5, name='input_a')
b = tf.constant(value=3, name='input_b')
c = tf.multiply(a,b, name='mult_c')
d = tf.add(a,b, name='add_d')
e = tf.add(c,d, name='add_e')
print(sess.run(e))
writer = tf.summary.FileWriter("./tb_graph", sess.graph)
Then, I pasted following line to the Anaconda Prompt:
tensorboard --logdir=="tb_graph"
I tried both with "" and '' as there were proposed: Tensorboard: No graph definition files were found. and it does nothing for me.
I had similar issue. The issue occurred when I specified 'logdir' folder inside single quotes instead of double quotes. Hope this may be helpful to you.
egs: tensorboard --logdir='my_graph' -> Tensorboard didn't detect the graph
tensorboard --logdir="my_graph" -> Tensorboard detected the graph
I checked the code on laptop with Ubuntu 16.04 and another one with Win10, so it probably isn't system-based error.
I also tried adding and removing --host=127.0.0.1 in An Prompt and checking several times both http://localhost:6006/ and http://desktop-.......:6006/.
Still same error:
No graph definition files were found.
To store a graph, create a tf.summary.FileWriter and pass the graph either via the constructor, or by calling its add_graph() method. You may want to check out the graph visualizer tutorial.
....
Please tell me what is wrong in the code/propmp command?
EDIT: On Ubuntu I used the normal terminal, of course.
EDIT2: I used both = and == in command prompt
The answer to my question is:
1) change "./new1_dir" into ".\\new1_dir"
and
2)put full track to file to anaconda propmpt: --logdir="C:\Users\Admin\Documents\PycharmProjects\try_tb\new1_dir"
Thanks #BugKiller for your help!
EDIT: Working only on Windows for me, but still better than nothing
EDIT2: Works on Ubuntu 16.04 too

ValueError: Input 0 of node Variable/Assign was passed int32 from Variable:0 incompatible with expected int32_ref

I am currently trying to get a trained TF seq2seq model working with Tensorflow.js. I need to get the json files for this. My input is a few sentences and the output is "embeddings". This model is working when I read in the checkpoint however I can't get it converted for tf.js. Part of the process for conversion is to get my latest checkpoint frozen as a protobuf (pb) file and then convert that to the json formats expected by tensorflow.js.
The above is my understanding and being that I haven't done this before, it may be wrong so please feel free to correct if I'm wrong in what I have deduced from reading.
When I try to convert to the tensorflow.js format I use the following command:
sudo tensorflowjs_converter --input_format=tf_frozen_model
--output_node_names='embeddings'
--saved_model_tags=serve
./saved_model/model.pb /web_model
This then displays the error listed in this post:
ValueError: Input 0 of node Variable/Assign was passed int32 from
Variable:0 incompatible with expected int32_ref.
One of the problems I'm running into is that I'm really not even sure how to troubleshoot this. So I was hoping that perhaps one of you maybe had some guidance or maybe you know what my issue may be.
I have upped the code I used to convert the checkpoint file to protobuf at the link below. I then added to the bottom of the notebook an import of that file that is then providing the same error I get when trying to convert to tensorflowjs format. (Just scroll to the bottom of the notebook)
https://github.com/xtr33me/textsumToTfjs/blob/master/convert_ckpt_to_pb.ipynb
Any help would be greatly appreciated!
Still unsure as to why I was getting the above error, however in the end I was able to resolve this issue by just switching over to using TF's SavedModel via tf.saved_model. A rough example of what worked for me can be found below should anyone in the future run into something similar. After saving out the below model, I was then able to perform the tensorflowjs_convert call on it and export the correct files.
if first_iter == True: #first time through
first_iter = False
#Lets try saving this badboy
cwd = os.getcwd()
path = os.path.join(cwd, 'simple')
shutil.rmtree(path, ignore_errors=True)
inputs_dict = {
"batch_decoder_input": tf.convert_to_tensor(batch_decoder_input)
}
outputs_dict = {
"batch_decoder_output": tf.convert_to_tensor(batch_decoder_output)
}
tf.saved_model.simple_save(
sess, path, inputs_dict, outputs_dict
)
print('Model Saved')
#End save model code

Google Bigquery ML model schema ValueError

I'm using Google Bigquery ML for the first time and try to train a linear regression model using the following command:
%%bigquery
CREATE OR REPLACE MODEL `sandbox.sample_lr_model`
OPTIONS
(model_type='linear_reg',
data_split_method ='no_split',
max_iterations=1) AS
SELECT
y AS label,
x AS x
FROM
`sandbox.y2018m08d01_rh_sample_dataframe_to_bq_v01_v01`
this step fails with the following error message:
ValueError: Table has no schema: call 'client.get_table()'
However the model is created and can be viewed:
The model has a so-called "Model schema". Am I doing something wrong?
google-cloud-bigquery==1.4.0 Python 3.5 Ubuntu
My input table is a minimum example:
This issue was fixed in https://github.com/GoogleCloudPlatform/google-cloud-python/pull/5602, which was released in version 1.4.0 of BigQuery. To double-check your BigQuery version, run !pip freeze | grep bigquery in a notebook cell.
Note that Datalab does not include the latest version of the google-cloud-bigquery library. To upgrade the version, run !pip install --upgrade google-cloud-bigquery.