Download app.py from Jacampo/Practica2: direct link, hf CLI and curl.
- Browser
- Download file 879 Bytes
-
https://huggingface.co/spaces/Jacampo/Practica2/resolve/main/app.py
- Command line
-
hf download hf://spaces/Jacampo/Practica2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Jacampo/Practica2/resolve/main/app.py
879 Bytes
| import icevision | |
| from icevision.all import * | |
| import torch | |
| import gradio as gr | |
| import PIL | |
| from PIL import Image | |
| # Cargamos el learner | |
| learner = torch.load('fasterRCNNKangaroo_obligatorio.pth',map_location='cpu') | |
| # Definimos una función que se encarga de llevar a cabo las predicciones | |
| def predict(img): | |
| #return img | |
| size = 384 | |
| class_map = ClassMap(['kangaroo']) | |
| infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(size),tfms.A.Normalize()]) | |
| pred_dict = models.torchvision.faster_rcnn.end2end_detect(img, infer_tfms, learner.to("cpu"), class_map=class_map, detection_threshold=0.5) | |
| #return pred_dict['img'] | |
| return img | |
| # Creamos la interfaz y la lanzamos. | |
| gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Image(type="pil",label='Imagen resultado'),examples=['00001.jpg','00002.jpg']).launch(share=False) | |