axinc-ai / ailia-models

The collection of pre-trained, state-of-the-art AI models for ailia SDK
2k stars 319 forks source link

ADD dsfd #131

Open kyakuno opened 4 years ago

kyakuno commented 4 years ago

https://github.com/610265158/DSFD-tensorflow/blob/master/README.md

ooe1123 commented 3 years ago

lib/core/api/face_detector.py のFaceDetectorクラスのdef __call__() 内に以下のエクスポートコードを追記して、エクスポートすることができた。

        boxes,labels, scores, num_boxes = self._sess.run(
            self.output_ops, feed_dict={self.input_image: image_fornet,self.training:False}
        )
        print("----->")
        import tf2onnx
        frozen_graph_def = tf.graph_util.convert_variables_to_constants(
            self._sess, self._sess.graph.as_graph_def(), ["tower_0/images", "training_flag", "tower_0/boxes", "tower_0/labels", "tower_0/scores", "tower_0/num_detections"])
        graph1 = tf.Graph()
        with graph1.as_default():
          tf.import_graph_def(frozen_graph_def)
          onnx_graph = tf2onnx.tfonnx.process_tf_graph(graph1,
                input_names=["import/tower_0/images:0", "import/training_flag:0"],
                output_names=["import/tower_0/boxes:0", "import/tower_0/labels:0", "import/tower_0/scores:0", "import/tower_0/num_detections:0"], opset=11
                )
          model_proto = onnx_graph.make_model("DSFD")
          with open("detector.onnx", "wb") as f:
            f.write(model_proto.SerializeToString())
        print("<-----")

しかし、推論時、ailia v1.2.7では以下のエラーが発生する。

ailia.core.AiliaInvalidLayerException: code : -10
+ error detail : Layer:import/tower_0/fems5/concat:0(Concat_DNN) Error:Invalid input shape [(2,6,9,256) v.s. (2,6,8,128) - blob=import/tower_0/fems5/eyes_2/Relu:0].

onnxrunitmeではモデルロード時に以下のエラーが発生する。

onnxruntime.capi.onnxruntime_pybind11_state.NotImplemented: [ONNXRuntimeError] : 9 : NOT_IMPLEMENTED : Could not find an implementation for the node import/tower_0/Ceil_2:Ceil(6)
ooe1123 commented 2 years ago

以下でエクスポートしたonnxが、ailia v1.2.9でロード可能

python -m tf2onnx.convert --graphdef model/detector.pb --output xxx.onnx --fold_const --opset 11 --inputs tower_0/images:0 --outputs tower_0/boxes:0,tower_0/labels:0,tower_0/scores:0,tower_0/num_detections:0