(self, model_config_paths_args)
| 469 | fout.write(str(pb_obj)) |
| 470 | |
| 471 | def load_model_config(self, model_config_paths_args): |
| 472 | # At present, Serving needs to configure the model path in |
| 473 | # the resource.prototxt file to determine the input and output |
| 474 | # format of the workflow. To ensure that the input and output |
| 475 | # of multiple models are the same. |
| 476 | if isinstance(model_config_paths_args, str): |
| 477 | model_config_paths_args = [model_config_paths_args] |
| 478 | |
| 479 | for single_model_config in model_config_paths_args: |
| 480 | if os.path.isdir(single_model_config): |
| 481 | pass |
| 482 | elif os.path.isfile(single_model_config): |
| 483 | raise ValueError( |
| 484 | "The input of --model should be a dir not file.") |
| 485 | |
| 486 | if isinstance(model_config_paths_args, list): |
| 487 | # If there is only one model path, use the default infer_op. |
| 488 | # Because there are several infer_op type, we need to find |
| 489 | # it from workflow_conf. |
| 490 | |
| 491 | # now only support single-workflow. |
| 492 | # TODO:support multi-workflow |
| 493 | model_config_paths_list_idx = 0 |
| 494 | for node in self.workflow_conf.workflows[0].nodes: |
| 495 | if node.type in self.default_engine_types: |
| 496 | if node.name is None: |
| 497 | raise Exception( |
| 498 | "You have set the engine_name of Op. Please use the form {op: model_path} to configure model path" |
| 499 | ) |
| 500 | |
| 501 | f = open("{}/serving_server_conf.prototxt".format( |
| 502 | model_config_paths_args[model_config_paths_list_idx]), |
| 503 | 'r') |
| 504 | self.model_conf[ |
| 505 | node.name] = google.protobuf.text_format.Merge( |
| 506 | str(f.read()), m_config.GeneralModelConfig()) |
| 507 | self.model_config_paths[ |
| 508 | node.name] = model_config_paths_args[ |
| 509 | model_config_paths_list_idx] |
| 510 | self.general_model_config_fn.append( |
| 511 | node.name + "/general_model.prototxt") |
| 512 | self.model_toolkit_fn.append(node.name + |
| 513 | "/model_toolkit.prototxt") |
| 514 | self.subdirectory.append(node.name) |
| 515 | model_config_paths_list_idx += 1 |
| 516 | if model_config_paths_list_idx == len( |
| 517 | model_config_paths_args): |
| 518 | break |
| 519 | #Right now, this is not useful. |
| 520 | elif isinstance(model_config_paths_args, dict): |
| 521 | self.model_config_paths = collections.OrderedDict() |
| 522 | for node_str, path in model_config_paths_args.items(): |
| 523 | node = server_sdk.DAGNode() |
| 524 | google.protobuf.text_format.Parse(node_str, node) |
| 525 | self.model_config_paths[node.name] = path |
| 526 | print("You have specified multiple model paths, please ensure " |
| 527 | "that the input and output of multiple models are the same.") |
| 528 | f = open("{}/serving_server_conf.prototxt".format(path), 'r') |
no test coverage detected