not-lain commited on
Commit
6afbcc3
1 Parent(s): b504e38

add pipeline

Browse files

this pr will add pipeline to your repo to test it out before merging you can try the following code :
```
pip install loadimg
```
```python
# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("image-to-image", model="p1atdev/MangaLineExtraction-hf",
revision="refs/pr/1",trust_remote_code=True)
```

Files changed (2) hide show
  1. MangaPipe.py +22 -0
  2. config.json +10 -0
MangaPipe.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import Pipeline , AutoModel, AutoImageProcessor, pipeline
2
+ from PIL import Image
3
+ from loadimg import load_img
4
+ import torch
5
+ REPO_NAME = "p1atdev/MangaLineExtraction-hf"
6
+
7
+ class MangaLineExtractionPipe(Pipeline):
8
+ def __init__(self,**kwargs):
9
+ self.processor = AutoImageProcessor.from_pretrained("p1atdev/MangaLineExtraction-hf", trust_remote_code=True)
10
+ Pipeline.__init__(self,**kwargs)
11
+ self.model.eval()
12
+ def _sanitize_parameters(kwargs):
13
+ return {}, {} , {}
14
+ def preprocess(self,image):
15
+ # takes any image type and returns a pil image
16
+ image = load_img(image, output_type = "pil").convert("RGB")
17
+ processed = self.processor(image, return_tensors="pt")
18
+ return processed.pixel_values
19
+ def _forward(self,inputs):
20
+ return self.model(inputs)
21
+ def postprocess(self,outputs):
22
+ return Image.fromarray(outputs.pixel_values[0].numpy().astype("uint8"), mode="L")
config.json CHANGED
@@ -6,6 +6,16 @@
6
  "AutoConfig": "configuration_mle.MLEConfig",
7
  "AutoModel": "modeling_mle.MLEForAnimeLineExtraction"
8
  },
 
 
 
 
 
 
 
 
 
 
9
  "batch_norm_eps": 0.001,
10
  "block_kernel_size": 3,
11
  "block_patch_size": 24,
 
6
  "AutoConfig": "configuration_mle.MLEConfig",
7
  "AutoModel": "modeling_mle.MLEForAnimeLineExtraction"
8
  },
9
+ "custom_pipelines": {
10
+ "image-to-image": {
11
+ "impl": "MangaPipe.MangaLineExtractionPipe",
12
+ "pt": [
13
+ "AutoModel"
14
+ ],
15
+ "tf": [],
16
+ "type": "image"
17
+ }
18
+ },
19
  "batch_norm_eps": 0.001,
20
  "block_kernel_size": 3,
21
  "block_patch_size": 24,