bubnov/tenserflow-bundle

将 tenserflow 识别器集成到您的 Symfony2/Symfony3 应用程序中

安装: 44

依赖: 0

建议者: 0

安全: 0

星标: 2

关注者: 2

分支: 0

公开问题: 0

类型:symfony-bundle

3.0.6 2017-01-23 08:21 UTC

README

此包提供服务和命令以识别图像。两者都将返回 RecognizeResult 对象。

需求

  • PHP 5.4 或更高版本
  • symfony > 2.3

安装

要使用 Composer 安装 bubnov/tenserflow-bundle,只需将以下内容添加到您的 'composer.json' 文件中:

{
    ...
    "scripts": {
        "post-install-cmd": [ "TensorFlowBinaryInstaller::install" ],
        "post-update-cmd":  [ "TensorFlowBinaryInstaller::update" ]
    },
    ...
}

接下来,您应该执行以下命令来安装此包:

```sh
composer require bubnov/tenserflow-bundle: ~3.0
```

最后,将包添加到 'app/AppKernel.php' 文件中的 AppKernel 类的 registerBundles 函数中

public function registerBundles()
{
    $bundles = array(
        ...
        new Bubnov\TensorFlowBundle\BubnovTensorFlowBundle(),
        ...
    );

用法

当您想从控制器中调用服务时,可以简单地调用

/* @var $result \Bubnov\TensorFlowBundle\Util\RecognizerResult */
$result = $this->get('tenserflow.recognizer')->recognize('some/path/to/image'); //Returns RecognizerResult object

/* @var $label \Bubnov\TensorFlowBundle\Util\Label */
$label = $result->getTopLabel();           // Returns Label with highest score
$label->getName();                         // Returns label`s name
$label->getScore();                        // Returns label`s score

$labels = $result->getLabels();            // Returns array of Label in order of score.
$labels = $result->getLabelsScored(0.8);   // Returns array of Label in order of score with score more or equal 0.8

/**
 * Find if there are any labels in the Dictionary
 */
$dict = new \Bubnov\TensorFlowBundle\Util\Dictionary(['apple', 'fruit']);
$dict->add('blueberry');                         // Add string to the dictionary

$scoreThreshold = 0.7;                           // Optional threshold
$dict->match($result, $scoreThreshold);          // Return true or false

这里也有用于测试图像的命令 "bubnov_tensorflow:recognize"。用法

bubnov_tensorflow:recognize /absolute/path/to/image.ext

命令将返回包含标签和分数的多行字符串

要创建包含某些目录中相同图像的常见标签的字典,可以调用

find /path/to/dir/with/images -type f | parallel ./bin/console bubnov_tensorflow:fill_dict {} --tmpdict /path/to/dict.tmp

此命令使用 GNU parallel。可选的 --tmpdict 可以省略 - 临时字典文件将保存到 /tmp/tensorFlowBundle.dict.tmp。完成后,调用

bin/console bubnov_tensorflow:combine_dict --tmpdict /path/to/dict.tmp --dict /path/to/complete.dict

此命令将创建包含标签及其在 dict.tmp 文件中重复次数的字典。现在您可以选择要包含在字典中的标签。可选的 --dict 可以省略 - 字典文件将保存到 /tmp/tensorFlowBundle.dict。可选的 --tmpdict 可以省略 - 从 /tmp/tensorFlowBundle.dict.tmp 读取临时字典文件

配置

此包可以使用独立配置运行,但您可能需要重新定义一些路径。这是可选的,不是必需的

bubnov_tensor_flow:
    recognizer:
        binary: 'some/path/to/label_image binary'
        graph: 'some/path/to/graph.pb'
        labels: 'some/path/to/labels.txt'

鸣谢

此包是围绕 tenderflow 的 label_image 二进制文件的一个包装,附带少量更新:由 TensorFlow 作者提供的 https://github.com/tensorflow/tensorflow

包代码由 Mikhail Bubnov 编写 bubnov.mihail@gmail.com https://github.com/bubnov-mikhail

许可证

此包受 MIT 许可证的约束。