0

我有一些用 python 编写的图像分类器。网上有很多例子描述了在标准输入/标准输出中使用的风暴螺栓中使用 python 的方式。我想将我的 python 图像分类器与风暴爬虫拓扑集成。有没有可能?

谢谢

4

2 回答 2

1

绝对有可能,几年前将图像分类器与 Tensorflow 集成到 StormCrawler 拓扑中。不记得细节了,代码留在了我为其编写的客户那里,但它是基于多语言协议的,遗憾的是不记得细节。

于 2020-01-06T09:34:31.733 回答
1

是的你可以。如果您使用的是 Flux,这是一个关于如何在拓扑中使用 python bolt 的示例定义:

  - id: "pythonbolt"
    className: "org.apache.storm.flux.wrappers.bolts.FluxShellBolt"
    constructorArgs:
      - ["python", "/absolute/path/to/your/python_file.py"]
      # declare your outputs here:
      - ["output0", "output1", "output2"]
    parallelism: 1

注意:确保向 python bolt 发出简单的数据类型(如字符串、整数等)。不是 java 数据类型,否则会抛出错误!首先下载storm.py表格

这里

这是一个示例 python 螺栓:

import storm

class SampleBolt(storm.BasicBolt):
    # Initialize this instance
    def initialize(self, conf, context):
        self._conf = conf
        self._context = context

    def process(self, tup):
        # Some processes here, and then emit your outputs.
        storm.emit([output0, output1, output2])

# Start the bolt when it's invoked
SampleBolt().run()
于 2020-02-22T14:41:47.170 回答