Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

call predict interface error: segmentation fault #1491

Open
baiziyuandyufei opened this issue Oct 12, 2020 · 0 comments
Open

call predict interface error: segmentation fault #1491

baiziyuandyufei opened this issue Oct 12, 2020 · 0 comments

Comments

@baiziyuandyufei
Copy link

Steps to reproduce

  1. edit "test_predict.py" list below
  2. run python test_predict.py demo/configs/docnn.json /tmp/model.caffe2.predictor
  3. terminal input hotel service too bad

Observed Results

neg
zsh: segmentation fault python test_predict.py demo/configs/docnn.json /tmp/model.caffe2.predictor

Expected Results

neg

Relevant Code

test_predict.py

import sys
import pytext

config_file = sys.argv[1]
model_file = sys.argv[2]
config = pytext.load_config(config_file)
predictor = pytext.create_predictor(config, model_file)


if __name__ == "__main__":
    while True:
        text = input()
        
        # Pass the inputs to PyText's prediction API
        result = predictor({"text": text})

        # Results is a list of output blob names and their scores.
        # The blob names are different for joint models vs doc models
        # Since this tutorial is for both, let's check which one we should look at.
        doc_label_scores_prefix = (
            'scores:' if any(r.startswith('scores:') for r in result)
            else 'doc_scores:'
        )

        # For now let's just output the top document label!
        best_doc_label = max(
            (label for label in result if label.startswith(doc_label_scores_prefix)),
            key=lambda label: result[label][0],
        # Strip the doc label prefix here
        )[len(doc_label_scores_prefix):]

        print(best_doc_label)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant