Ask Your Question
0

Unspecified error (Can't create layer "data" of type "Input") in getLayerInstance

asked 2017-12-27 09:05:58 -0600

updated 2017-12-28 03:36:29 -0600

berak gravatar image

I've trained the GoogleNet model on custom datasets and trying to deploy in raspberry pi for image classification. Following code for image predictions:

import cv2
net = cv2.dnn.readNetFromCaffe(
'deploy.prototxt',
'cyrrup_googlenet_iter_1110.caffemodel')
frame = cv2.imread('frame.jpg', cv2.IMREAD_GRAYSCALE)
image=cv2.resize(frame, (224, 224))
blob = cv2.dnn.blobFromImage(image,1, (224, 224), (104, 117, 123))
net.setInput(blob)
detections = net.forward()
print(detections)

The following error I'm getting.

OpenCV Error: Unspecified error (Can't create layer "data" of type "Input") in getLayerInstance, file /home/pi/opencv-3.3.0/modules/dnn/src/dnn.cpp, line 365
Traceback (most recent call last):
File "image_detection.py", line 9, in
detections = net.forward()
cv2.error: /home/pi/opencv-3.3.0/modules/dnn/src/dnn.cpp:365: error: (-2) Can't create layer "data" of type "Input" in function getLayerInstance

Will anyone please help me to debug? If required more information I would like to discuss.

Thanks.

edit retag flag offensive close merge delete

Comments

  • please show the 1st lines of the prototxt (the input layer)
  • opencv-3.3.0 -- nooo, please use latest 3.4 (even if that means a tiresome rebuild)
berak gravatar imageberak ( 2017-12-27 09:48:54 -0600 )edit

Deploy.prototxt

name: "GoogleNet"
layer {
  name: "data"
  type: "Input"
  top: "data"
  input_param { shape: { dim: 10 dim: 3 dim: 224 dim: 224 } }
}
.....
layer {
  name: "prob"
  type: "Softmax"
  bottom: "loss3/classifier"
  top: "prob"
}
prabhundps gravatar imageprabhundps ( 2017-12-27 23:57:12 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-12-28 03:31:32 -0600

berak gravatar image

updated 2017-12-28 03:33:54 -0600

replace your input layer with the following lines:

input: "data"
input_dim: 1
input_dim: 3
input_dim: 224
input_dim: 224

(note, that the actual numbers are taken from blobFromImage() later)

then, in you code, call:

frame = cv2.imread('frame.jpg') ## color, NOT grayscale !
blob = cv2.dnn.blobFromImage(frame, 1, (224, 224), (104, 117, 123), True, False)

(no need to resize the image before !)

and again, you need the latest version for this, not 3.3.0

edit flag offensive delete link more

Comments

@berak Is there no way to use a grayscale image? You suggest to use color images just for dim=3 channels in prototxt? Switching dim=3 to dim=1 could be a solution to make it working on grayscale images?

lezan gravatar imagelezan ( 2018-05-28 06:57:42 -0600 )edit

lezan, if your network was trained with color images, it does not make much sense, to use grayscale ones for testing

berak gravatar imageberak ( 2018-05-28 07:35:50 -0600 )edit

It does not make much sense to be wrong?

lezan gravatar imagelezan ( 2018-05-28 16:16:31 -0600 )edit
2

@lezan, by definition, grayscale images are images with red=green=blue. So you can copy luminance in each channel instead.

dkurt gravatar imagedkurt ( 2018-05-28 22:27:01 -0600 )edit

@dkurt that's a good point. I will try it.

lezan gravatar imagelezan ( 2018-05-29 04:03:24 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2017-12-27 09:05:58 -0600

Seen: 1,010 times

Last updated: Dec 28 '17