Problem loading MobilenetV1 (from Keras) with OpenCV::DNN

asked 2018-05-09 10:55:50 -0600

Rbt gravatar image

I have a trained mobilenetv1 network and I get the following error when I try to read the model with cv2.dnn.readNetFromTensorflow():

OpenCV(3.4.1) /feedstock_root/build_artefacts/opencv_1520722599420/work/opencv-3.4.1/modules/dnn/src/tensorflow/tf_importer.cpp:1582: error: (-2) Unknown layer type Minimum in op mobilenet_0_25_48/conv1_relu/Minimum in function populateNet

I followed all the steps for converting the Keras model to Tensorflow model (https://github.com/opencv/opencv/pull...).

Here one of the problematic part (*.pbtxt):

node {
  name: "input_1"
  op: "Placeholder"
  attr {
    key: "dtype"
    value {
      type: DT_FLOAT
    }
  }
  attr {
    key: "shape"
    value {
      shape {
        dim {
          size: -1
        }
        dim {
          size: 48
        }
        dim {
          size: 48
        }
        dim {
          size: 1
        }
      }
    }
  }
}
node {
  name: "mobilenet_0_25_48/conv1_pad/Pad"
  op: "Pad"
  input: "input_1:0"
  input: "mobilenet_0_25_48/conv1_pad/Pad/paddings"
}
node {
  name: "mobilenet_0_25_48/conv1/convolution"
  op: "Conv2D"
  input: "mobilenet_0_25_48/conv1_pad/Pad"
  input: "conv1/kernel/read/_0__cf__0"
  attr {
    key: "dilations"
    value {
      list {
        i: 1
        i: 1
        i: 1
        i: 1
      }
    }
  }
  attr {
    key: "padding"
    value {
      s: "VALID"
    }
  }
  attr {
    key: "strides"
    value {
      list {
        i: 1
        i: 2
        i: 2
        i: 1
      }
    }
  }
}
node {
  name: "mobilenet_0_25_48/conv1_bn/batchnorm/mul_1"
  op: "Mul"
  input: "mobilenet_0_25_48/conv1/convolution"
  input: "mobilenet_0_25_48/conv1_bn/batchnorm/mul/_27__cf__27"
}
node {
  name: "mobilenet_0_25_48/conv1_bn/batchnorm/add_1"
  op: "Add"
  input: "mobilenet_0_25_48/conv1_bn/batchnorm/mul_1"
  input: "mobilenet_0_25_48/conv1_bn/batchnorm/sub/_28__cf__28"
}
node {
  name: "mobilenet_0_25_48/conv1_relu/Relu"
  op: "Relu"
  input: "mobilenet_0_25_48/conv1_bn/batchnorm/add_1"
}
node {
  name: "mobilenet_0_25_48/conv1_relu/Minimum"
  op: "Minimum"
  input: "mobilenet_0_25_48/conv1_relu/Relu"
  input: "mobilenet_0_25_48/conv1_relu/Const"
}
node {
  name: "mobilenet_0_25_48/conv_pad_1/Pad"
  op: "Pad"
  input: "mobilenet_0_25_48/conv1_relu/Minimum"
  input: "mobilenet_0_25_48/conv_pad_1/Pad/paddings"
}
node {
  name: "mobilenet_0_25_48/conv_dw_1/depthwise"
  op: "DepthwiseConv2dNative"
  input: "mobilenet_0_25_48/conv_pad_1/Pad"
  input: "conv_dw_1/depthwise_kernel/read/_1__cf__1"
  attr {
    key: "dilations"
    value {
      list {
        i: 1
        i: 1
        i: 1
        i: 1
      }
    }
  }
  attr {
    key: "padding"
    value {
      s: "VALID"
    }
  }
  attr {
    key: "strides"
    value {
      list {
        i: 1
        i: 1
        i: 1
        i: 1
      }
    }
  }
}
edit retag flag offensive close merge delete

Comments

@Rbt may I ask you to check your model again with the latest state of OpenCV, without a text file? It seems to me that we've already solved this issue.

dkurt gravatar imagedkurt ( 2018-05-09 11:33:51 -0600 )edit

Ok, I will check but I am using the last version of OpenCV 3.4.1

Rbt gravatar imageRbt ( 2018-05-09 11:37:03 -0600 )edit

@Rbt, you need at least changes from https://github.com/opencv/opencv/pull... which have been merged two months ago.

dkurt gravatar imagedkurt ( 2018-05-09 13:06:22 -0600 )edit

Now I get the following error: what(): OpenCV(4.0.0-pre) /home/programs/opencv_last_state/modules/dnn/src/tensorflow/tf_importer.cpp:474: error: (-2:Unspecified error) Const kernel input not found in function 'getConstBlob'

Rbt gravatar imageRbt ( 2018-05-09 16:02:19 -0600 )edit

@Rbt, please provide a code and some reference to model if it's possible.

dkurt gravatar imagedkurt ( 2018-05-09 22:51:18 -0600 )edit

That will not be necessary, I performed the whole process from the beginning and it works, maybe I was missing something. Thank you very much

Rbt gravatar imageRbt ( 2018-05-10 19:40:15 -0600 )edit