Error doing forward pass with OpenCV 3.3

asked 2017-11-01 23:26:03 -0500

Rbt gravatar image

updated 2017-11-01 23:40:57 -0500

berak gravatar image

I have the following code:

 ...
modelTxt = "deploy.prototxt"
modelBin = "deploy.caffemodel"

net = cv2.dnn.readNetFromCaffe(modelTxt, modelBin)

frame = cv2.imread("/home/rbt/BG.jpg")
blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)), 0.007843, (512, 512), [104,117,123])

net.setInput(blob)
detections = net.forward()
....

All work ok until the "detections = net.forward()", here I get the following error:

OpenCV Error: Assertion failed (fracpart == 0.0) in get<long int>, file /io/opencv/modules/dnn/include/opencv2/dnn/dnn.inl.hpp, line 101
Traceback (most recent call last):
  File "pyTest.py", line 16, in <module>
    detections = net.forward()
cv2.error: /io/opencv/modules/dnn/include/opencv2/dnn/dnn.inl.hpp:101: error: (-215) fracpart == 0.0 in function get<long int>

I think errors come from muy trained caffe model because with other model I have not errors. Here my "deploy.prototxt":

name: "deploy"
input: "data"
input_shape {
  dim: 1
  dim: 3
  dim: 512
  dim: 512
}
layer {
  name: "conv1_1"
  type: "Convolution"
  bottom: "data"
  top: "conv1_1"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 64
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu1_1"
  type: "ReLU"
  bottom: "conv1_1"
  top: "conv1_1"
}
layer {
  name: "conv1_2"
  type: "Convolution"
  bottom: "conv1_1"
  top: "conv1_2"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 64
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu1_2"
  type: "ReLU"
  bottom: "conv1_2"
  top: "conv1_2"
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1_2"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  name: "conv2_1"
  type: "Convolution"
  bottom: "pool1"
  top: "conv2_1"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 128
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu2_1"
  type: "ReLU"
  bottom: "conv2_1"
  top: "conv2_1"
}
layer {
  name: "conv2_2"
  type: "Convolution"
  bottom: "conv2_1"
  top: "conv2_2"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 128
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu2_2"
  type: "ReLU"
  bottom: "conv2_2"
  top: "conv2_2"
}
layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2_2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  name: "conv3_1"
  type: "Convolution"
  bottom: "pool2"
  top: "conv3_1"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu3_1"
  type: "ReLU"
  bottom: "conv3_1"
  top: "conv3_1"
}
layer {
  name: "conv3_2"
  type: "Convolution"
  bottom: "conv3_1"
  top: "conv3_2"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu3_2"
  type: "ReLU"
  bottom: "conv3_2"
  top: "conv3_2"
}
layer {
  name: "conv3_3"
  type: "Convolution"
  bottom: "conv3_2"
  top: "conv3_3"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu3_3"
  type: "ReLU"
  bottom: "conv3_3"
  top: "conv3_3"
}
layer {
  name: "pool3"
  type: "Pooling"
  bottom: "conv3_3"
  top: "pool3"
  pooling_param {
    pool: MAX
    kernel_size ...
(more)
edit retag flag offensive close merge delete

Comments

dkurt gravatar imagedkurt ( 2017-11-01 23:51:56 -0500 )edit

Why do you think that is the same problem?? I have real values (e.i: min_size: 20.48) Should I truncate them to integer values?

Rbt gravatar imageRbt ( 2017-11-02 01:01:37 -0500 )edit
1

You were right, I truncated all the values ​​to integers and worked. Thank you!!

Rbt gravatar imageRbt ( 2017-11-02 01:40:40 -0500 )edit
1

@Rbt, an other one solution is to use the latest state of OpenCV master branch.

dkurt gravatar imagedkurt ( 2017-11-02 02:04:10 -0500 )edit

@dkurt, yes, this is the best solution!!!!

Rbt gravatar imageRbt ( 2017-11-02 15:35:45 -0500 )edit