Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- .gitattributes +1 -0
- app.py +19 -15
- model.keras +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ 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 |
+
model.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -1,33 +1,37 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import torch
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
-
from torchvision.transforms import Compose, Resize, ToTensor, Normalize
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
print('loading model..')
|
| 10 |
-
model =
|
| 11 |
-
model.eval()
|
| 12 |
print('loaded.')
|
| 13 |
|
| 14 |
|
| 15 |
-
transform = Compose([
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
])
|
| 21 |
|
| 22 |
def predict(img):
|
| 23 |
-
labels = list(range(10))
|
| 24 |
if isinstance(img, np.ndarray):
|
| 25 |
img = Image.fromarray(img.astype('uint8'), 'RGB')
|
| 26 |
-
img =
|
| 27 |
-
img =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
with torch.inference_mode():
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
result = { num:float(prob.numpy()) for num, prob in enumerate(prediction)}
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
# import torch
|
| 3 |
+
import tensorflow as tf
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image
|
| 6 |
+
# from torchvision.transforms import Compose, Resize, ToTensor, Normalize
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
print('loading model..')
|
| 11 |
+
model = tf.keras.models.load_model('model.keras')
|
|
|
|
| 12 |
print('loaded.')
|
| 13 |
|
| 14 |
|
| 15 |
+
# transform = Compose([
|
| 16 |
+
# Resize((300,300)),
|
| 17 |
+
# ToTensor(),
|
| 18 |
+
# Normalize(mean=[0.485, 0.456, 0.406],
|
| 19 |
+
# std=[0.229, 0.224, 0.225]),
|
| 20 |
+
# ])
|
| 21 |
|
| 22 |
def predict(img):
|
|
|
|
| 23 |
if isinstance(img, np.ndarray):
|
| 24 |
img = Image.fromarray(img.astype('uint8'), 'RGB')
|
| 25 |
+
img = img.resize((300,300))
|
| 26 |
+
img = np.array(img)
|
| 27 |
+
img = np.expand_dims(img,axis=0)
|
| 28 |
+
labels = list(range(10))
|
| 29 |
+
# img = transform(img)
|
| 30 |
+
# img = img.unsqueeze(0)
|
| 31 |
|
| 32 |
+
# with torch.inference_mode():
|
| 33 |
+
# prediction = torch.softmax(model(img),dim=1)[0]
|
| 34 |
+
prediction = model(img)[0]
|
| 35 |
|
| 36 |
|
| 37 |
result = { num:float(prob.numpy()) for num, prob in enumerate(prediction)}
|
model.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a0aed96125de150e9b07b705f2879cb465516acb8532bb8a57b85569b4210d7a
|
| 3 |
+
size 20058690
|