Skip to content

Does opencv support faster_rcnn_inception_resnet_v2_atrous_oid? #14634

Closed

Description

@LaurentBerger

opencv version 4.1.0-dev
model http://download.tensorflow.org/models/object_detection/faster_rcnn_inception_resnet_v2_atrous_oid_2018_01_28.tar.gz

Detailed description
exception reading model :

cv2.error: OpenCV(4.1.0-dev) G:\Lib\opencv\modules\dnn\src\tensorflow\tf_importer.cpp:544: error: (-2:Unspecified error) Input layer not found: FirstStageBoxPredictor/ClassPredictor/BiasAdd in function 'cv::dnn::dnn4_v20190430::`anonymous-namespace'::TFImporter::connect'

Steps to reproduce

tf_text_graph_faster_rcnn.py --input frozen_inference_graph.pb --config pipeline.config --output frozen.pbtxt
Number of classes: 2854
Scales:            [0.25, 0.5, 1.0, 2.0]
Aspect ratios:     [0.5, 1.0, 2.0]
Width stride:      16.000000
Height stride:     16.000000
Features stride:   16.000000

then

cv.dnn.readNet('frozen_inference_graph.pb','frozen.pbtxt')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: OpenCV(4.1.0-dev) G:\Lib\opencv\modules\dnn\src\tensorflow\tf_importer.cpp:544: error: (-2:Unspecified error) Input layer not found: FirstStageBoxPredictor/ClassPredictor/BiasAdd in function 'cv::dnn::dnn4_v20190430::`anonymous-namespace'::TFImporter::connect'


Activity

  1. alex4men commented on Jun 6, 2019

    @alex4men

    I have very similar problem:

    opencv: 4.1.0 (from conda-forge channel)
    tensorflow: 1.13.1
    python: 3.7.3
    model: faster_rcnn_inception_resnet_v2_atrous_oid_v4_2018_12_12

    Detailed description

    exception reading model :

    cv2.error: OpenCV(4.1.0) ../modules/dnn/src/tensorflow/tf_importer.cpp:497: error: (-2:Unspecified error) Input layer not found: FirstStageBoxPredictor/ClassPredictor/BiasAdd in function 'connect'
    

    Steps to reproduce

    Export pbtxt from the model:

    python tf_text_graph_faster_rcnn.py --input frozen_inference_graph.pb --output frozen_inference_graph.pbtxt --config pipeline.config 
    Number of classes: 601
    Scales:            [0.25, 0.5, 1.0, 2.0]
    Aspect ratios:     [0.5, 1.0, 2.0]
    Width stride:      8.000000
    Height stride:     8.000000
    Features stride:   8.000000
    

    Add description to models.yaml:

    faster_rcnn_oid_tf:
      model: "frozen_inference_graph.pb"
      config: "frozen_inference_graph.pbtxt"
      mean: [0, 0, 0]
      scale: 1.0
      width: 800
      height: 800
      rgb: true
      classes: "oid_v4_label_map.txt"
      sample: "object_detection"
    

    then launch object_detection.py:

    python object_detection.py faster_rcnn_oid_tf
    Traceback (most recent call last):
      File "object_detection.py", line 70, in <module>
        net = cv.dnn.readNet(cv.samples.findFile(args.model), cv.samples.findFile(args.config), args.framework)
    cv2.error: OpenCV(4.1.0) ../modules/dnn/src/tensorflow/tf_importer.cpp:497: error: (-2:Unspecified error) Input layer not found: FirstStageBoxPredictor/ClassPredictor/BiasAdd in function 'connect'
    

    Link to the frozen_inference_graph.pb, frozen_inference_graph.pbtxt and oid_v4_label_map.txt files: here

  2. dkurt commented on Dec 31, 2019

    @dkurt
    Member

    Hi!

    According to #16113 (see the answer at https://stackoverflow.com/a/59541189/6548453), faster_rcnn_inception_resnet_v2_atrous_oid_2018_01_28 is supported. Going to try faster_rcnn_inception_resnet_v2_atrous_oid_v4_2018_12_12.

  3. dkurt commented on Dec 31, 2019

    @dkurt
    Member

    Thanks for this catch!

    Please try this patch #16270 considering a comment #13237 (comment) to modify pipeline.config:

    height_stride: 8
    width_stride: 8
    height_stride: 16
    width_stride: 16

    Output from OpenCV for faster_rcnn_inception_resnet_v2_atrous_oid_v4_2018_12_12:
    res

    import cv2 as cv
    
    cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'graph.pbtxt')
    
    img = cv.imread('S6yhf.jpg')
    rows = img.shape[0]
    cols = img.shape[1]
    cvNet.setInput(cv.dnn.blobFromImage(img, size=(800, 600), swapRB=True, crop=False))
    cvOut = cvNet.forward()
    
    for detection in cvOut[0,0,:,:]:
        score = float(detection[2])
        if score > 0.3:
            print(score)
            left = detection[3] * cols
            top = detection[4] * rows
            right = detection[5] * cols
            bottom = detection[6] * rows
            cv.rectangle(img, (int(left), int(top)), (int(right), int(bottom)), (23, 230, 210), thickness=2)
    
    cv.imshow('img', img)
    cv.waitKey()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions