rahul5035 commited on
Commit
22801e0
1 Parent(s): 4f4f224

Upload 5 files

Browse files
Files changed (5) hide show
  1. LRCN_model.h5 +3 -0
  2. app.py +36 -1
  3. prediction.py +59 -0
  4. requirements.txt +4 -0
  5. youtube_downloader.py +36 -0
LRCN_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:08f4c257915c46e805cd6bd83ade5612975ba3d832f4271f9362af748e27a67f
3
+ size 946728
app.py CHANGED
@@ -1,2 +1,37 @@
1
  import streamlit as st
2
- st.text("hello")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from youtube_downloader import Download
3
+ from collections import deque
4
+ from prediction import Predict
5
+
6
+ downld=Download()
7
+
8
+ st.title("Human Action Recognization [DL]")
9
+ with st.expander("Details", expanded=False):
10
+ st.write('''
11
+ The chart above shows some numbers I picked for you.
12
+ I rolled actual dice for these, so they're *guaranteed* to
13
+ be random''')
14
+
15
+
16
+ url= st.text_input("Insert Youtube Url as instructed above ")
17
+
18
+ if st.button("submit"):
19
+ title, output_dir=downld.youtube_d(url)
20
+ col1, col2 = st.columns([2, 2])
21
+
22
+ with col1:
23
+ st.write(f"Video [{title}] downloaded successfully!")
24
+ print(output_dir)
25
+ st.video(f"{output_dir}/{title}.mp4")
26
+
27
+ with col2:
28
+ st.write("wait while model is performing its task")
29
+ pred =Predict()
30
+ frames_needed=25
31
+ input_path=f"{output_dir}/{title}.mp4"
32
+ output_path=f"test_videos/{title}_output.mp4"
33
+ pred.prediction(input_path,output_path ,frames_needed)
34
+
35
+ # st.video(f"test_videos/{title}.mp4")
36
+
37
+
prediction.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+ import math
4
+ from collections import deque
5
+ import tensorflow as tf
6
+ from tensorflow import keras
7
+ from collections import OrderedDict
8
+
9
+
10
+ from keras.models import load_model
11
+
12
+ LCRN_model = load_model('LRCN_model.h5')
13
+
14
+ class Predict:
15
+
16
+ def __init__(self) :
17
+ pass
18
+
19
+
20
+ def prediction(self,input_path, output_path,frames_needed):
21
+ video_reader=cv2.VideoCapture(input_path)
22
+
23
+ original_video_width=int(video_reader.get(cv2.CAP_PROP_FRAME_WIDTH))
24
+ original_video_hight=int(video_reader.get(cv2.CAP_PROP_FRAME_HEIGHT))
25
+
26
+ video_writer=cv2.VideoWriter(output_path,cv2.VideoWriter_fourcc("M","P","4","V"),video_reader.get(cv2.CAP_PROP_FPS),(original_video_width,original_video_hight))
27
+ frames_deque=deque(maxlen=frames_needed)
28
+
29
+ predicted_class_name=""
30
+ IMAGE_HEIGHT , IMAGE_WIDTH = 64, 64
31
+ classes_to_be_used=["HorseRace","BenchPress","PullUps","PushUps","HorseRiding","HighJump","Swing"]
32
+
33
+ while video_reader.isOpened():
34
+
35
+ ok, frame= video_reader.read()
36
+
37
+ if not ok:
38
+ break
39
+
40
+ resized_frame=cv2.resize(frame,(IMAGE_HEIGHT,IMAGE_WIDTH))
41
+
42
+ normalized_frame= resized_frame/255
43
+
44
+ frames_deque.append(normalized_frame)
45
+
46
+ if len(frames_deque)==frames_needed:
47
+
48
+ predicted_labels_probabilities= LCRN_model.predict(np.expand_dims(frames_deque,axis=0)[0])
49
+
50
+ predicted_label=np.argmax(predicted_labels_probabilities)
51
+
52
+ predicted_class_name=classes_to_be_used[predicted_label]
53
+
54
+ cv2.putText(frame,predicted_class_name,(10,30),cv2.FONT_HERSHEY_SIMPLEX,1,(0,255,0),2)
55
+
56
+ video_writer.write(frame)
57
+
58
+ video_reader.release()
59
+ video_writer.release()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ !pip install pytube@git+https://github.com/priyankaj1311/pytube.git@master_copy
3
+
4
+ opencv-python
youtube_downloader.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pytube import YouTube
2
+ import streamlit as st
3
+ import os
4
+
5
+ # YouTube video URL
6
+ # video_url = 'https://youtu.be/7zJvNZVZMew'
7
+
8
+ # Set the output directory
9
+
10
+
11
+ # # Choose the highest resolution stream (usually the first one)
12
+ # video_stream = yt.streams.get_highest_resolution()
13
+
14
+ # # Download the video
15
+ # video_stream.download(output_path=output_dir)
16
+
17
+ # print("Video downloaded successfully!")
18
+
19
+ class Download:
20
+ def __init__(self):
21
+ pass
22
+
23
+ def youtube_d(self,url):
24
+ self.url = url
25
+ os.makedirs('test_videos',exist_ok=True)
26
+ output_dir = "test_videos"
27
+ print(url)
28
+ yt = YouTube(url)
29
+ video_stream = yt.streams.get_highest_resolution()
30
+ video_stream.download(output_path=output_dir)
31
+
32
+ return yt.title, output_dir
33
+
34
+
35
+
36
+