Commit 
							
							·
						
						5161138
	
1
								Parent(s):
							
							5f31b46
								
Update pipeline.py
Browse files- pipeline.py +3 -0
    	
        pipeline.py
    CHANGED
    
    | @@ -5,6 +5,7 @@ import os | |
| 5 | 
             
            from fastai.learner import load_learner
         | 
| 6 | 
             
            from helpers import is_cat
         | 
| 7 |  | 
|  | |
| 8 |  | 
| 9 | 
             
            class PreTrainedPipeline():
         | 
| 10 | 
             
                def __init__(self, path=""):
         | 
| @@ -12,6 +13,7 @@ class PreTrainedPipeline(): | |
| 12 | 
             
                    # Preload all the elements you are going to need at inference.
         | 
| 13 | 
             
                    # For instance your model, processors, tokenizer that might be needed.
         | 
| 14 | 
             
                    # This function is only called once, so do all the heavy processing I/O here"""
         | 
|  | |
| 15 | 
             
                    self.model = load_learner(os.path.join(path, "model.pkl"))
         | 
| 16 | 
             
                    with open(os.path.join(path, "config.json")) as config:
         | 
| 17 | 
             
                        config = json.load(config)
         | 
| @@ -27,6 +29,7 @@ class PreTrainedPipeline(): | |
| 27 | 
             
                        A :obj:`list`:. The list contains items that are dicts should be liked {"label": "XXX", "score": 0.82}
         | 
| 28 | 
             
                            It is preferred if the returned list is in decreasing `score` order
         | 
| 29 | 
             
                    """
         | 
|  | |
| 30 | 
             
                    # IMPLEMENT_THIS
         | 
| 31 | 
             
                    # FastAI expects a np array, not a PIL Image.
         | 
| 32 | 
             
                    _, _, preds = self.model.predict(np.array(inputs))
         | 
|  | |
| 5 | 
             
            from fastai.learner import load_learner
         | 
| 6 | 
             
            from helpers import is_cat
         | 
| 7 |  | 
| 8 | 
            +
            def is_cat(x): return x[0].isupper()
         | 
| 9 |  | 
| 10 | 
             
            class PreTrainedPipeline():
         | 
| 11 | 
             
                def __init__(self, path=""):
         | 
|  | |
| 13 | 
             
                    # Preload all the elements you are going to need at inference.
         | 
| 14 | 
             
                    # For instance your model, processors, tokenizer that might be needed.
         | 
| 15 | 
             
                    # This function is only called once, so do all the heavy processing I/O here"""
         | 
| 16 | 
            +
                    def is_cat(x): return x[0].isupper()
         | 
| 17 | 
             
                    self.model = load_learner(os.path.join(path, "model.pkl"))
         | 
| 18 | 
             
                    with open(os.path.join(path, "config.json")) as config:
         | 
| 19 | 
             
                        config = json.load(config)
         | 
|  | |
| 29 | 
             
                        A :obj:`list`:. The list contains items that are dicts should be liked {"label": "XXX", "score": 0.82}
         | 
| 30 | 
             
                            It is preferred if the returned list is in decreasing `score` order
         | 
| 31 | 
             
                    """
         | 
| 32 | 
            +
                    def is_cat(x): return x[0].isupper()
         | 
| 33 | 
             
                    # IMPLEMENT_THIS
         | 
| 34 | 
             
                    # FastAI expects a np array, not a PIL Image.
         | 
| 35 | 
             
                    _, _, preds = self.model.predict(np.array(inputs))
         | 
