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

call predict interface error: segmentation fault #1491

@baiziyuandyufei

Description

@baiziyuandyufei

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions