Open yarekc opened 3 years ago
@yarekc the simplest way to deploy this on a server is to
docker run -p8080:8080 notaitech/nudenet:detector
or :classifier if you want the classifier.http://localhost:8080/sync
to which you can send any image as a base64 encoded file and get the prediction back.Sounds great This will start a api server with endpoint at http://localhost:8080/sync to which you can send any image as a base64 encoded file and get the prediction back.
Send = POST ? Maybe a sample about what to Send ? Just base64 data ? Other params ?
Send = POST ?
yes
https://fastdeploy.notai.tech/api#request-type-file this details the request formats.
{
"data": {
"1.png": "base64 encoded 1.png",
"2.png": "base64 encoded 2.png"
}
}
this is the format of the json.
Hi,
docker run -p8080:8080 notaitech/nudenet:detector
2021-02-18:13:01:40,720 INFO [_utils.py:129] AVAILABLE FREE MEMORY: 3384207.09375; CACHE: 169210.35468750002 MB
2021-02-18:13:01:40,830 INFO [_utils.py:129] AVAILABLE FREE MEMORY: 3384207.08984375; CACHE: 169210.3544921875 MB
2021-02-18:13:01:41,533 INFO [_utils.py:186] Warming up ..
Waiting for prediction loop to begin.
2021-02-18:13:01:47,507 INFO [_utils.py:226] Time per sample for batch_size: 1 is 0.9713496367136637
Waiting for prediction loop to begin.
2021-02-18:13:01:53,307 INFO [_utils.py:226] Time per sample for batch_size: 2 is 0.9665474096934
2021-02-18:13:01:53,307 INFO [_utils.py:241] optimum batch size is 1
2021-02-18:13:01:53,339 INFO [_loop.py:35] Starting prediction loop
Waiting for prediction loop to begin.
2021-02-18:13:01:55,817 INFO [_utils.py:129] AVAILABLE FREE MEMORY: 3384207.0390625; CACHE: 169210.351953125 MB
2021-02-18:13:01:55,823 INFO [_generate_run_sh.py:11] WORKERS=2; batch_size=1; cpu_count=12
2021-02-18:13:01:56,234 INFO [_utils.py:129] AVAILABLE FREE MEMORY: 3384207.015625; CACHE: 169210.35078125002 MB
[2021-02-18 13:01:56 +0000] [65] [INFO] Starting gunicorn 20.0.4
[2021-02-18 13:01:56 +0000] [65] [INFO] Listening at: http://0.0.0.0:8080 (65)
[2021-02-18 13:01:56 +0000] [65] [INFO] Using worker: gevent
[2021-02-18 13:01:56 +0000] [69] [INFO] Booting worker with pid: 69
[2021-02-18 13:01:56 +0000] [70] [INFO] Booting worker with pid: 7
Server runs on : http://46.105.117.18:8080/ (which gives me a 404 error with direct access, which I believe is normal)
Then I try to POST data (2 php methods)
<?php
ini_set('display_errors', 1);error_reporting(E_ALL);
$url = "http://46.105.117.18:8080/";
$image1 = base64_encode(file_get_contents('https://www.rezocoquin.com/uploads/big/801590326639.jpg'));
$data = array(
'1.png'=>$image1
);
$payload = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result1 = curl_exec($ch);
print_r($result1);
$options = array(
'http' => array(
'method' => 'POST',
'content' => $payload,
'header'=> "Content-Type: application/json\r\n" .
"Accept: application/json\r\n"
)
);
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
$result2 = json_decode( $result );
print_r($result2);
method1: blank result method2: 404 error
Any clue/tip/help is welcome.
Regards
are you posting to /sync
end point? Also, the json your are sending should have "data" key.
something like
$data = array('data' => array( '1.png'=>$image1 ););
I just changed $url and set it to
$url = "http://46.105.117.18:8080/sync/";
and got the same result
remove / at the end
You are a GENIOUS ! May I suggest you to publish this php same ? (I am sure there will be lot of people interested in !) Regards
{"prediction": {"1.png": [{"box": [194, 335, 380, 495], "score": 0.8863019943237305, "label": "EXPOSED_BREAST_F"}, {"box": [64, 444, 253, 571], "score": 0.7764702439308167, "label": "EXPOSED_BELLY"}, {"box": [42, 220, 246, 426], "score": 0.6950249075889587, "label": "EXPOSED_BREAST_F"}]}, "success": true}stdClass Object ( [prediction] => stdClass Object ( [1.png] => Array ( [0] => stdClass Object ( [box] => Array ( [0] => 194 [1] => 335 [2] => 380 [3] => 495 ) [score] => 0.88630199432373 [label] => EXPOSED_BREAST_F ) [1] => stdClass Object ( [box] => Array ( [0] => 64 [1] => 444 [2] => 253 [3] => 571 ) [score] => 0.77647024393082 [label] => EXPOSED_BELLY ) [2] => stdClass Object ( [box] => Array ( [0] => 42 [1] => 220 [2] => 246 [3] => 426 ) [score] => 0.69502490758896 [label] => EXPOSED_BREAST_F ) ) ) [success] => 1 )
@yarekc can you post the full php snippet for this. I will link it in the readme.
I'm using the following PHP script:
<?php
header("Content-Type: application/json");
$url = "http://localhost:8080/sync";
$image1 = base64_encode(file_get_contents('https://domain.com/16955673673220129769.jpg'));
$data = array('data' => array('image'=>$image1));
$payload = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result1 = curl_exec($ch);
print_r($result1);
?>
and all I get is this:
{
"prediction": {
"image": {
"safe": 0.07022832334041595,
"unsafe": 0.9297716617584229
}
},
"success": true
}
Am I missing something?
Hi,
Your project looks great. However I have not Python knowledge at all (nodejs/js only) and was unable to test it.
I think it would be great if you can provide the simplest possible way to deploy that on a dedicated server and a small snippet on how to use that in html/js page (a kind of rest API ajax call I guess)
A kind of "demo" page.
Thanks a lot.