Skip to content

Error in using tensorflow model with opencv dnn module. #17364

@naserpiltan

Description

@naserpiltan

Hi.
Im working on a road segmentation project with tensorflow. I searched and find this usefull repo :
https://github.com/MaybeShewill-CV/lanenet-lane-detection
Author has provided a link to pre-trained checkpoints file as this :
https://www.dropbox.com/sh/tnsf0lw6psszvy4/AAA81r53jpUI3wLsRW6TiPCya?dl=0

I downloaded this check points and froze them with freeze_lanenet_model.py script in the mnn_project folder of project and now i have a model with this name : lanenet.pb

freeze_lanenet_model main function is this :

def convert_ckpt_into_pb_file(ckpt_file_path, pb_file_path):

:param ckpt_file_path:
:param pb_file_path:
:return:
"""
# construct compute graph
with tf.variable_scope('lanenet'):
    input_tensor = tf.placeholder(dtype=tf.float32, shape=[1, 256, 512, 3], name='input_tensor')

net = lanenet.LaneNet(phase='test', net_flag='vgg')
binary_seg_ret, instance_seg_ret = net.inference(input_tensor=input_tensor, name='lanenet_model')

with tf.variable_scope('lanenet/'):
    binary_seg_ret = tf.cast(binary_seg_ret, dtype=tf.float32)
    binary_seg_ret = tf.squeeze(binary_seg_ret, axis=0, name='final_binary_output')
    instance_seg_ret = tf.squeeze(instance_seg_ret, axis=0, name='final_pixel_embedding_output')

# create a session
saver = tf.train.Saver()

sess_config = tf.ConfigProto()
sess_config.gpu_options.per_process_gpu_memory_fraction = 0.85
sess_config.gpu_options.allow_growth = False
sess_config.gpu_options.allocator_type = 'BFC'

sess = tf.Session(config=sess_config)

with sess.as_default():
    saver.restore(sess, ckpt_file_path)

    converted_graph_def = tf.graph_util.convert_variables_to_constants(
        sess,
        input_graph_def=sess.graph.as_graph_def(),
        output_node_names=[
            'lanenet/input_tensor',
            'lanenet/final_binary_output',
            'lanenet/final_pixel_embedding_output'
        ]
    )

    with tf.gfile.GFile(pb_file_path, "wb") as f:
        f.write(converted_graph_def.SerializeToString())`

Now i wanna use this saved model in opencv dnn module like this :
Net net = readNetFromTensorflow("lanenet.pb");

But when i run the code , i have this error :
OpenCV(4.2.0) /home/eagle-soft/opencv/modules/dnn/src/tensorflow/tf_importer.cpp:544: error: (-2:Unspecified error) Input layer not found: lanenet_model/vgg_frontend/vgg16_decode_module/instance_seg_decode/decode_stage_1_fuse/deconv/deconv/Shape in function 'connect'
I searched a lot but couldn't find a same issue and solution.
Please give me some workaround to solve this annoying problem.
Thanks in advande.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions