Waste-Detector / app.py
Hector Lopez
Added closing ports before launching
95d9d45
raw
history blame
1.65 kB
import gradio as gr
import PIL
import torch
from utils import plot_img_no_mask, get_models
from classifier import CustomEfficientNet, CustomViT
from model import get_model, predict, prepare_prediction, predict_class
DET_CKPT = 'efficientDet_icevision.ckpt'
CLASS_CKPT = 'class_ViT_taco_7_class.pth'
def waste_detector_interface(
image,
detection_threshold,
nms_threshold
):
det_model, classifier = get_models(DET_CKPT, CLASS_CKPT)
print('Getting predictions')
pred_dict = predict(det_model, image, detection_threshold)
print('Fixing the preds')
boxes, image = prepare_prediction(pred_dict, nms_threshold)
print('Predicting classes')
labels = predict_class(classifier, image, boxes)
print('Plotting')
return plot_img_no_mask(image, boxes, labels)
inputs = [
gr.inputs.Image(type="pil", label="Original Image"),
gr.inputs.Number(default=0.5, label="detection_threshold"),
gr.inputs.Number(default=0.5, label="nms_threshold"),
]
outputs = [
gr.outputs.Image(type="plot", label="Prediction"),
]
title = 'Waste Detection'
description = 'Demo for waste object detection. It detects and classify waste in images according to which rubbish bin the waste should be thrown. Upload an image or click an image to use.'
examples = [
['example_imgs/basura_4_2.jpg', 0.5, 0.5],
['example_imgs/basura_1.jpg', 0.5, 0.5],
['example_imgs/basura_3.jpg', 0.5, 0.5]
]
gr.close_all()
gr.Interface(
waste_detector_interface,
inputs,
outputs,
title=title,
description=description,
examples=examples,
theme="huggingface",
).launch(share=True, enable_queue=True)