Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,19 @@
|
|
| 1 |
-
from huggingface_hub import from_pretrained_fastai
|
| 2 |
import gradio as gr
|
| 3 |
-
from
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
#img = PILImage.create(img)
|
| 16 |
-
pred,pred_idx,probs = learner.predict(img)
|
| 17 |
-
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 18 |
-
|
| 19 |
-
# Creamos la interfaz y la lanzamos.
|
| 20 |
-
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Label(num_top_classes=3),examples=['raccoon-177.jpg','raccoon-197.jpg']).launch(share=False)
|
| 21 |
-
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from icevision.all import *
|
| 3 |
+
import PIL
|
| 4 |
+
class_map = ClassMap(['raccoon'])
|
| 5 |
+
model = models.torchvision.faster_rcnn.model(backbone=models.torchvision.faster_rcnn.backbones.resnet50_fpn(pretrained=True), num_classes=len(class_map))
|
| 6 |
+
state_dict = torch.load('fasterRCNNRaccoonRESNET50.pth')
|
| 7 |
+
model.load_state_dict(state_dict)
|
| 8 |
+
size = 384
|
| 9 |
+
infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(size),tfms.A.Normalize()])
|
| 10 |
+
def predict(img):
|
| 11 |
+
# img = PIL.Image.open(img)
|
| 12 |
+
np.int = int
|
| 13 |
+
img = PIL.Image.fromarray(img)
|
| 14 |
|
| 15 |
+
pred_dict = models.torchvision.faster_rcnn.end2end_detect(img, infer_tfms, model.to("cpu"), class_map=class_map, detection_threshold=0.5)
|
| 16 |
+
return pred_dict['img']
|
| 17 |
|
| 18 |
+
# Creamos la interfaz y la lanzamos.
|
| 19 |
+
gr.Interface(fn=predict, inputs=["image"], outputs=["image"], examples=['raccoon/train/images/raccoon-197.jpg','raccoon/train/images/raccoon-177.jpg']).launch(share=True,debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|