Skip to content

Commit 1e81b85

Browse files
committed
Add install instructions
1 parent 250c9a8 commit 1e81b85

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

Readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ If you have a usecase that's not listed above, please create an [issue](https://
1818
- **Super simple API** - No machine learning knowledge required
1919
- **Maximum performance** - Preloads the machine learning core, so predictions are super fast
2020

21+
### Installation
22+
Install the package via composer:
23+
24+
composer require funcai/funcai-php
25+
26+
Until we've figured out a solution for how to host the final models, the following step is a bit more difficult than we'd like it to be.
27+
28+
You'll need to have python installed (locally), and some sort of way to host the model files yourself.
29+
30+
To generate the model, run:
31+
32+
pip3 install tensorflow
33+
python3 scripts/generate/efficientnet.py
34+
35+
The model will be placed in /models/efficientnet. You will need to have access to this folder from your webserver. For example, if you've uploaded the folder to /var/www/models/efficientnet, you should set the path like this:
36+
37+
\FuncAI\Config::setModelBasePath('/var/www/models');
38+
39+
2140
### Requirements
2241
- Either the provided dockerfile
2342
- Or PHP >= 7.4 on Linux

example.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
require __DIR__.'/vendor/autoload.php';
66

7+
\FuncAI\Config::setModelBasePath(realpath(dirname(__FILE__) . '/models/'));
8+
79
$model = new EfficientNet();
810
$output = $model->predict(__DIR__ . '/sample_data/butterfly.jpg');
911

src/Config.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
namespace FuncAI;
3+
4+
class Config {
5+
private static string $modelBasePath;
6+
7+
/**
8+
* @return string
9+
*/
10+
public static function getModelBasePath(): string
11+
{
12+
if(!isset(self::$modelBasePath)) {
13+
self::$modelBasePath = realpath(dirname(__FILE__) . '/../models/');
14+
}
15+
return self::$modelBasePath;
16+
}
17+
18+
/**
19+
* @param string $modelBasePath
20+
*/
21+
public static function setModelBasePath(string $modelBasePath): void
22+
{
23+
self::$modelBasePath = $modelBasePath;
24+
}
25+
26+
}

src/Models/EfficientNet.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22
namespace FuncAI\Models;
33

4+
use FuncAI\Config;
45
use FuncAI\Tensorflow\TensorFlow;
56

67
class EfficientNet extends AbstractModel
78
{
89
public function getModelPath()
910
{
10-
return __DIR__ . '/../../models/efficientnet';
11+
return Config::getModelBasePath() . '/efficientnet';
1112
}
1213

1314
public function getOutputTensor()

0 commit comments

Comments
 (0)