Spaces:
Runtime error
Runtime error
BilalSardar
commited on
Commit
•
67dcfd1
1
Parent(s):
e236fe9
Update app.py
Browse files
app.py
CHANGED
@@ -7,8 +7,18 @@ from tensorflow.keras.models import Sequential
|
|
7 |
from tensorflow.keras.optimizers import legacy
|
8 |
from tensorflow.keras.layers import Conv3D, LSTM, Dense, Dropout, Bidirectional, MaxPool3D, Activation, Reshape, SpatialDropout3D, BatchNormalization, TimeDistributed, Flatten
|
9 |
from tensorflow.keras.callbacks import ModelCheckpoint, LearningRateScheduler
|
|
|
10 |
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def load_video(video_path):
|
13 |
|
14 |
cap = cv2.VideoCapture(video_path)
|
@@ -74,7 +84,8 @@ model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['ac
|
|
74 |
model.load_weights('model/checkpoint')
|
75 |
|
76 |
def Predict(Video):
|
77 |
-
|
|
|
78 |
yhat = model.predict(tf.expand_dims(sample, axis=0))
|
79 |
decoded = tf.keras.backend.ctc_decode(yhat, input_length=[75], greedy=True)[0][0].numpy()
|
80 |
result=[tf.strings.reduce_join([num_to_char(word) for word in sentence]) for sentence in decoded]
|
|
|
7 |
from tensorflow.keras.optimizers import legacy
|
8 |
from tensorflow.keras.layers import Conv3D, LSTM, Dense, Dropout, Bidirectional, MaxPool3D, Activation, Reshape, SpatialDropout3D, BatchNormalization, TimeDistributed, Flatten
|
9 |
from tensorflow.keras.callbacks import ModelCheckpoint, LearningRateScheduler
|
10 |
+
from moviepy.editor import VideoFileClip
|
11 |
|
12 |
|
13 |
+
|
14 |
+
def convert_mp4_to_mpg(input_file):
|
15 |
+
if not os.path.exists(input_file):
|
16 |
+
raise FileNotFoundError(f"Input file '{input_file}' not found.")
|
17 |
+
|
18 |
+
video_clip = VideoFileClip(input_file)
|
19 |
+
video_clip.write_videofile("output.mpg", codec='mpeg2video')
|
20 |
+
video_clip.close()
|
21 |
+
|
22 |
def load_video(video_path):
|
23 |
|
24 |
cap = cv2.VideoCapture(video_path)
|
|
|
84 |
model.load_weights('model/checkpoint')
|
85 |
|
86 |
def Predict(Video):
|
87 |
+
convert_mp4_to_mpg(Video)
|
88 |
+
sample = load_data(tf.convert_to_tensor("output.mpg"))
|
89 |
yhat = model.predict(tf.expand_dims(sample, axis=0))
|
90 |
decoded = tf.keras.backend.ctc_decode(yhat, input_length=[75], greedy=True)[0][0].numpy()
|
91 |
result=[tf.strings.reduce_join([num_to_char(word) for word in sentence]) for sentence in decoded]
|