欢迎使用Pinferencia¶
Pinferencia?¶
没听说过Pinferencia
,这不是你的错。主要我的宣传经费,实在是不够多。
你是不是训练了一堆模型,然而别人谁用都不行。不是环境搞不定,就是bug命太硬。
你想:
要是我能有个API,谁能不陷入我的爱。不用安装不用等待,发个请求结果自己到来。
可是世上API千百万,却没有哪个我能玩得转。用来用去,看来还是我心太软,有些产品真的不能惯。
我多想这个世界变得简单,我的模型1分钟就能上线。然而现实这么残酷,一天两天过去,我的眼泪哗哗止不住。
到底谁能给予我这个恩赐啊,看来只有Pinferencia。
$ pip install "pinferencia[streamlit]"
---> 100%
High起来!¶
欢欢乐乐,搞定App¶
app.py
import joblib
import uvicorn
from pinferencia import Server
# train your model
model = "..."
# or load your model
model = joblib.load("/path/to/model.joblib") # (1)
service = Server()
service.register(
model_name="mymodel",
model=model,
entrypoint="predict", # (2)
)
-
For more details, please visit https://scikit-learn.org/stable/modules/model_persistence.html
-
entrypoint
is the function name of themodel
to perform predictions.Here the data will be sent to the
predict
function:model.predict(data)
.
app.py
import torch
import uvicorn
from pinferencia import Server
# train your models
model = "..."
# or load your models (1)
# from state_dict
model = TheModelClass(*args, **kwargs)
model.load_state_dict(torch.load(PATH))
# entire model
model = torch.load(PATH)
# torchscript
model = torch.jit.load('model_scripted.pt')
model.eval()
service = Server()
service.register(
model_name="mymodel",
model=model,
)
- For more details, please visit https://pytorch.org/tutorials/beginner/saving_loading_models.html
app.py
import tensorflow as tf
import uvicorn
from pinferencia import Server
# train your models
model = "..."
# or load your models (1)
# saved_model
model = tf.keras.models.load_model('saved_model/model')
# HDF5
model = tf.keras.models.load_model('model.h5')
# from weights
model = create_model()
model.load_weights('./checkpoints/my_checkpoint')
loss, acc = model.evaluate(test_images, test_labels, verbose=2)
service = Server()
service.register(
model_name="mymodel",
model=model,
entrypoint="predict",
)
- For more details, please visit https://www.tensorflow.org/tutorials/keras/save_and_load
app.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
app.py
import uvicorn
from pinferencia import Server
# train your models
class MyModel:
def predict(self, data):
return sum(data)
model = MyModel()
service = Server()
service.register(
model_name="mymodel",
model=model,
entrypoint="predict",
)
app.py
import uvicorn
from pinferencia import Server
# train your models
def model(data):
return sum(data)
service = Server()
service.register(
model_name="mymodel",
model=model,
)
走一个~¶
$ uvicorn app:service --reload
INFO: Started server process [xxxxx]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)