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
classImageService(WebService):
defpreprocess(self,feed={},fetch=[]):
reader=ImageReader()
if"image"notinfeed:
raise("feed data error!")
ifisinstance(feed["image"],list):
feed_batch=[]
forimageinfeed["image"]:
sample=base64.b64decode(image)
forinsinfeed:
if"image"notinins:
raise("feed data error!")
sample=base64.b64decode(ins["image"])
img=reader.process_image(sample)
res_feed={}
res_feed["image"]=img.reshape(-1)
feed_batch.append(res_feed)
feed_batch.append({"image":img})
returnfeed_batch,fetch
else:
sample=base64.b64decode(feed["image"])
img=reader.process_image(sample)
res_feed={}
res_feed["image"]=img.reshape(-1)
returnres_feed,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.