https://github.com/bubnov-mikhail/tenserflow-bundle
Integrates tenserflow recognizer into your Symfony2 application
https://github.com/bubnov-mikhail/tenserflow-bundle
image-recognition symfony-bundle symfony-service
Last synced: 3 months ago
JSON representation
Integrates tenserflow recognizer into your Symfony2 application
- Host: GitHub
- URL: https://github.com/bubnov-mikhail/tenserflow-bundle
- Owner: bubnov-mikhail
- Created: 2016-08-08T12:46:23.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-23T08:21:17.000Z (over 8 years ago)
- Last Synced: 2025-01-13T05:29:24.260Z (5 months ago)
- Topics: image-recognition, symfony-bundle, symfony-service
- Language: PHP
- Size: 85 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
BubnovTensorFlowBundle
=================This bundle provides service and command to recognize image.
Both will return RecognizeResult object.### Requirements
- PHP 5.4 or higher
- symfony > 2.3### Installation
To install bubnov/tenserflow-bundle with Composer just add the following to your 'composer.json' file:
{
...
"scripts": {
"post-install-cmd": [ "TensorFlowBinaryInstaller::install" ],
"post-update-cmd": [ "TensorFlowBinaryInstaller::update" ]
},
...
}The next thing you should do is to install the bundle by executing the following command:
```sh
composer require bubnov/tenserflow-bundle: ~3.0
```Finally, add the bundle to the registerBundles function of the AppKernel class in the 'app/AppKernel.php' file:
public function registerBundles()
{
$bundles = array(
...
new Bubnov\TensorFlowBundle\BubnovTensorFlowBundle(),
...
);### Usage
When you want to use service from the controller you can simply call:
/* @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 falseWhere is also the command for testing images "bubnov_tensorflow:recognize". Usage:
bubnov_tensorflow:recognize /absolute/path/to/image.ext
Command will return multiline string with labels and scores
To create dictionary with common labels to the same images in some directory, you can call:
find /path/to/dir/with/images -type f | parallel ./bin/console bubnov_tensorflow:fill_dict {} --tmpdict /path/to/dict.tmp
This command using GNU parallel. Optional --tmpdict may be omitted - temporary dict file will be saved to /tmp/tensorFlowBundle.dict.tmp
After complete, call:bin/console bubnov_tensorflow:combine_dict --tmpdict /path/to/dict.tmp --dict /path/to/complete.dict
This command will create dictionary with labels and the number of their repetitions in the dict.tmp file.
Now you may choose, which labels to include in Dictionary.
Optional --dict may be omitted - dict file will be saved to /tmp/tensorFlowBundle.dict
Optional --tmpdict may be omitted - temporary dict file will be read from /tmp/tensorFlowBundle.dict.tmp### Configuration
This bundle will work with standalone configuration, but you may redefine some paths. It is optional and not necessary
```yml
bubnov_tensor_flow:
recognizer:
binary: 'some/path/to/label_image binary'
graph: 'some/path/to/graph.pb'
labels: 'some/path/to/labels.txt'```
### Credits
This bundle is a wrapper around tenderflow`s label_image binary with tiny updates:
https://github.com/tensorflow/tensorflow by The TensorFlow AuthorsBundle code is written by Mikhail Bubnov
[email protected]
https://github.com/bubnov-mikhail### License
This bundle is under the MIT license.