示例#1
0
 def auditConfig(self):
     for name in self._mandatory_member_name:
         if name not in self._mandatory_member:
             LOG.logE(
                 "Error! self.{} must be definded in your subclass.".format(
                     name),
                 exit=True)
示例#2
0
    def exportNCNN(self, img):
        if not self.conf.ncnn_param_output_path or not self.conf.ncnn_bin_output_path:
            return
        if not self.conf.onnx2ncnn:
            LOG.logE(
                "You must set the onnx2ncnn executable program path in config file. If you want to compile onnx2ncnn tools, reference https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-linux-x86 ",
                exit=True)

        import onnx
        import subprocess
        import tempfile
        from onnxsim import simplify

        if not self.conf.onnx_output_model_path:
            f = tempfile.NamedTemporaryFile()
            self.conf.onnx_output_model_path = f.name
        self.exportONNX(img)

        cmd = self.conf.onnx2ncnn + " " + self.conf.onnx_output_model_path + " " + self.conf.ncnn_param_output_path + " " + self.conf.ncnn_bin_output_path
        pd = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
        if pd.stderr.read() != b"":
            LOG.logE(
                pd.stderr.read() +
                b". Error occured when export ncnn model. We try to simplify the model first"
            )
            model_op, check_ok = simplify(self.conf.onnx_output_model_path,
                                          check_n=3,
                                          perform_optimization=True,
                                          skip_fuse_bn=True,
                                          skip_shape_inference=False)
            onnx.save(model_op, self.conf.onnx_output_model_path)
            if not check_ok:
                LOG.logE(
                    "Maybe something wrong when simplify the model, we can't guarantee generate model is right"
                )
            else:
                LOG.logI("Simplify model succeed")
            subprocess.Popen(cmd,
                             shell=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
            if pd.stderr.read() != b"":
                LOG.logE(pd.stderr.read() +
                         b". we can't guarantee generate model is right")

        LOG.logI(
            "Pytorch model convert to NCNN model succeed, save ncnn param file in {}, save ncnn bin file in {}"
            .format(self.conf.ncnn_param_output_path,
                    self.conf.ncnn_bin_output_path))
示例#3
0
    def assertInGit(self):
        if os.environ.get("disable_git"):
            self.branch = "sevice"
            return

        if self.conf.disable_git:
            self.branch = "disable_git"
            return

        self.branch = getCurrentGitBranch()
        if self.branch is None:
            LOG.logE(
                'According to deepvac standard, you must working in a git repo.',
                exit=True)

        if len(self.branch) < 6:
            LOG.logE(
                'According to deepvac standard, your git branch name is too short: {}'
                .format(self.branch),
                exit=True)

        if self.branch.startswith('LTS_'):
            return

        if self.branch.startswith('PROTO_'):
            return

        LOG.logE(
            'According to deepvac standard, git branch name should start from LTS_ or PROTO_: {}'
            .format(self.branch),
            exit=True)
示例#4
0
文件: test.py 项目: MHGL/SYSZUXnsfw
 def process(self):
     label_list = config.label_list
     for image_path in self.dataset():
         self.getTask(image_path)
         self.request.set_content(
             HttpContentHelper.toValue({
                 "tasks": [self.task],
                 "scenes": [config.scenes]
             }))
         response = self.clt.do_action_with_exception(self.request)
         result = json.loads(response)
         if result['code'] != 200:
             LOG.logE(
                 f"got request error! please checkout your AccessKeyId and Secret"
             )
             continue
         if result['data'][0]['code'] != 200:
             LOG.logE(
                 f"got error! [file: {image_path}, msg: {result['data'][0]['msg']}]"
             )
             continue
         pred = result['data'][0]['results'][0]['label']
         label = image_path.split('/')[-2]
         if label not in label_list:
             LOG.logE(f"got error! test file structure not standard")
             continue
         LOG.logI(
             f"got Success! [file: {image_path}, label: {label}, pred: {pred}]"
         )
         self.report.add(label_list.index(label), label_list.index(pred))
示例#5
0
 def initValLoader(self):
     self.val_loader = None
     LOG.logE(
         "You must reimplement initTrainLoader() to initialize self.val_loader",
         exit=True)
示例#6
0
 def process(self):
     LOG.logE(
         "You must reimplement process() to process self.input_output['input']",
         exit=True)
示例#7
0
 def initNetWithCode(self):
     self.net = None
     LOG.logE(
         "You must reimplement initNetWithCode() to initialize self.net",
         exit=True)