Instructions to use p1atdev/MangaLineExtraction-hf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use p1atdev/MangaLineExtraction-hf with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-to-image", model="p1atdev/MangaLineExtraction-hf", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("p1atdev/MangaLineExtraction-hf", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
| from transformers import Pipeline , AutoModel, AutoImageProcessor, pipeline | |
| from PIL import Image | |
| from loadimg import load_img | |
| import torch | |
| REPO_NAME = "p1atdev/MangaLineExtraction-hf" | |
| class MangaLineExtractionPipe(Pipeline): | |
| def __init__(self,**kwargs): | |
| self.processor = AutoImageProcessor.from_pretrained("p1atdev/MangaLineExtraction-hf", trust_remote_code=True) | |
| Pipeline.__init__(self,**kwargs) | |
| self.model.eval() | |
| def _sanitize_parameters(kwargs): | |
| return {}, {} , {} | |
| def preprocess(self,image): | |
| # takes any image type and returns a pil image | |
| image = load_img(image, output_type = "pil").convert("RGB") | |
| processed = self.processor(image, return_tensors="pt") | |
| return processed.pixel_values | |
| def _forward(self,inputs): | |
| return self.model(inputs) | |
| def postprocess(self,outputs): | |
| return Image.fromarray(outputs.pixel_values[0].numpy().astype("uint8"), mode="L") | |