pr4nav101 commited on
Commit
d767156
·
verified ·
1 Parent(s): 926db48

Upload 6 files

Browse files
Files changed (6) hide show
  1. activity_recognition.h5 +3 -0
  2. activity_recognition2.h5 +3 -0
  3. classes.txt +30 -0
  4. main.py +87 -0
  5. requirements.txt +7 -0
  6. utils.py +34 -0
activity_recognition.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2dbceddfb0b6e54dafd62e7a06831659633db33694bf3859f32b8639af75cd38
3
+ size 44792360
activity_recognition2.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:13a14c7b271bb053fefc262a231e94ed8210218120a6aba936d164140efea524
3
+ size 18776384
classes.txt ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1 ApplyEyeMakeup
2
+ 2 ApplyLipstick
3
+ 3 Archery
4
+ 4 BabyCrawling
5
+ 5 BalanceBeam
6
+ 6 BandMarching
7
+ 7 BaseballPitch
8
+ 8 Basketball
9
+ 9 BasketballDunk
10
+ 10 BenchPress
11
+ 11 Biking
12
+ 12 Billiards
13
+ 13 BlowDryHair
14
+ 14 BlowingCandles
15
+ 15 BodyWeightSquats
16
+ 16 Bowling
17
+ 17 BoxingPunchingBag
18
+ 18 BoxingSpeedBag
19
+ 19 BreastStroke
20
+ 20 BrushingTeeth
21
+ 21 CleanAndJerk
22
+ 22 CliffDiving
23
+ 23 CricketBowling
24
+ 24 CricketShot
25
+ 25 CuttingInKitchen
26
+ 26 Diving
27
+ 27 Drumming
28
+ 28 Fencing
29
+ 29 FieldHockeyPenalty
30
+ 30 FloorGymnastics
main.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Mon Dec 11 19:31:04 2023
4
+
5
+ @author: Pranav
6
+ """
7
+
8
+ import streamlit as st
9
+ import os
10
+ import cv2
11
+ import numpy as np
12
+ import pandas as pd
13
+ import tensorflow as tf
14
+ from tensorflow import keras
15
+ from keras.models import load_model
16
+ from utils import eval_real,load_video
17
+ import tempfile
18
+
19
+ st.title('Action Recognition video spliter')
20
+ st.header('Please Upload a Video')
21
+
22
+ file = st.file_uploader('',type=['mp4'])
23
+ isresnet = st.button("Load Resnet Model")
24
+ iscnnlstm = st.button("Load CNN-LSTM Model")
25
+
26
+ label_data = pd.read_csv("classes.txt", sep = ' ', header = None)
27
+ label_data.columns = ['index','labels']
28
+ classes = label_data['labels']
29
+
30
+ if file is not None :
31
+ video_bytes = file.read()
32
+ st.video(video_bytes)
33
+
34
+ with tempfile.NamedTemporaryFile(dir='.') as f:
35
+ f.write(file.getbuffer())
36
+
37
+ model = load_model('activity_recognition.h5',compile = False)
38
+
39
+ if iscnnlstm == True :
40
+ model = load_model('activity_recognition2.h5',compile = False)
41
+
42
+ images = load_video(f.name)
43
+
44
+ edited_img = []
45
+ count = 0
46
+ for count in range(len(images[0]) - 15):
47
+ imgs = images[0][count:count+15]
48
+ edited_img.append(imgs)
49
+ count += 1
50
+ edited_imgs = np.array(edited_img)
51
+ images_arr = np.array(images)
52
+
53
+ model.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'])
54
+ pred = []
55
+ with st.spinner('Wait for it...'):
56
+ for img in edited_imgs:
57
+ img = img.reshape(1,15,64,64,3)
58
+ prediction = eval_real(img,model)
59
+ pred.append(prediction)
60
+ st.success('Done!')
61
+
62
+ names = []
63
+ start = []
64
+ end = []
65
+ start.append(0)
66
+ names.append(classes[pred[0]])
67
+ for i in range(len(pred)-1):
68
+ if pred[i] != pred[i+1] :
69
+ names.append(classes[pred[i]])
70
+ if len(end) != 0:
71
+ end.pop()
72
+ end.append(i)
73
+ start.append(i+1)
74
+ end.append(i+1)
75
+ else :
76
+ if len(end) != 0:
77
+ end.pop()
78
+ end.append(i)
79
+
80
+ for j in range(len(end)):
81
+ if j < len(names) :
82
+ name = names[j]
83
+ else: name = names[j-1]
84
+ if start[j] - end[j] != 0:
85
+ st.write('Video ',j,' Start: ',start[j],' End: ',end[j],name)
86
+ else:
87
+ st.write('Video',j,'Insignificant Change')
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ keras==2.12.0
2
+ numpy==2.0.0
3
+ opencv_python==4.9.0.80
4
+ pandas==2.2.2
5
+ streamlit==1.33.0
6
+ tensorflow==2.12.0
7
+ tensorflow_intel==2.12.0
utils.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+
4
+
5
+ def video_Frames(clip_path,img_size = 64):
6
+ video = cv2.VideoCapture(clip_path)
7
+ frame_count = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
8
+ for count in range(frame_count):
9
+ flag, frame = video.read()
10
+ if not flag:
11
+ break
12
+ frame = cv2.resize(frame,(img_size,img_size))
13
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
14
+ #normalizing the pixels between 0 and 1
15
+ frame = frame/255.0
16
+ yield frame
17
+ video.release()
18
+
19
+
20
+ def load_video(folder_path):
21
+ imgs = []
22
+ frames_generator = video_Frames(folder_path)
23
+ frames_array = np.array(list(frames_generator))
24
+ imgs.append(frames_array)
25
+ real_imgs = np.array(imgs)
26
+
27
+ return imgs
28
+
29
+
30
+ def eval_real(real_imgs, model):
31
+ pred1 = model.predict(real_imgs)
32
+ pred1_max = pred1.argmax()
33
+
34
+ return pred1_max