Spaces:
Sleeping
Sleeping
DataRaptor
commited on
Commit
•
845eb37
1
Parent(s):
f1bc089
Upload 64 files
Browse files- ModelClass.py +1 -26
- app.py +14 -12
- inputs/Image_3242.jpg +0 -0
- inputs/Image_3254.jpg +0 -0
- inputs/Image_3255.jpg +0 -0
- inputs/Image_3265.jpg +0 -0
- inputs/Image_3266.jpg +0 -0
- inputs/Image_3272.jpg +0 -0
- inputs/Image_3273.jpg +0 -0
- inputs/Image_3274.jpg +0 -0
- inputs/Image_3275.jpg +0 -0
- inputs/Image_3452.jpg +0 -0
- inputs/Image_3461.jpg +0 -0
- inputs/Image_3462.jpg +0 -0
- inputs/Image_3463.jpg +0 -0
- inputs/Image_3468.jpg +0 -0
- inputs/Image_3482.jpg +0 -0
- inputs/Image_3483.jpg +0 -0
- inputs/Image_3488.jpg +0 -0
- inputs/Image_3495.jpg +0 -0
- inputs/Image_3499.jpg +0 -0
- inputs/Image_3500.jpg +0 -0
- inputs/Image_3501.jpg +0 -0
- inputs/Image_3503.jpg +0 -0
- inputs/Image_3507.jpg +0 -0
- inputs/Image_3513.jpg +0 -0
- inputs/Image_3515.jpg +0 -0
- inputs/Image_3520.jpg +0 -0
- inputs/Image_3528.jpg +0 -0
- inputs/Image_3543.jpg +0 -0
- inputs/Image_3547.jpg +0 -0
- inputs/Image_3549.jpg +0 -0
- inputs/Image_3550.jpg +0 -0
- inputs/Image_3555.jpg +0 -0
- inputs/Image_3563.jpg +0 -0
- inputs/Image_3567.jpg +0 -0
- inputs/Image_3568.jpg +0 -0
- inputs/Image_3572.jpg +0 -0
- inputs/Image_3582.jpg +0 -0
- requirements.txt +2 -2
ModelClass.py
CHANGED
@@ -1,24 +1,6 @@
|
|
1 |
-
|
2 |
import torch
|
3 |
-
from torch import nn
|
4 |
from torchvision import transforms, models
|
5 |
-
#from torch_snippets import *
|
6 |
-
#from torch.utils.data import DataLoader, Dataset
|
7 |
-
#from torchsummary import summary
|
8 |
-
|
9 |
-
#import seaborn as sns
|
10 |
-
#import matplotlib.pyplot as plt
|
11 |
-
#from sklearn.model_selection import train_test_split
|
12 |
-
from PIL import Image
|
13 |
-
#import numpy as np
|
14 |
-
#import cv2
|
15 |
-
#from glob import glob
|
16 |
-
#import pandas as pd
|
17 |
-
import numpy as np
|
18 |
-
|
19 |
-
#device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
20 |
-
|
21 |
-
|
22 |
|
23 |
class ActionClassifier(nn.Module):
|
24 |
def __init__(self, ntargets):
|
@@ -86,17 +68,10 @@ def get_class(index):
|
|
86 |
|
87 |
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
|
94 |
# img = Image.open('./inputs/Image_102.jpg').convert('RGB')
|
95 |
-
|
96 |
# #print(transform(img))
|
97 |
-
|
98 |
# img = transform(img)
|
99 |
-
|
100 |
# img = img.unsqueeze(dim=0)
|
101 |
# print(img.shape)
|
102 |
|
|
|
|
|
1 |
import torch
|
2 |
+
from torch import nn
|
3 |
from torchvision import transforms, models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
class ActionClassifier(nn.Module):
|
6 |
def __init__(self, ntargets):
|
|
|
68 |
|
69 |
|
70 |
|
|
|
|
|
|
|
|
|
71 |
|
72 |
# img = Image.open('./inputs/Image_102.jpg').convert('RGB')
|
|
|
73 |
# #print(transform(img))
|
|
|
74 |
# img = transform(img)
|
|
|
75 |
# img = img.unsqueeze(dim=0)
|
76 |
# print(img.shape)
|
77 |
|
app.py
CHANGED
@@ -6,6 +6,7 @@ import ModelClass
|
|
6 |
from glob import glob
|
7 |
import torch
|
8 |
import torch.nn as nn
|
|
|
9 |
|
10 |
@st.cache_resource
|
11 |
def load_model():
|
@@ -99,8 +100,8 @@ def predict(image):
|
|
99 |
def app():
|
100 |
|
101 |
st.title('ActionNet')
|
102 |
-
st.markdown("[![View in W&B](https://img.shields.io/badge/View%20in-W%26B-blue)](https://wandb.ai/<username>/<project_name>?workspace=user-<username>)")
|
103 |
-
st.markdown('
|
104 |
|
105 |
|
106 |
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
@@ -109,7 +110,7 @@ def app():
|
|
109 |
test_image = st.selectbox('Or choose a test image', list(test_images.keys()))
|
110 |
|
111 |
|
112 |
-
st.
|
113 |
|
114 |
left_column, right_column = st.columns([1.5, 2.5], gap="medium")
|
115 |
with left_column:
|
@@ -126,22 +127,23 @@ def app():
|
|
126 |
if st.button('✨ Get prediction from AI', type='primary'):
|
127 |
spacer = st.empty()
|
128 |
|
129 |
-
|
130 |
res = infer(image)
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
139 |
right_column.write(f'{class_name}: {class_probability:.2%}')
|
140 |
right_column.progress(class_probability)
|
|
|
141 |
|
142 |
|
143 |
st.markdown("---")
|
144 |
-
st.markdown("Built by [Shamim Ahamed](https://
|
145 |
|
146 |
|
147 |
app()
|
|
|
6 |
from glob import glob
|
7 |
import torch
|
8 |
import torch.nn as nn
|
9 |
+
import numpy as np
|
10 |
|
11 |
@st.cache_resource
|
12 |
def load_model():
|
|
|
100 |
def app():
|
101 |
|
102 |
st.title('ActionNet')
|
103 |
+
# st.markdown("[![View in W&B](https://img.shields.io/badge/View%20in-W%26B-blue)](https://wandb.ai/<username>/<project_name>?workspace=user-<username>)")
|
104 |
+
st.markdown('Human Action Recognition using CNN: A Conputer Vision project that trains a ResNet model to classify human activities. The dataset contains 15 activity classes, and the model predicts the activity from input images.')
|
105 |
|
106 |
|
107 |
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
|
|
110 |
test_image = st.selectbox('Or choose a test image', list(test_images.keys()))
|
111 |
|
112 |
|
113 |
+
st.markdown('#### Selected Image')
|
114 |
|
115 |
left_column, right_column = st.columns([1.5, 2.5], gap="medium")
|
116 |
with left_column:
|
|
|
127 |
if st.button('✨ Get prediction from AI', type='primary'):
|
128 |
spacer = st.empty()
|
129 |
|
|
|
130 |
res = infer(image)
|
131 |
+
prob = res.numpy()
|
132 |
+
idx = np.argpartition(prob, -4)[-4:]
|
133 |
+
right_column.markdown('#### Results')
|
134 |
|
135 |
+
idx = list(idx)
|
136 |
+
for i in idx:
|
137 |
+
|
138 |
+
class_name = ModelClass.get_class(i).replace('_', ' ').capitalize()
|
139 |
+
class_probability = prob[i].astype(float)
|
140 |
right_column.write(f'{class_name}: {class_probability:.2%}')
|
141 |
right_column.progress(class_probability)
|
142 |
+
|
143 |
|
144 |
|
145 |
st.markdown("---")
|
146 |
+
st.markdown("Built by [Shamim Ahamed](https://www.shamimahamed.com/). Data provided by [aiplanet](https://aiplanet.com/challenges/data-sprint-76-human-activity-recognition/233/overview/about)")
|
147 |
|
148 |
|
149 |
app()
|
inputs/Image_3242.jpg
ADDED
inputs/Image_3254.jpg
ADDED
inputs/Image_3255.jpg
ADDED
inputs/Image_3265.jpg
ADDED
inputs/Image_3266.jpg
ADDED
inputs/Image_3272.jpg
ADDED
inputs/Image_3273.jpg
ADDED
inputs/Image_3274.jpg
ADDED
inputs/Image_3275.jpg
ADDED
inputs/Image_3452.jpg
ADDED
inputs/Image_3461.jpg
ADDED
inputs/Image_3462.jpg
ADDED
inputs/Image_3463.jpg
ADDED
inputs/Image_3468.jpg
ADDED
inputs/Image_3482.jpg
ADDED
inputs/Image_3483.jpg
ADDED
inputs/Image_3488.jpg
ADDED
inputs/Image_3495.jpg
ADDED
inputs/Image_3499.jpg
ADDED
inputs/Image_3500.jpg
ADDED
inputs/Image_3501.jpg
ADDED
inputs/Image_3503.jpg
ADDED
inputs/Image_3507.jpg
ADDED
inputs/Image_3513.jpg
ADDED
inputs/Image_3515.jpg
ADDED
inputs/Image_3520.jpg
ADDED
inputs/Image_3528.jpg
ADDED
inputs/Image_3543.jpg
ADDED
inputs/Image_3547.jpg
ADDED
inputs/Image_3549.jpg
ADDED
inputs/Image_3550.jpg
ADDED
inputs/Image_3555.jpg
ADDED
inputs/Image_3563.jpg
ADDED
inputs/Image_3567.jpg
ADDED
inputs/Image_3568.jpg
ADDED
inputs/Image_3572.jpg
ADDED
inputs/Image_3582.jpg
ADDED
requirements.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
-
|
2 |
Pillow
|
3 |
protobuf
|
4 |
torchvision==0.15.2
|
5 |
torch==2.0.1
|
6 |
-
|
|
|
1 |
+
streamlit==1.21.0
|
2 |
Pillow
|
3 |
protobuf
|
4 |
torchvision==0.15.2
|
5 |
torch==2.0.1
|
6 |
+
numpy
|