Spaces:
Sleeping
Sleeping
annadurai003
commited on
Commit
·
86f402d
1
Parent(s):
0375f57
Fix the transformer error
Browse files
app.py
CHANGED
|
@@ -31,24 +31,18 @@ def predict(img) -> Tuple[Dict, float]:
|
|
| 31 |
# Start a timer
|
| 32 |
start_time = timer()
|
| 33 |
# Transform the input image for use with EffNetB2
|
| 34 |
-
transform_img =
|
| 35 |
|
| 36 |
# Put model into eval mode, main prediction
|
| 37 |
effnetb2.eval()
|
| 38 |
with torch.inference_mode():
|
| 39 |
-
|
| 40 |
-
pred_prob = torch.softmax(pred,dim=1)
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
end_time = timer()
|
| 47 |
# Create a prediction label and prediction probability dictionary
|
| 48 |
pred_labels_and_probs = {class_names[i]:float(pred_prob[0][i]) for i in range(len(class_names))}
|
| 49 |
|
| 50 |
# Calculate pred time
|
| 51 |
-
time = round(
|
| 52 |
|
| 53 |
# Return pred dict and pred time
|
| 54 |
return pred_labels_and_probs,time
|
|
|
|
| 31 |
# Start a timer
|
| 32 |
start_time = timer()
|
| 33 |
# Transform the input image for use with EffNetB2
|
| 34 |
+
transform_img = effnetb2_transforms(img).unsqueeze(0)
|
| 35 |
|
| 36 |
# Put model into eval mode, main prediction
|
| 37 |
effnetb2.eval()
|
| 38 |
with torch.inference_mode():
|
| 39 |
+
pred_prob=torch.softmax(effnetb2(transform_img),dim=1)
|
|
|
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
# Create a prediction label and prediction probability dictionary
|
| 42 |
pred_labels_and_probs = {class_names[i]:float(pred_prob[0][i]) for i in range(len(class_names))}
|
| 43 |
|
| 44 |
# Calculate pred time
|
| 45 |
+
time = round(timer()-start_time,4)
|
| 46 |
|
| 47 |
# Return pred dict and pred time
|
| 48 |
return pred_labels_and_probs,time
|