Spaces:
Runtime error
Runtime error
UCLV\beel commited on
Commit ·
e6e93d6
1
Parent(s): 10740cb
Modeltester gradio app
Browse files- .gitattributes +2 -0
- .ipynb_checkpoints/ModelTester-checkpoint.ipynb +0 -0
- 1.jpg +3 -0
- 2-3.jpg +3 -0
- 4.jpg +3 -0
- ModelTester.ipynb +0 -0
- app.py +64 -4
- textfile3-2.pk1 +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.pk1 filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
.ipynb_checkpoints/ModelTester-checkpoint.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
1.jpg
ADDED
|
Git LFS Details
|
2-3.jpg
ADDED
|
Git LFS Details
|
4.jpg
ADDED
|
Git LFS Details
|
ModelTester.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
app.py
CHANGED
|
@@ -1,7 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ModelTester.ipynb.
|
| 2 |
+
|
| 3 |
+
# %% auto 0
|
| 4 |
+
__all__ = ['learn', 'categories', 'examples', 'intf', 'OrdinalRegressionMetric', 'classify_image']
|
| 5 |
+
|
| 6 |
+
# %% ModelTester.ipynb 1
|
| 7 |
+
from fastai.vision.all import *
|
| 8 |
import gradio as gr
|
| 9 |
|
| 10 |
+
# %% ModelTester.ipynb 3
|
| 11 |
+
from fastai.metrics import Metric
|
| 12 |
+
|
| 13 |
+
class OrdinalRegressionMetric(Metric):
|
| 14 |
+
def __init__(self):
|
| 15 |
+
super().__init__()
|
| 16 |
+
self.total = 0
|
| 17 |
+
self.count = 0
|
| 18 |
+
|
| 19 |
+
def accumulate(self, learn):
|
| 20 |
+
# Get predictions and targets
|
| 21 |
+
preds, targs = learn.pred, learn.y
|
| 22 |
+
|
| 23 |
+
# Your custom logic to convert predictions and targets to numeric values
|
| 24 |
+
preds_numeric = torch.argmax(preds, dim=1)
|
| 25 |
+
targs_numeric = targs
|
| 26 |
+
|
| 27 |
+
#print("preds_numeric: ",preds_numeric)
|
| 28 |
+
#print("targs_numeric: ",targs_numeric)
|
| 29 |
+
|
| 30 |
+
# Calculate the metric (modify this based on your specific needs)
|
| 31 |
+
squared_diff = torch.sum(torch.sqrt((preds_numeric - targs_numeric)**2))
|
| 32 |
+
|
| 33 |
+
# Normalize by the maximum possible difference
|
| 34 |
+
max_diff = torch.sqrt((torch.max(targs_numeric) - torch.min(targs_numeric))**2)
|
| 35 |
+
|
| 36 |
+
#print("squared_diff: ",squared_diff)
|
| 37 |
+
#print("max_diff: ",max_diff)
|
| 38 |
+
|
| 39 |
+
# Update the metric value
|
| 40 |
+
self.total += squared_diff
|
| 41 |
+
#print("self.total: ",self.total)
|
| 42 |
+
self.count += max_diff
|
| 43 |
+
#print("self.count: ",self.count)
|
| 44 |
+
@property
|
| 45 |
+
def value(self):
|
| 46 |
+
if self.count == 0:
|
| 47 |
+
return 0.0 # or handle this case appropriately
|
| 48 |
+
#print("self.total / self.count: ", (self.total / self.count))
|
| 49 |
+
# Calculate the normalized metric value
|
| 50 |
+
metric_value = 1/(self.total / self.count)
|
| 51 |
+
return metric_value
|
| 52 |
+
|
| 53 |
+
# %% ModelTester.ipynb 4
|
| 54 |
+
learn = load_learner("textfile3-2.pk1")
|
| 55 |
+
|
| 56 |
+
# %% ModelTester.ipynb 6
|
| 57 |
+
categories = ("0","1","2","3","4","5","6","7","8")
|
| 58 |
+
|
| 59 |
+
def classify_image(img):
|
| 60 |
+
pred, idx, probs = learn.predict(img)
|
| 61 |
+
return dict(zip(categories, map(float, probs)))
|
| 62 |
+
|
| 63 |
+
# %% ModelTester.ipynb 8
|
| 64 |
+
examples = ['2-3.jpg','1.jpg','4.jpg']
|
| 65 |
|
| 66 |
+
intf = gr.Interface(fn=classify_image, inputs='image', outputs='label', examples=examples)
|
| 67 |
+
intf.launch(inline=False)
|
textfile3-2.pk1
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c86bf454f4bcf7dd0fba8c4628ac89872ce3431fb4d2997ccbdbab5ba70c3dbb
|
| 3 |
+
size 46998504
|