Henry Du commited on
Commit
aba3a63
·
1 Parent(s): bdd497a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -15
app.py CHANGED
@@ -40,23 +40,10 @@ def convert_img_to_tensor(img):
40
 
41
 
42
  def predict(img) -> Dict:
43
- """Transforms and performs a prediction on img and returns prediction and time taken.
44
  """
45
- # Start the timer
46
- # print(type(img))
47
- # img = img['composite']
48
- # if type(img) == numpy.ndarray:
49
- # img = PIL.Image.fromarray(img)
50
  img = convert_img_to_tensor(img)
51
- # padding = transforms.CenterCrop([224, 224])
52
- # img = padding(img)
53
- # img = torch.from_numpy(img)
54
- # print(img.shape)
55
- # Transform the target image and add a batch dimension
56
- # # img = torch.tensor(img, dtype=torch.float32).unsqueeze(0).unsqueeze(0) / 255
57
  img = mobileNetV3_transform(img).unsqueeze(0)
58
- # img = image_transform(img).unsqueeze(0)
59
-
60
 
61
  # Put model into evaluation mode and turn on inference mode
62
  mobileNetV3.eval()
@@ -64,7 +51,6 @@ def predict(img) -> Dict:
64
  # Pass the transformed image through the model and turn the prediction logits into prediction probabilities
65
  y_pred = mobileNetV3(img)
66
  pred_probs = torch.softmax(y_pred, dim=1)
67
- # y_pred_class = torch.argmax(torch.softmax(y_pred, dim=1), dim=1)
68
 
69
  # Create a prediction label and prediction probability dictionary for each prediction class (this is the required format for Gradio's output parameter)
70
  pred_labels_and_probs = {class_names[i]: float(pred_probs[0][i]) for i in range(len(class_names))}
@@ -73,6 +59,7 @@ def predict(img) -> Dict:
73
 
74
  # Return the prediction dictionary and prediction time
75
  return pred_labels_and_probs
 
76
  link_to_code = "https://github.com/henrythdu/MobileNetV3-QuickDraw-Animals"
77
  title = "MobileNetV3 - Quick Draw - Animals 🔢"
78
  description = "An MobileNetV3 feature extractor computer vision model to classify doodling of animals from Quick Draw dataset. The goal is to have a small model without significantly compromising on the predictive performance"
 
40
 
41
 
42
  def predict(img) -> Dict:
43
+ """Transforms and performs a prediction on img and returns prediction.
44
  """
 
 
 
 
 
45
  img = convert_img_to_tensor(img)
 
 
 
 
 
 
46
  img = mobileNetV3_transform(img).unsqueeze(0)
 
 
47
 
48
  # Put model into evaluation mode and turn on inference mode
49
  mobileNetV3.eval()
 
51
  # Pass the transformed image through the model and turn the prediction logits into prediction probabilities
52
  y_pred = mobileNetV3(img)
53
  pred_probs = torch.softmax(y_pred, dim=1)
 
54
 
55
  # Create a prediction label and prediction probability dictionary for each prediction class (this is the required format for Gradio's output parameter)
56
  pred_labels_and_probs = {class_names[i]: float(pred_probs[0][i]) for i in range(len(class_names))}
 
59
 
60
  # Return the prediction dictionary and prediction time
61
  return pred_labels_and_probs
62
+
63
  link_to_code = "https://github.com/henrythdu/MobileNetV3-QuickDraw-Animals"
64
  title = "MobileNetV3 - Quick Draw - Animals 🔢"
65
  description = "An MobileNetV3 feature extractor computer vision model to classify doodling of animals from Quick Draw dataset. The goal is to have a small model without significantly compromising on the predictive performance"