Commit
·
d9afba7
1
Parent(s):
6551aa9
Upload 2 files
Browse files- app.py +21 -2
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from fastai.vision.all import *
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
learn = load_learner('resnet18_model.pkl')
|
| 5 |
|
|
@@ -11,12 +12,30 @@ def classify_image(image):
|
|
| 11 |
is_people,_,probs = learn.predict(PILImage.create(image))
|
| 12 |
return dict(zip(categories,map(float,probs)))
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
label = gr.outputs.Label()
|
|
|
|
| 17 |
examples=['example1.jpg','example2.jpg','example3.jpg']
|
| 18 |
|
| 19 |
-
intf =gr.Interface(fn=classify_image,inputs=image,outputs=label,examples=examples
|
|
|
|
|
|
|
| 20 |
intf.launch(inline=False)
|
| 21 |
|
| 22 |
|
|
|
|
| 1 |
from fastai.vision.all import *
|
| 2 |
import gradio as gr
|
| 3 |
+
import cv2
|
| 4 |
|
| 5 |
learn = load_learner('resnet18_model.pkl')
|
| 6 |
|
|
|
|
| 12 |
is_people,_,probs = learn.predict(PILImage.create(image))
|
| 13 |
return dict(zip(categories,map(float,probs)))
|
| 14 |
|
| 15 |
+
def capture_image(cam):
|
| 16 |
+
cam = cv2.VideoCapture(0)
|
| 17 |
+
_, frame = cam.read()
|
| 18 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 19 |
+
cam.release()
|
| 20 |
+
return frame
|
| 21 |
|
| 22 |
+
|
| 23 |
+
def webcam():
|
| 24 |
+
cam = cv2.VideoCapture(0)
|
| 25 |
+
while True:
|
| 26 |
+
_, frame = cam.read()
|
| 27 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 28 |
+
yield frame
|
| 29 |
+
|
| 30 |
+
image = gr.inputs.Image(shape=(192, 192), label="Upload Image", source="upload")
|
| 31 |
+
webcam = gr.inputs.Image(shape=(192, 192), label="Webcam Image", source="webcam")
|
| 32 |
label = gr.outputs.Label()
|
| 33 |
+
|
| 34 |
examples=['example1.jpg','example2.jpg','example3.jpg']
|
| 35 |
|
| 36 |
+
intf = gr.Interface(fn=classify_image, inputs=[image, webcam], outputs=label, examples=examples,
|
| 37 |
+
allow_flagging=False, capture_session=True)
|
| 38 |
+
|
| 39 |
intf.launch(inline=False)
|
| 40 |
|
| 41 |
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
fastai
|
|
|
|
|
|
| 1 |
+
fastai==1.0.61
|
| 2 |
+
cv2
|