def _create_rpc_call(self, sess, model_file, **kwargs): model_base_dir = os.path.split(model_file)[0] pid = model_file.split("-")[-1] lengths = peek_lengths_key(model_file, self.feature_exporter_field_map) pc = PreProcessorController(model_base_dir, pid, self.task.config_params['features'], self.feature_exporter_field_map, lengths) tf_example, preprocessed = pc.run() # Create a dict of embedding names to sub-graph outputs to wire in as embedding inputs embedding_inputs = {} for feature in preprocessed: embedding_inputs[feature] = preprocessed[feature] model, classes, values = self._create_model(sess, model_file, **embedding_inputs) sig_input = {x: tf.saved_model.utils.build_tensor_info(tf_example[x]) for x in pc.FIELD_NAMES} if model.lengths is not None: sig_input.update({model.lengths_key: tf.saved_model.utils.build_tensor_info(model.lengths)}) sig_output = SignatureOutput(classes, values) sig_name = 'predict_text' assets = create_assets( model_file, sig_input, sig_output, sig_name, model.lengths_key, return_labels=self.return_labels, preproc=self.preproc_type(), ) return sig_input, sig_output, sig_name, assets
def _create_rpc_call(self, sess, model_file, **kwargs): model_base_dir = os.path.split(model_file)[0] pid = model_file.split("-")[-1] lengths = peek_lengths_key(model_file, self.feature_exporter_field_map) pc = PreProcessorController(model_base_dir, pid, self.task.config_params['features'], self.feature_exporter_field_map, lengths) tf_example, preprocessed = pc.run() # Create a dict of embedding names to sub-graph outputs to wire in as embedding inputs embedding_inputs = {} for feature in preprocessed: embedding_inputs[feature] = preprocessed[feature] model, embedded = self._create_model(sess, model_file, **embedding_inputs) sig_input = { x: tf.saved_model.utils.build_tensor_info(tf_example[x]) for x in pc.FIELD_NAMES } classes = tf.ones([1, 1], dtype=tf.uint8) sig_output = SignatureOutput(classes, embedded) sig_name = 'embed_text' assets = create_assets(model_file, sig_input, sig_output, sig_name, None, return_labels=False) return sig_input, sig_output, sig_name, assets
def _create_rpc_call(self, sess, basename, **kwargs): model, embedded = self._create_model(sess, basename) predict_tensors = {} for k, v in model.embeddings.items(): try: predict_tensors[k] = tf.saved_model.utils.build_tensor_info(v.x) except: raise Exception('Unknown attribute in signature: {}'.format(v)) sig_input = predict_tensors classes = tf.ones([1, 1], dtype=tf.uint8) sig_output = SignatureOutput(classes, embedded) sig_name = 'embed_text' assets = create_assets(basename, sig_input, sig_output, sig_name, None, return_labels=False) return sig_input, sig_output, sig_name, assets
def _create_rpc_call(self, sess, model_file, **kwargs): model_base_dir = os.path.split(model_file)[0] pid = model_file.split("-")[-1] pc = PreProcessorController(model_base_dir, pid, self.task.config_params['features'], self.feature_exporter_field_map) tf_example, preprocessed = pc.run() # Create a dict of embedding names to sub-graph outputs to wire in as embedding inputs embedding_inputs = {} for feature in preprocessed: embedding_inputs[feature] = preprocessed[feature] model, classes, values = self._create_model(sess, model_file, **embedding_inputs) sig_input = {x: tf.saved_model.utils.build_tensor_info(tf_example[x]) for x in pc.FIELD_NAMES} sig_input.update({model.lengths_key: tf.saved_model.utils.build_tensor_info(model.lengths)}) sig_output = SignatureOutput(classes, values) sig_name = 'tag_text' assets = create_assets(model_file, sig_input, sig_output, sig_name, model.lengths_key, return_labels=self.return_labels) return sig_input, sig_output, sig_name, assets
def _create_rpc_call(self, sess, model_file): model_base_dir = os.path.split(model_file)[0] pid = model_file.split("-")[-1] pc = PreProcessorController(model_base_dir, pid, self.task.config_params['features']) model_params = self.task.config_params['model'] tf_example, preprocessed = pc.run() for feature in preprocessed: model_params[feature] = preprocessed[feature] model, classes, values = self._create_model(sess, model_file) sig_input = { 'tokens': tf.saved_model.utils.build_tensor_info(tf_example[pc.FIELD_NAME]), model.lengths_key: tf.saved_model.utils.build_tensor_info(model.lengths) } sig_output = SignatureOutput(classes, values) sig_name = 'tag_text' assets = create_assets(model_file, sig_input, sig_output, sig_name, model.lengths_key) return sig_input, sig_output, sig_name, assets