osanseviero commited on
Commit
e8e50c3
1 Parent(s): d95dc9f

Create pipeline.py

Browse files
Files changed (1) hide show
  1. pipeline.py +27 -0
pipeline.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+ from PIL import Image
3
+
4
+ class PreTrainedPipeline():
5
+ def __init__(self, path=""):
6
+ # IMPLEMENT_THIS
7
+ # Preload all the elements you are going to need at inference.
8
+ # For instance your model, processors, tokenizer that might be needed.
9
+ # This function is only called once, so do all the heavy processing I/O here"""
10
+ raise NotImplementedError(
11
+ "Please implement PreTrainedPipeline __init__ function"
12
+ )
13
+
14
+ def __call__(self, inputs: "Image.Image") -> List[Dict[str, Any]]:
15
+ """
16
+ Args:
17
+ inputs (:obj:`PIL.Image`):
18
+ The raw image representation as PIL.
19
+ No transformation made whatsoever from the input. Make all necessary transformations here.
20
+ Return:
21
+ A :obj:`list`:. The list contains items that are dicts should be liked {"label": "XXX", "score": 0.82}
22
+ It is preferred if the returned list is in decreasing `score` order
23
+ """
24
+ # IMPLEMENT_THIS
25
+ raise NotImplementedError(
26
+ "Please implement PreTrainedPipeline __call__ function"
27
+ )