Image classifier API
Method: POST
Input: Base 64 stream (JPG image data)
Output: JSON array (Top 5 matching Hollander data)
Language: PHP
Input data
{
“image64”: base64 stream
}
Output data
{
“title”: “matching”,
“description”: “Please check the results.”,
“uploadedUrl”: uploaded JPG file URL,
“ref”: [
{
“id”: Hollander ID,
“img_url”: Hollander image file URL,
“prob”: Similarity
},
{
“id”: Hollander ID,
“img_url”: Hollander image file URL,
“prob”: Similarity
},
…
]
}
Source File:
PHP
<?php
//setting headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
//recevieing json
$content = trim(file_get_contents("php://input"));
$post = json_decode($content);
//saving uploaded image
$imagedata = base64_decode($post->image64);
$file_path = 'upload/' . date("Y_m_d_H_i_s_") . '[login to view URL]';
$file = fopen($file_path, "wb");
fwrite($file, $imagedata);
fclose($file);
//Matching (Here Deep Learning)
$result_json = exec("[login to view URL] ".$file_path);
$result_arr = json_decode($result_json);
//making json
$MyResult = array();
$MyResult['title'] = "Matching";
$MyResult['description'] = "Please check the results.";
$MyResult['uploadedUrl'] = $file_path;
$MyResult['ref'] = array();
foreach ($result_arr as $key => $value) {
$img_file_arr = scandir('base/' . $key . '/');
$buff = array('id' => $key, 'img_url' => 'base/' . $key . '/' . $img_file_arr[2], 'prob' => $value);
array_push($MyResult['ref'], $buff);
}
//Sending Results
http_response_code(200);
$JSONResult = json_encode($MyResult);
echo $JSONResult;
?>
Python
Tree Structure
Base folder structure
I am using base folder for Hollander images.
But you needn’t use this folder.
I can use your origin database.
And you can find all the reference wheel information which has the same hollander ids.
So I hope you to expand my raw api to send all the reference wheel spieces, not only hollander ids.
In the 7z file, the [login to view URL] is the kernel of image classifying.
If you train more, the [login to view URL] will be updated. Then you should replace it to newer version.
There is no training part in 7z python files.
Are you using Tensorflow? what's version? I believe the model isn't trained? How many images did you use to training?
Using PHP to call a Python file decreases the performance
Making a JSON output using PHP without OOP it will not scalable.
Well, if you need only improve the prediction for me it's ok.
I'll do it in flask + Python Tensorflow. I'll improve the prediction of your model
I just saw your project description carefully. I am very interested in your project. I have rich experience in Python and webscraping. I can help you surely and complete in a short time..
waiting for your reply, sir.