Deep API
Deep Learning as Cloud APIs.
This project provides an image classification cloud service for research on Black-box Adversarial Attacks.
Quick Start
Using Docker:
docker run -p 8080:8080 wuhanstudio/deepapi
Python 3:
$ pip install deepapi
# For development
# python setup.py develop
# By default, we enable all models on the server.
# Use deepapi -h to see more options.
$ python -m deepapi
Serving on port 8080...
The website and API service are available at https://localhost:8080.
DeepAPI Client
To initiate black-box adversarial attacks, we can get predictions from a cloud API using model.predict().
Behind the scene, this model makes predictions by sending a POST request to http://localhost:8080/vgg16_cifar10.
import numpy as np
from PIL import Image
from deepapi.api import DeepAPI_VGG16_Cifar10
# Load the image
x = Image.open("dog.jpg")
x = np.array(x)
# Initialize the model
model = DeepAPI_VGG16_Cifar10('http://localhost:8080', concurrency=8)
# Predict
y = model.predict(np.array([x]))[0]
# Print the result
model.print(y)
Using Curl
export IMAGE_FILE=test/cat.jpg
(echo -n '{"file": "'; base64 $IMAGE_FILE; echo '"}') | \
curl -H "Content-Type: application/json" \
-d @- http://127.0.0.1:8080/vgg16_cifar10
Using Python Request
You can also implement the API client from scratch using the request module.
def classification(url, file):
# Load the input image and construct the payload for the request
image = Image.open(file)
buff = BytesIO()
image.save(buff, format="JPEG")
data = {'file': base64.b64encode(buff.getvalue()).decode("utf-8")}
return requests.post(url, json=data).json()
res = classification('http://127.0.0.1:8080/vgg16_cifar10', 'cat.jpg')
This python script is available in the test folder. You should see prediction results by running python3 minimal.py:
cat 0.99804
deer 0.00156
truck 0.00012
airplane 0.00010
dog 0.00009
bird 0.00005
ship 0.00003
frog 0.00001
horse 0.00001
automobile 0.00001
Concurrent requests
Sending 5 concurrent requests to the API server:
$ python3 multi-client.py --num_workers 5 cat.jpg
You should see the result:
----- start -----
Sending requests
Sending requests
Sending requests
Sending requests
Sending requests
------ end ------
Concurrent Requests: 5
Total Runtime: 2.441638708114624
Metadata
Release files for deepapi 0.4.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| deepapi-0.4.3.tar.gz | 38.7 kB | Without provenance | Details for deepapi-0.4.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| deepapi-0.4.3-py3-none-any.whl | Python 3 | none | any | Details for deepapi-0.4.3-py3-none-any.whl |
Total release size: 94.9 kB
Release files / deepapi-0.4.3.tar.gz
| Download URL | deepapi-0.4.3.tar.gz |
|---|---|
| Size | 38.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b42df41793c9e87431eba0945e01c80487a2d14d4776a6951e51c0c7f7c6f257
|
|
BLAKE2b-256 checksum How to use checksums |
2774462068bcf025f6dad53b1de1541d45e4968f6fe1d744fd8988d2a437dadc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.7.13
|
Release files / deepapi-0.4.3-py3-none-any.whl
| Download URL | deepapi-0.4.3-py3-none-any.whl |
|---|---|
| Size | 56.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8efedc2056ebdd14811bd4466ad90d203d3a535fec488ac03eff3d3cc0f3bc85
|
|
BLAKE2b-256 checksum How to use checksums |
79412ab038fc38b96bcf78f61b7864ea83bd313851edc72786345ac4517c62d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.7.13
|
Security for deepapi 0.4.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.