diff --git a/doc/NEW_WEB_SERVICE.md b/doc/NEW_WEB_SERVICE.md index 63f62a774d914c7271bfed1508881e04f74f2ca8..a36c1b7633076b04801bcbb5ce04ae39acd7bce9 100644 --- a/doc/NEW_WEB_SERVICE.md +++ b/doc/NEW_WEB_SERVICE.md @@ -21,7 +21,7 @@ class WebService(object): The preprocess method has two input parameters, `feed` and `fetch`. For an HTTP request `request`: -- The value of `feed` is request data `request.json` +- The value of `feed` is the feed part `request.json["feed"]` in the request data - The value of `fetch` is the fetch part `request.json["fetch"]` in the request data The return values are the feed and fetch values used in the prediction. @@ -30,7 +30,7 @@ The return values are the feed and fetch values used in the prediction. The postprocess method has three input parameters, `feed`, `fetch` and `fetch_map`: -- The value of `feed` is request data `request.json` +- The value of `feed` is the feed part `request.json["feed"]` in the request data - The value of `fetch` is the fetch part `request.json["fetch"]` in the request data - The value of `fetch_map` is the model output value. @@ -40,25 +40,17 @@ The return value will be processed as `{"reslut": fetch_map}` as the return of t ```python class ImageService(WebService): + def preprocess(self, feed={}, fetch=[]): reader = ImageReader() - if "image" not in feed: - raise ("feed data error!") - if isinstance(feed["image"], list): - feed_batch = [] - for image in feed["image"]: - sample = base64.b64decode(image) - img = reader.process_image(sample) - res_feed = {} - res_feed["image"] = img.reshape(-1) - feed_batch.append(res_feed) - return feed_batch, fetch - else: - sample = base64.b64decode(feed["image"]) + feed_batch = [] + for ins in feed: + if "image" not in ins: + raise ("feed data error!") + sample = base64.b64decode(ins["image"]) img = reader.process_image(sample) - res_feed = {} - res_feed["image"] = img.reshape(-1) - return res_feed, fetch + feed_batch.append({"image": img}) + return feed_batch, fetch ``` For the above `ImageService`, only the `preprocess` method is rewritten to process the image data in Base64 format into the data format required by prediction. diff --git a/doc/NEW_WEB_SERVICE_CN.md b/doc/NEW_WEB_SERVICE_CN.md index e1a21d8a0e91a114c9d94b09ef0afa9a0d29de89..c9555f88a62d64b2ce1b2d8dabd2bf88dc706326 100644 --- a/doc/NEW_WEB_SERVICE_CN.md +++ b/doc/NEW_WEB_SERVICE_CN.md @@ -21,7 +21,7 @@ class WebService(object): preprocess方法有两个输入参数,`feed`和`fetch`。对于一个HTTP请求`request`: -- `feed`的值为请求数据`request.json` +- `feed`的值为请求数据中的feed部分`request.json["feed"]` - `fetch`的值为请求数据中的fetch部分`request.json["fetch"]` 返回值分别是预测过程中用到的feed和fetch值。 @@ -30,7 +30,7 @@ preprocess方法有两个输入参数,`feed`和`fetch`。对于一个HTTP请 postprocess方法有三个输入参数,`feed`、`fetch`和`fetch_map`: -- `feed`的值为请求数据`request.json` +- `feed`的值为请求数据中的feed部分`request.json["feed"]` - `fetch`的值为请求数据中的fetch部分`request.json["fetch"]` - `fetch_map`的值为fetch到的模型输出值 @@ -40,25 +40,17 @@ postprocess方法有三个输入参数,`feed`、`fetch`和`fetch_map`: ```python class ImageService(WebService): + def preprocess(self, feed={}, fetch=[]): reader = ImageReader() - if "image" not in feed: - raise ("feed data error!") - if isinstance(feed["image"], list): - feed_batch = [] - for image in feed["image"]: - sample = base64.b64decode(image) - img = reader.process_image(sample) - res_feed = {} - res_feed["image"] = img.reshape(-1) - feed_batch.append(res_feed) - return feed_batch, fetch - else: - sample = base64.b64decode(feed["image"]) + feed_batch = [] + for ins in feed: + if "image" not in ins: + raise ("feed data error!") + sample = base64.b64decode(ins["image"]) img = reader.process_image(sample) - res_feed = {} - res_feed["image"] = img.reshape(-1) - return res_feed, fetch + feed_batch.append({"image": img}) + return feed_batch, fetch ``` 对于上述的`ImageService`,只重写了前处理方法,将base64格式的图片数据处理成模型预测需要的数据格式。