【发布时间】:2020-01-19 22:03:01
【问题描述】:
我正在开展一个在 GCP 上创建流处理预测引擎的项目。我主要从这个 repo here 中学习。但是,当我尝试执行脚本 blogposts/got_sentiment/4_streaming_pipeline/streaming_tweet.py 时,我不断收到错误
NameError: name 'estimate' is not defined [while running 'generatedPtransform-129']
我的函数如下所示
from __future__ import absolute_import
import argparse
import datetime
import json
import logging
import numpy as np
import apache_beam as beam
import apache_beam.transforms.window as window
from apache_beam.io.gcp.bigquery import parse_table_schema_from_json
from apache_beam.options.pipeline_options import StandardOptions, GoogleCloudOptions, SetupOptions, PipelineOptions
from apache_beam.transforms.util import BatchElements
from googleapiclient import discovery
def init():
........
def estimate_cmle():
init()
.....
def estimate(instances):
estimate_cmle()
......
def run(argv=None):
....
output = (lines
| 'assign window key' >> beam.WindowInto(window.FixedWindows(10))
| 'batch into n batches' >> BatchElements(min_batch_size=49, max_batch_size=50)
| 'predict sentiment' >> beam.FlatMap(lambda messages: estimate(messages))
)
.....
f __name__ == '__main__':
logging.getLogger().setLevel(logging.INFO)
run()
这是梁似乎无法识别估计函数的地方,尽管我在同一个脚本中创建它。
编辑
尝试使用beam.FlatMap(estimate) 出现错误
name 'estimate_cmle' is not defined [while running 'generatedPtransform-1208']
【问题讨论】:
-
您是否尝试过使用 beam.FlatMap(estimate) 而不是 beam.FlatMap(lambda messages: estimate(messages))?
-
我试过了。现在它给了我estimate_cmle not found :(
-
您在哪里以及如何使用estimate_cmle?
-
在估计函数中,estimate_cmle 被用于调用 CMLE 上的模型 API 以获取预测
-
您使用的是哪个 python 版本?我在 github 上看到了代码,它应该可以工作
标签: google-cloud-platform google-cloud-dataflow apache-beam