pipeline() 是使用预训练模型进行推理的最简便、高效的方式,适用于多种任务跨模型的应用场景。利用 pipeline(),可轻松调用不同模型。代码示例如下所示:
def test_pipeline(): # 情感分析 classifier = pipeline(task="sentiment-analysis") # 给出三个文本内容 results = classifier( ["It's a great ride around the island", "The weather is bad", "He sent an email"]) # 打印出结果 for i in results: print(f"label: {i['label']}, with score: {round(i['score'], 4)}")目标检测