Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.

Convert tensorflow YOLOv3 model: *.pb file to IR Model error

nickle__fang
Beginner
2,132 Views

First I use YOLOv3 to train my own dataset using tensorflow==1.15.3, and I got three model files:

model-epoch_90_step_22659_loss_0.3480_lr_1e-05.data-00000-of-00001

model-epoch_90_step_22659_loss_0.3480_lr_1e-05.index

model-epoch_90_step_22659_loss_0.3480_lr_1e-05.meta

And then I use the following code to freeze the model to a .pb file:

# -*- coding: utf-8 -*-
import tensorflow as tf
from tensorflow.python.framework import graph_util
import os
os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
import cv2
import numpy as np


def freeze_graph(input_checkpoint, output_graph):
    output_node_names = "Sigmoid"
    saver = tf.train.import_meta_graph(input_checkpoint + '.meta', clear_devices=True)
    graph = tf.get_default_graph()  
    input_graph_def = graph.as_graph_def()  

    with tf.Session() as sess:
        saver.restore(sess, input_checkpoint)  
        node_names = [n.name for n in input_graph_def.node]
        print(node_names)
        with open('./nodes.txt', 'a+') as w:
            for node in node_names:
                w.write(node + '\n')

        output_graph_def = graph_util.convert_variables_to_constants(  
            sess=sess,
            input_graph_def=input_graph_def,  
            output_node_names=output_node_names.split(",")) 

        with tf.gfile.GFile(output_graph, "wb") as f:  
            f.write(output_graph_def.SerializeToString()) 
        print("%d ops in the final graph." % len(output_graph_def.node))  


if __name__ == '__main__':
    input_checkpoint = '/home/zjunlict/Desktop/YOLOv3_TensorFlow/IR_Output/model-epoch_90_step_22659_loss_0.3480_lr_1e-05'
    out_pb_path = "/home/zjunlict/Desktop/YOLOv3_TensorFlow/IR_Output/frozen_model_10000.pb"
    freeze_graph(input_checkpoint, out_pb_path)

Then I got a .pb file and a nodes.txt. I use the command 

python3 mo_tf.py --input_model /home/zjunlict/Desktop/YOLOv3_TensorFlow/IR_Output/frozen_model_10000.pb --tensorflow_use_custom_operations_config /opt/intel/openvino/deployment_tools/model_optimizer/extensions/front/tf/yolo_v3.json --input_shape=[1,416,416,3]  --data_type=FP16

and I got the error:

[ WARNING ]  Use of deprecated cli option --tensorflow_use_custom_operations_config detected. Option use in the following releases will be fatal. Please use --transformations_config cli option instead
Model Optimizer arguments:
Common parameters:
	- Path to the Input Model: 	/home/zjunlict/Desktop/YOLOv3_TensorFlow/IR_Output/frozen_model_10000.pb
	- Path for generated IR: 	/opt/intel/openvino_2020.3.194/deployment_tools/model_optimizer/.
	- IR output name: 	frozen_model_10000
	- Log level: 	ERROR
	- Batch: 	Not specified, inherited from the model
	- Input layers: 	Not specified, inherited from the model
	- Output layers: 	Not specified, inherited from the model
	- Input shapes: 	[1,416,416,3]
	- Mean values: 	Not specified
	- Scale values: 	Not specified
	- Scale factor: 	Not specified
	- Precision of IR: 	FP16
	- Enable fusing: 	True
	- Enable grouped convolutions fusing: 	True
	- Move mean values to preprocess section: 	False
	- Reverse input channels: 	False
TensorFlow specific parameters:
	- Input model in text protobuf format: 	False
	- Path to model dump for TensorBoard: 	None
	- List of shared libraries with TensorFlow custom layers implementation: 	None
	- Update the configuration file with input/output node names: 	None
	- Use configuration file used to generate the model with Object Detection API: 	None
	- Use the config file: 	/opt/intel/openvino/deployment_tools/model_optimizer/extensions/front/tf/yolo_v3.json
Model Optimizer version: 	
[ ANALYSIS INFO ]  It looks like there are input nodes of boolean type:
	phase_train
If this input node is as switch between the training and an inference mode, then you need to freeze this input with value True or False.
In order to do this run the Model Optimizer with the command line parameter:
	--input "phase_train->False" or --input "phase_train->True"
to switch graph to inference mode.
[ ANALYSIS INFO ]  It looks like there is IteratorGetNext as input
Run the Model Optimizer with:
		--input "IteratorGetNext:1[]"
And replace all negative values with positive values
[ ERROR ]  Exception occurred during running replacer "TFYOLOV3" (<class 'extensions.front.YOLO.YoloV3RegionAddon'>): TensorFlow YOLO V3 conversion mechanism was enabled. Entry points "yolo-v3/Reshape, yolo-v3/Reshape_4, yolo-v3/Reshape_8" were provided in the configuration file. Entry points are nodes that feed YOLO Region layers. Node with name yolo-v3/Reshape doesn't exist in the graph. Refer to documentation about converting YOLO models for more information.

This is my yolo_v3.json:

[
  {
    "id": "TFYOLOV3",
    "match_kind": "general",
    "custom_attributes": {
      "classes": 3,
      "anchors": [10,9, 15,14, 21,22, 37,32, 25,54, 54,44, 72,65, 192,43, 103,98],
      "coords": 4,
      "num": 9,
      "masks":[[6, 7, 8], [3, 4, 5], [0, 1, 2]],
      "entry_points": ["yolo-v3/Reshape", "yolo-v3/Reshape_4", "yolo-v3/Reshape_8"]
    }
  }
]

How can I solve this problem and got the right IR files? Thanks a lot!

0 Kudos
5 Replies
nickle__fang
Beginner
2,132 Views

I met some problems uploading my .pb files. If anyone wants to check it I can send it via e-mail to you.

0 Kudos
Munesh_Intel
Moderator
2,132 Views

Hi Fang,

Please share the trained model files for us to reproduce your issue (files can be shared via Private Message).

Additionally, please provide your environment details as well (versions of OpenVINO, OS, etc.).

 

Regards,

Munesh

 

0 Kudos
AlexQuan
Beginner
1,588 Views

Hi there

 

I got different detect results between tensorflow pb model and openvino IR model,  

the model is YOLOv3 and my convert command is like this:

python /opt/intel/openvino/deployment_tools/model_optimizer/mo_tf.py \
--input_model /home/admin/cellphoneUseDetect_20210711_mAP73.pb \
--input_shape [1,608,608,3] \
--data_type FP32

 Could you please help me with this issue? Thanks a lot!

0 Kudos
D__yugendra
Novice
2,059 Views

I am also facing same problem. Have you solved?

Thank you

0 Kudos
D__yugendra
Novice
2,033 Views

Hi,

please check output node names in converting Pb file, and as per the output node name change your YoloV3. Jason entry_points. The problem will solve.

Thank you.

0 Kudos
Reply