1

I converted a Tensorflow model to a Caffe model (tf_resnet.prototxt), and I'm now trying to run an object detection counting algorithm (code). However, i get the following error:

[INFO] loading model...
[INFO] opening video file...
Traceback (most recent call last):
  File "people_counter.py", line 132, in <module>
    detections = net.forward()
cv2.error: OpenCV(4.2.0) /io/opencv/modules/dnn/src/dnn.cpp:562: error: (-2:Unspecified error) Can't create layer "DummyData1" of type "DummyData" in function 'getLayerInstance'

This similar issue here on Stackoverflow suggested to change the type: "DummyData1" to type: "Input" in the following code:

layer {
  name: "DummyData1"
  type: "DummyData1"
  top: "DummyData1"
  dummy_data_param {
    shape {
      dim: 1
      dim: 64
      dim: 150
      dim: 150
    }
  }
}

However, when doing this, i get another error:

Traceback (most recent call last):
  File "people_counter.py", line 132, in <module>
    detections = net.forward()
cv2.error: OpenCV(4.2.0) /io/opencv/modules/dnn/src/dnn.cpp:2709: error: (-215:Assertion failed) inp.total() in function 'allocateLayers''

Any suggestions on how to fix this issue?

fendrbud
  • 89
  • 1
  • 11

1 Answers1

0

You can try this approach; change this:

layer {
  name: "DummyData1"
  type: "DummyData1"
  top: "DummyData1"
  dummy_data_param {
    shape {
      dim: 1
      dim: 64
      dim: 150
      dim: 150
    }
  }
}

With this:

layer {
  name: "DummyData1"
  type: "Input"
  top: "DummyData1"
  input_param {
    shape {
      dim: 1
      dim: 64
      dim: 150
      dim: 150
    }
  }
}

Then in the script, instead of using these lines:

blob = cv2.dnn.blobFromImage(frame, 0.007843, (W, H), 127.5)
net.setInput(blob)
detections = net.forward()

Try these:

blob = cv2.dnn.blobFromImage(frame, 0.007843, (W, H), 127.5)
net.setInput(blob, "Placeholder")
net.setInput(np.zeros((1, 64, 150, 150)), "DummyData1")
detections = net.forward()

I don't know if the results will be good, but this should at least resolve the exception.

In order to have good results, you have to find off what kind of data goes in that layer, because in the original model "DummyData1" is probably some kind of generator or maybe a constant matrix.

Doch88
  • 728
  • 1
  • 8
  • 22