awinml's picture
Upload 2 files
5f0f615
import numpy as np
from tensorflow.image import resize
classes = [
"air hockey",
"ampute football",
"archery",
"arm wrestling",
"axe throwing",
"balance beam",
"barell racing",
"baseball",
"basketball",
"baton twirling",
"bike polo",
"billiards",
"bmx",
"bobsled",
"bowling",
"boxing",
"bull riding",
"bungee jumping",
"canoe slamon",
"cheerleading",
"chuckwagon racing",
"cricket",
"croquet",
"curling",
"disc golf",
"fencing",
"field hockey",
"figure skating men",
"figure skating pairs",
"figure skating women",
"fly fishing",
"football",
"formula 1 racing",
"frisbee",
"gaga",
"giant slalom",
"golf",
"hammer throw",
"hang gliding",
"harness racing",
"high jump",
"hockey",
"horse jumping",
"horse racing",
"horseshoe pitching",
"hurdles",
"hydroplane racing",
"ice climbing",
"ice yachting",
"jai alai",
"javelin",
"jousting",
"judo",
"lacrosse",
"log rolling",
"luge",
"motorcycle racing",
"mushing",
"nascar racing",
"olympic wrestling",
"parallel bar",
"pole climbing",
"pole dancing",
"pole vault",
"polo",
"pommel horse",
"rings",
"rock climbing",
"roller derby",
"rollerblade racing",
"rowing",
"rugby",
"sailboat racing",
"shot put",
"shuffleboard",
"sidecar racing",
"ski jumping",
"sky surfing",
"skydiving",
"snow boarding",
"snowmobile racing",
"speed skating",
"steer wrestling",
"sumo wrestling",
"surfing",
"swimming",
"table tennis",
"tennis",
"track bicycle",
"trapeze",
"tug of war",
"ultimate",
"uneven bars",
"volleyball",
"water cycling",
"water polo",
"weightlifting",
"wheelchair basketball",
"wheelchair racing",
"wingsuit flying",
]
def predict_label(img, model):
resized_img = resize(img, (150, 150)).numpy().astype(int)
exp_img = np.expand_dims(resized_img, 0)
y_prob = model.predict(exp_img)
if y_prob.max(axis=-1) < 0.5:
return "Cannot predict. Please provide appropriate image."
else:
y_classes = y_prob.argmax(axis=-1)
label = classes[y_classes[0]]
return "Predicted Sport: " + label.capitalize()