otolith / app.py
gvrgrn's picture
Update app.py
cdbe999 verified
import numpy as np
import cv2
import gradio as gr
import onnxruntime as ort
labels = ["Alburnoides eichwaldi",
"Atherina boyeri",
"Barbus xanthos",
"Capoeta aydinesis",
"Carassius gibelio",
"Chelon salians",
"Coptodon zilli",
"Gymnocephalus cernua",
"Lepomis gibbosus",
"Panticola cyrius",
"Perca fluvialitis",
"Salariopsis renatorum",
"Salmo abanticus",
"Salmo araxensis",
"Salmo ardahanensis",
"Salmo caspius",
"Salmo cf. trutta",
"Salmo kotteleti",
"Salmo labecula",
"Salmo okumusi",
"Salmo opimus",
"Salmo pelagonicus",
"Salmo platycephalus",
"Salmo rizeensis",
"Salmo trutta",
"Sander luciuperca",
"Scardinius erythrophthalmus",
"Squalius fellowesii",
"Vimba mirabilis"
]
ort_session = ort.InferenceSession("otolith_effb0.onnx")
def inference(img):
img = cv2.imread(img)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = np.array(img, dtype=np.float32)
img -= [123.675, 116.28, 103.53]
img /= [58.395, 57.12, 57.375]
img = np.swapaxes(img, 0, 2)
img = np.swapaxes(img, 1, 2)
img = np.expand_dims(img, axis=0)
ort_inputs = {ort_session.get_inputs()[0].name: img}
ort_outs = ort_session.run(None, ort_inputs)
return labels[np.argmax(ort_outs)]
title = "Otolith Recognition System"
description = "In this study, a data set and artificial intelligence model are created with the otoliths of the species that make up the freshwater fish fauna of Türkiye. The model created within the scope of the study can classify 29 species with otolith images."
examples = [['sample.jpg']]
gr.Interface(inference, gr.Image(type="filepath"), "label", title=title, description=description, examples=examples).launch()