Upload 12 files
Browse files- FAKE.txt +323 -0
- REAL.txt +77 -0
- arrange.py +59 -0
- dl_training.ipynb +957 -0
- dvl.ipynb +0 -0
- fast_feature_extraction.ipynb +580 -0
- feature_extraction.ipynb +429 -0
- features.csv +0 -0
- ml_training.ipynb +0 -0
- test.py +80 -0
- y.pkl +3 -0
- y_for_dl_2000.pkl +3 -0
FAKE.txt
ADDED
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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yuv.mp4
|
27 |
+
akxoopqjqz.mp4
|
28 |
+
akzbnazxtz.mp4
|
29 |
+
aladcziidp.mp4
|
30 |
+
alaijyygdv.mp4
|
31 |
+
alninxcyhg.mp4
|
32 |
+
altziddtxi.mp4
|
33 |
+
alvgwypubw.mp4
|
34 |
+
amaivqofda.mp4
|
35 |
+
amowujxmzc.mp4
|
36 |
+
andaxzscny.mp4
|
37 |
+
aneclqfpbt.mp4
|
38 |
+
aorjvbyxhw.mp4
|
39 |
+
apatcsqejh.mp4
|
40 |
+
apgjqzkoma.mp4
|
41 |
+
apogckdfrz.mp4
|
42 |
+
aqpnvjhuzw.mp4
|
43 |
+
arkroixhey.mp4
|
44 |
+
arlmiizoob.mp4
|
45 |
+
arrhsnjqku.mp4
|
46 |
+
asdpeebotb.mp4
|
47 |
+
aslsvlvpth.mp4
|
48 |
+
asmpfjfzif.mp4
|
49 |
+
asvcrfdpnq.mp4
|
50 |
+
atxvxouljq.mp4
|
51 |
+
atyntldecu.mp4
|
52 |
+
atzdznmder.mp4
|
53 |
+
aufmsmnoye.mp4
|
54 |
+
augtsuxpzc.mp4
|
55 |
+
avfitoutyn.mp4
|
56 |
+
avgiuextiz.mp4
|
57 |
+
avibnnhwhp.mp4
|
58 |
+
avnqydkqjj.mp4
|
59 |
+
avssvvsdhz.mp4
|
60 |
+
avtycwsgyb.mp4
|
61 |
+
avvdgsennp.mp4
|
62 |
+
avywawptfc.mp4
|
63 |
+
awhmfnnjih.mp4
|
64 |
+
awnwkrqibf.mp4
|
65 |
+
awukslzjra.mp4
|
66 |
+
axczxisdtb.mp4
|
67 |
+
axoygtekut.mp4
|
68 |
+
axwgcsyphv.mp4
|
69 |
+
axwovszumc.mp4
|
70 |
+
ayqvfdhslr.mp4
|
71 |
+
azpuxunqyo.mp4
|
72 |
+
azsmewqghg.mp4
|
73 |
+
bahdpoesir.mp4
|
74 |
+
bbhpvrmbse.mp4
|
75 |
+
bbhtdfuqxq.mp4
|
76 |
+
bbvgxeczei.mp4
|
77 |
+
bchnbulevv.mp4
|
78 |
+
bctvsmddgq.mp4
|
79 |
+
bdbhekrrwo.mp4
|
80 |
+
bdgipnyobr.mp4
|
81 |
+
bdxuhamuqx.mp4
|
82 |
+
benmsfzfaz.mp4
|
83 |
+
bgaogsjehq.mp4
|
84 |
+
bggsurpgpr.mp4
|
85 |
+
bghphrsfxf.mp4
|
86 |
+
bgmlwsoamc.mp4
|
87 |
+
bguwlyazau.mp4
|
88 |
+
bhaaboftbc.mp4
|
89 |
+
bhbdugnurr.mp4
|
90 |
+
bhpwpydzpo.mp4
|
91 |
+
bhsluedavd.mp4
|
92 |
+
bjjbwsqjir.mp4
|
93 |
+
bjkmjilrxp.mp4
|
94 |
+
bjsmaqefoi.mp4
|
95 |
+
bkmdzhfzfh.mp4
|
96 |
+
bkvetcojbt.mp4
|
97 |
+
bkwxhglwct.mp4
|
98 |
+
blpchvmhxx.mp4
|
99 |
+
blzydqdfem.mp4
|
100 |
+
bmbbkwmxqj.mp4
|
101 |
+
bmehkyanbj.mp4
|
102 |
+
bmhvktyiwp.mp4
|
103 |
+
bmioepcpsx.mp4
|
104 |
+
bmjmjmbglm.mp4
|
105 |
+
bnbuonyoje.mp4
|
106 |
+
bndybcqhfr.mp4
|
107 |
+
bnjcdrfuov.mp4
|
108 |
+
bntlodcfeg.mp4
|
109 |
+
bofqajtwve.mp4
|
110 |
+
boovltmuwi.mp4
|
111 |
+
bopqhhalml.mp4
|
112 |
+
bourlmzsio.mp4
|
113 |
+
bpwzipqtxf.mp4
|
114 |
+
bpxckdzddv.mp4
|
115 |
+
bqdjzqhcft.mp4
|
116 |
+
bqeiblbxtl.mp4
|
117 |
+
bqhtpqmmqp.mp4
|
118 |
+
bqkdbcqjvb.mp4
|
119 |
+
bqnymlsayl.mp4
|
120 |
+
bqqpbzjgup.mp4
|
121 |
+
bqtuuwzdtr.mp4
|
122 |
+
brhalypwoo.mp4
|
123 |
+
brvqtabyxj.mp4
|
124 |
+
bseamdrpbj.mp4
|
125 |
+
bsfmwclnqy.mp4
|
126 |
+
bsqgziaylx.mp4
|
127 |
+
btiysiskpf.mp4
|
128 |
+
btjlfpzbdu.mp4
|
129 |
+
btjwbtsgln.mp4
|
130 |
+
btmsngnqhv.mp4
|
131 |
+
btohlidmru.mp4
|
132 |
+
btugrnoton.mp4
|
133 |
+
btunxncpjh.mp4
|
134 |
+
btxlttbpkj.mp4
|
135 |
+
bvgwelbeof.mp4
|
136 |
+
bvzjkezkms.mp4
|
137 |
+
bweezhfpzp.mp4
|
138 |
+
bwuwstvsbw.mp4
|
139 |
+
bydaidkpdp.mp4
|
140 |
+
byfenovjnf.mp4
|
141 |
+
byijojkdba.mp4
|
142 |
+
byofowlkki.mp4
|
143 |
+
byqzyxifza.mp4
|
144 |
+
byunigvnay.mp4
|
145 |
+
byyqectxqa.mp4
|
146 |
+
bzmdrafeex.mp4
|
147 |
+
caqbrkogkb.mp4
|
148 |
+
cbbibzcoih.mp4
|
149 |
+
cbltdtxglo.mp4
|
150 |
+
ccmonzqfrz.mp4
|
151 |
+
cdaxixbosp.mp4
|
152 |
+
cdbsbdymzd.mp4
|
153 |
+
cdphtzqrvp.mp4
|
154 |
+
cdyakrxkia.mp4
|
155 |
+
cepxysienc.mp4
|
156 |
+
cettndmvzl.mp4
|
157 |
+
ceymbecxnj.mp4
|
158 |
+
cferslmfwh.mp4
|
159 |
+
cffffbcywc.mp4
|
160 |
+
cfyduhpbps.mp4
|
161 |
+
cglxirfaey.mp4
|
162 |
+
cgvrgibpfo.mp4
|
163 |
+
chzieimrwu.mp4
|
164 |
+
ckbdwedgmc.mp4
|
165 |
+
cknyxaqouy.mp4
|
166 |
+
cksanfsjhc.mp4
|
167 |
+
clihsshdkq.mp4
|
168 |
+
cmxcfkrjiv.mp4
|
169 |
+
cnilkgvfei.mp4
|
170 |
+
coadfnerlk.mp4
|
171 |
+
covdcysmbi.mp4
|
172 |
+
cqfugiqupm.mp4
|
173 |
+
cqhngvpgyi.mp4
|
174 |
+
cqrskwiqng.mp4
|
175 |
+
crktehraph.mp4
|
176 |
+
crzfebnfgb.mp4
|
177 |
+
cthdnahrkh.mp4
|
178 |
+
ctpqeykqdp.mp4
|
179 |
+
cttqtsjvgn.mp4
|
180 |
+
ctzmavwror.mp4
|
181 |
+
curpwogllm.mp4
|
182 |
+
cuzrgrbvil.mp4
|
183 |
+
cvaksbpssm.mp4
|
184 |
+
cwbacdwrzo.mp4
|
185 |
+
cwqlvzefpg.mp4
|
186 |
+
cwrtyzndpx.mp4
|
187 |
+
cwsbspfzck.mp4
|
188 |
+
cwwandrkus.mp4
|
189 |
+
cxfujlvsuw.mp4
|
190 |
+
cxrfacemmq.mp4
|
191 |
+
cxttmymlbn.mp4
|
192 |
+
cyboodqqyr.mp4
|
193 |
+
cycacemkmt.mp4
|
194 |
+
cyclgfjdrv.mp4
|
195 |
+
czfunozvwp.mp4
|
196 |
+
czkdanyadc.mp4
|
197 |
+
czmqpxrqoh.mp4
|
198 |
+
dafhtipaml.mp4
|
199 |
+
dakqwktlbi.mp4
|
200 |
+
dbhoxkblzx.mp4
|
201 |
+
dbhrpizyeq.mp4
|
202 |
+
dboxtiehng.mp4
|
203 |
+
dbzcqmxzaj.mp4
|
204 |
+
dbzpcjntve.mp4
|
205 |
+
dcamvmuors.mp4
|
206 |
+
dcuiiorugd.mp4
|
207 |
+
ddhfabwpuz.mp4
|
208 |
+
ddjggcasdw.mp4
|
209 |
+
ddpvuimigj.mp4
|
210 |
+
ddqccgmtka.mp4
|
211 |
+
degpbqvcay.mp4
|
212 |
+
deywhkarol.mp4
|
213 |
+
deyyistcrd.mp4
|
214 |
+
dfbpceeaox.mp4
|
215 |
+
dgmevclvzy.mp4
|
216 |
+
dgxrqjdomn.mp4
|
217 |
+
dgzklxjmix.mp4
|
218 |
+
dhcselezer.mp4
|
219 |
+
dhevettufk.mp4
|
220 |
+
dhjmzhrcav.mp4
|
221 |
+
dhkwmjxwrn.mp4
|
222 |
+
dhoqofwoxa.mp4
|
223 |
+
diomeixhrg.mp4
|
224 |
+
diopzaywor.mp4
|
225 |
+
diqraixiov.mp4
|
226 |
+
diuzrpqjli.mp4
|
227 |
+
djvtbgwdcc.mp4
|
228 |
+
djvutyvaio.mp4
|
229 |
+
dkdwxmtpuo.mp4
|
230 |
+
dkhlttuvmx.mp4
|
231 |
+
dkrvorliqc.mp4
|
232 |
+
dkwjwbwgey.mp4
|
233 |
+
dlrsbscitn.mp4
|
234 |
+
dnexlwbcxq.mp4
|
235 |
+
dnhvalzvrt.mp4
|
236 |
+
dntkzzzcdh.mp4
|
237 |
+
dnyvfblxpm.mp4
|
238 |
+
doanjploai.mp4
|
239 |
+
dofusvhnib.mp4
|
240 |
+
dozyddhild.mp4
|
241 |
+
dptbnjnkdg.mp4
|
242 |
+
dptrzdvwpg.mp4
|
243 |
+
dqnyszdong.mp4
|
244 |
+
dqppxmoqdl.mp4
|
245 |
+
dqqtjcryjv.mp4
|
246 |
+
dqswpjoepo.mp4
|
247 |
+
dqzreruvje.mp4
|
248 |
+
drgjzlxzxj.mp4
|
249 |
+
drsakwyvqv.mp4
|
250 |
+
drtbksnpol.mp4
|
251 |
+
dsdoseflas.mp4
|
252 |
+
dsgpbgsrdm.mp4
|
253 |
+
dsndhujjjb.mp4
|
254 |
+
dtbpmdqvao.mp4
|
255 |
+
dtocdfbwca.mp4
|
256 |
+
dubiroskqn.mp4
|
257 |
+
dulanfulol.mp4
|
258 |
+
duvyaxbzvp.mp4
|
259 |
+
duzuusuajr.mp4
|
260 |
+
dvakowbgbt.mp4
|
261 |
+
dvumqqhoac.mp4
|
262 |
+
dwediigjit.mp4
|
263 |
+
dxuliowugt.mp4
|
264 |
+
dxuplhwvig.mp4
|
265 |
+
dzieklokdr.mp4
|
266 |
+
dzqwgqewhu.mp4
|
267 |
+
dzvyfiarrq.mp4
|
268 |
+
dzwkmcwkwl.mp4
|
269 |
+
eahlqmfvtj.mp4
|
270 |
+
eajlrktemq.mp4
|
271 |
+
ebchwmwayp.mp4
|
272 |
+
ebebgmtlcu.mp4
|
273 |
+
ebeknhudxq.mp4
|
274 |
+
ebkzwjgjhq.mp4
|
275 |
+
ebywfrmhtd.mp4
|
276 |
+
ecnihjlfyt.mp4
|
277 |
+
ecuvtoltue.mp4
|
278 |
+
ecwaxgutkc.mp4
|
279 |
+
eczrseixwq.mp4
|
280 |
+
eebrkicpry.mp4
|
281 |
+
eebserckhh.mp4
|
282 |
+
eejswgycjc.mp4
|
283 |
+
eekozbeafq.mp4
|
284 |
+
eepezmygaq.mp4
|
285 |
+
eeyhxisdfh.mp4
|
286 |
+
efdyrflcpg.mp4
|
287 |
+
egbbcxcuqy.mp4
|
288 |
+
ehbnclaukr.mp4
|
289 |
+
ehdkmxgtxh.mp4
|
290 |
+
ehevsxtecd.mp4
|
291 |
+
ehfiekigla.mp4
|
292 |
+
ehieahnhte.mp4
|
293 |
+
eiriyukqqy.mp4
|
294 |
+
eivxffliio.mp4
|
295 |
+
eiwopxzjfn.mp4
|
296 |
+
eixwxvxbbn.mp4
|
297 |
+
ejkqesyvam.mp4
|
298 |
+
ekhacizpah.mp4
|
299 |
+
ekkdjkirzq.mp4
|
300 |
+
elginszwtk.mp4
|
301 |
+
elvvackpjh.mp4
|
302 |
+
emaalmsonj.mp4
|
303 |
+
emfbhytfhc.mp4
|
304 |
+
emgjphonqb.mp4
|
305 |
+
ensyyivobf.mp4
|
306 |
+
eoewqcpbgt.mp4
|
307 |
+
eprybmbpba.mp4
|
308 |
+
epymyyiblu.mp4
|
309 |
+
eqjscdagiv.mp4
|
310 |
+
eqvuznuwsa.mp4
|
311 |
+
erqgqacbqe.mp4
|
312 |
+
errocgcham.mp4
|
313 |
+
esckbnkkvb.mp4
|
314 |
+
esgftaficx.mp4
|
315 |
+
esnntzzajv.mp4
|
316 |
+
esxrvsgpvb.mp4
|
317 |
+
esyhwdfnxs.mp4
|
318 |
+
esyrimvzsa.mp4
|
319 |
+
etdcqxabww.mp4
|
320 |
+
etejaapnxh.mp4
|
321 |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
|
31 |
+
bxzakyopjf.mp4
|
32 |
+
bzythlfnhq.mp4
|
33 |
+
caifxvsozs.mp4
|
34 |
+
ccfoszqabv.mp4
|
35 |
+
cfxkpiweqt.mp4
|
36 |
+
chtapglbcj.mp4
|
37 |
+
chviwxsfhg.mp4
|
38 |
+
ciyoudyhly.mp4
|
39 |
+
cizlkenljw.mp4
|
40 |
+
ckjaibzfxa.mp4
|
41 |
+
ckkuyewywx.mp4
|
42 |
+
clrycekyst.mp4
|
43 |
+
cmbzllswnl.mp4
|
44 |
+
cobjrlugvp.mp4
|
45 |
+
cpjxareypw.mp4
|
46 |
+
cppdvdejkc.mp4
|
47 |
+
cprhtltsjp.mp4
|
48 |
+
crezycjqyk.mp4
|
49 |
+
cyxlcuyznd.mp4
|
50 |
+
dakiztgtnw.mp4
|
51 |
+
dbnygxtwek.mp4
|
52 |
+
dbtbbhakdv.mp4
|
53 |
+
ddepeddixj.mp4
|
54 |
+
dhcndnuwta.mp4
|
55 |
+
dhxctgyoqj.mp4
|
56 |
+
djxdyjopjd.mp4
|
57 |
+
dkuayagnmc.mp4
|
58 |
+
dkzvdrzcnr.mp4
|
59 |
+
dlpoieqvfb.mp4
|
60 |
+
drcyabprvt.mp4
|
61 |
+
dsjbknkujw.mp4
|
62 |
+
duycddgtrl.mp4
|
63 |
+
dxbqjxrhin.mp4
|
64 |
+
dzyuwjkjui.mp4
|
65 |
+
eckvhdusax.mp4
|
66 |
+
ecujsjhscd.mp4
|
67 |
+
edyncaijwx.mp4
|
68 |
+
efwfxwwlbw.mp4
|
69 |
+
eggbjzxnmg.mp4
|
70 |
+
egghxjjmfg.mp4
|
71 |
+
ehccixxzoe.mp4
|
72 |
+
ehtdtkmmli.mp4
|
73 |
+
ekcrtigpab.mp4
|
74 |
+
ellavthztb.mp4
|
75 |
+
eqnoqyfquo.mp4
|
76 |
+
erlvuvjsjf.mp4
|
77 |
+
eudeqjhdfd.mp4
|
arrange.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
import glob
|
4 |
+
|
5 |
+
|
6 |
+
# Ensure the REAL and FAKE directories exist
|
7 |
+
real_dir = r"REAL"
|
8 |
+
fake_dir = r"FAKE"
|
9 |
+
|
10 |
+
if not os.path.exists(real_dir):
|
11 |
+
os.makedirs(real_dir)
|
12 |
+
|
13 |
+
if not os.path.exists(fake_dir):
|
14 |
+
os.makedirs(fake_dir)
|
15 |
+
|
16 |
+
t = 0
|
17 |
+
|
18 |
+
real = []
|
19 |
+
fake = []
|
20 |
+
l = glob.glob("train_sample_videos/*.json")
|
21 |
+
for i in l:
|
22 |
+
with open(i, "r") as f:
|
23 |
+
x = json.load(f)
|
24 |
+
|
25 |
+
for file in x:
|
26 |
+
if x[file]["label"] == "REAL":
|
27 |
+
real.append(file)
|
28 |
+
else:
|
29 |
+
fake.append(file)
|
30 |
+
|
31 |
+
print("Real: ", real)
|
32 |
+
print("Fake: ", fake)
|
33 |
+
|
34 |
+
with open("REAL.txt", "w") as f:
|
35 |
+
for i in real:
|
36 |
+
f.write(i + "\n")
|
37 |
+
|
38 |
+
with open("FAKE.txt", "w") as f:
|
39 |
+
for i in fake:
|
40 |
+
f.write(i + "\n")
|
41 |
+
|
42 |
+
# for file in x:
|
43 |
+
# try:
|
44 |
+
# if x[file]["label"] == "REAL":
|
45 |
+
# os.rename(
|
46 |
+
# f"C:\\Users\\vaibh\\OneDrive\\Desktop\\deepfake_project\\train_sample_videos\\{file}",
|
47 |
+
# f"{real_dir}\\{file}",
|
48 |
+
# )
|
49 |
+
# except Exception as e:
|
50 |
+
# print(f"Error moving REAL video {file}: {e}")
|
51 |
+
|
52 |
+
# try:
|
53 |
+
# if x[file]["label"] == "FAKE":
|
54 |
+
# os.rename(
|
55 |
+
# f"C:\\Users\\vaibh\\OneDrive\\Desktop\\deepfake_project\\train_sample_videos\\{file}", # Corrected path
|
56 |
+
# f"{fake_dir}\\{file}",
|
57 |
+
# )
|
58 |
+
# except Exception as e:
|
59 |
+
# print(f"Error moving FAKE video {file}: {e}")
|
dl_training.ipynb
ADDED
@@ -0,0 +1,957 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"import numpy as np\n",
|
10 |
+
"import librosa\n",
|
11 |
+
"import io\n",
|
12 |
+
"import soundfile as sf\n",
|
13 |
+
"from moviepy.editor import VideoFileClip\n",
|
14 |
+
"from tqdm import tqdm\n",
|
15 |
+
"import pickle as pk\n",
|
16 |
+
"import os\n",
|
17 |
+
"import tensorflow as tf\n",
|
18 |
+
"# from tensorflow.keras.saving import register_keras_serializable\n",
|
19 |
+
"from sklearn.model_selection import train_test_split\n",
|
20 |
+
"from sklearn.metrics import classification_report, confusion_matrix\n",
|
21 |
+
"from tensorflow.keras import layers, models\n",
|
22 |
+
"from tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping"
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"cell_type": "code",
|
27 |
+
"execution_count": 2,
|
28 |
+
"metadata": {},
|
29 |
+
"outputs": [],
|
30 |
+
"source": [
|
31 |
+
"# real_audio_dir = (\n",
|
32 |
+
"# r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\REAL\"\n",
|
33 |
+
"# )\n",
|
34 |
+
"# fake_audio_dir = (\n",
|
35 |
+
"# r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\FAKE\"\n",
|
36 |
+
"# )"
|
37 |
+
]
|
38 |
+
},
|
39 |
+
{
|
40 |
+
"cell_type": "code",
|
41 |
+
"execution_count": 3,
|
42 |
+
"metadata": {},
|
43 |
+
"outputs": [],
|
44 |
+
"source": [
|
45 |
+
"# with open(\n",
|
46 |
+
"# r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\real_files.pkl\",\n",
|
47 |
+
"# \"rb\",\n",
|
48 |
+
"# ) as f:\n",
|
49 |
+
"# real_files = pk.load(f)\n",
|
50 |
+
"\n",
|
51 |
+
"# with open(\n",
|
52 |
+
"# r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\fake_files.pkl\",\n",
|
53 |
+
"# \"rb\",\n",
|
54 |
+
"# ) as f:\n",
|
55 |
+
"# fake_files = pk.load(f)"
|
56 |
+
]
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"cell_type": "code",
|
60 |
+
"execution_count": 4,
|
61 |
+
"metadata": {},
|
62 |
+
"outputs": [],
|
63 |
+
"source": [
|
64 |
+
"# len(real_files), len(fake_files)"
|
65 |
+
]
|
66 |
+
},
|
67 |
+
{
|
68 |
+
"cell_type": "code",
|
69 |
+
"execution_count": 5,
|
70 |
+
"metadata": {},
|
71 |
+
"outputs": [],
|
72 |
+
"source": [
|
73 |
+
"# real_files = real_files[:2000]\n",
|
74 |
+
"# fake_files = fake_files[:2000]"
|
75 |
+
]
|
76 |
+
},
|
77 |
+
{
|
78 |
+
"cell_type": "code",
|
79 |
+
"execution_count": 6,
|
80 |
+
"metadata": {},
|
81 |
+
"outputs": [],
|
82 |
+
"source": [
|
83 |
+
"# fake_files = fake_files[: len(real_files)]"
|
84 |
+
]
|
85 |
+
},
|
86 |
+
{
|
87 |
+
"cell_type": "code",
|
88 |
+
"execution_count": 7,
|
89 |
+
"metadata": {},
|
90 |
+
"outputs": [],
|
91 |
+
"source": [
|
92 |
+
"# len(real_files), len(fake_files)"
|
93 |
+
]
|
94 |
+
},
|
95 |
+
{
|
96 |
+
"cell_type": "code",
|
97 |
+
"execution_count": 8,
|
98 |
+
"metadata": {},
|
99 |
+
"outputs": [],
|
100 |
+
"source": [
|
101 |
+
"# def extract_features(file_path):\n",
|
102 |
+
"# try:\n",
|
103 |
+
"# # Load the video file\n",
|
104 |
+
"# video_clip = VideoFileClip(file_path)\n",
|
105 |
+
"# audio = video_clip.audio\n",
|
106 |
+
"# fps = audio.fps\n",
|
107 |
+
"# audio_samples = np.array(\n",
|
108 |
+
"# list(audio.iter_frames(fps=fps, dtype=\"float32\"))\n",
|
109 |
+
"# ).flatten()\n",
|
110 |
+
"# buffer = io.BytesIO()\n",
|
111 |
+
"# sf.write(buffer, audio_samples, fps, format=\"wav\")\n",
|
112 |
+
"# buffer.seek(0)\n",
|
113 |
+
"# x, sr = librosa.load(buffer, sr=None)\n",
|
114 |
+
"# mfccs = librosa.feature.mfcc(y=x, sr=sr, n_mfcc=20)\n",
|
115 |
+
"\n",
|
116 |
+
"# return mfccs\n",
|
117 |
+
"\n",
|
118 |
+
"# except Exception as e:\n",
|
119 |
+
"# print(f\"Error encountered while parsing file: {file_path}, {e}\")\n",
|
120 |
+
"# return None\n",
|
121 |
+
"\n",
|
122 |
+
"\n",
|
123 |
+
"# def load_data(real_dir, fake_dir):\n",
|
124 |
+
"# labels = []\n",
|
125 |
+
"# features = []\n",
|
126 |
+
"\n",
|
127 |
+
"# # Load real audios\n",
|
128 |
+
"# for file_name in real_files:\n",
|
129 |
+
"# file_path = os.path.join(real_dir, file_name)\n",
|
130 |
+
"# mfccs = extract_features(file_path)\n",
|
131 |
+
"# if mfccs is not None:\n",
|
132 |
+
"# features.append(mfccs)\n",
|
133 |
+
"# labels.append(0) # 0 for REAL\n",
|
134 |
+
"\n",
|
135 |
+
"# # Load fake audios\n",
|
136 |
+
"# for file_name in fake_files:\n",
|
137 |
+
"# file_path = os.path.join(fake_dir, file_name)\n",
|
138 |
+
"# mfccs = extract_features(file_path)\n",
|
139 |
+
"# if mfccs is not None:\n",
|
140 |
+
"# features.append(mfccs)\n",
|
141 |
+
"# labels.append(1) # 1 for FAKE\n",
|
142 |
+
"\n",
|
143 |
+
"# return np.array(features), np.array(labels)"
|
144 |
+
]
|
145 |
+
},
|
146 |
+
{
|
147 |
+
"cell_type": "code",
|
148 |
+
"execution_count": 9,
|
149 |
+
"metadata": {},
|
150 |
+
"outputs": [],
|
151 |
+
"source": [
|
152 |
+
"# def extract_frame_features(file_path, frame_duration=1.0):\n",
|
153 |
+
"# try:\n",
|
154 |
+
"# video_clip = VideoFileClip(file_path)\n",
|
155 |
+
"# audio = video_clip.audio\n",
|
156 |
+
"# fps = audio.fps\n",
|
157 |
+
"# audio_samples = np.array(\n",
|
158 |
+
"# list(audio.iter_frames(fps=fps, dtype=\"float32\"))\n",
|
159 |
+
"# ).flatten()\n",
|
160 |
+
"# buffer = io.BytesIO()\n",
|
161 |
+
"# sf.write(buffer, audio_samples, fps, format=\"wav\")\n",
|
162 |
+
"# buffer.seek(0)\n",
|
163 |
+
"# x, sr = librosa.load(buffer, sr=None)\n",
|
164 |
+
"\n",
|
165 |
+
"# # Split audio into frames of 'frame_duration' seconds\n",
|
166 |
+
"# frame_length = int(frame_duration * sr)\n",
|
167 |
+
"# frames = [\n",
|
168 |
+
"# librosa.feature.mfcc(y=x[i : i + frame_length], sr=sr, n_mfcc=20)\n",
|
169 |
+
"# for i in range(0, len(x), frame_length)\n",
|
170 |
+
"# if i + frame_length <= len(x)\n",
|
171 |
+
"# ]\n",
|
172 |
+
"\n",
|
173 |
+
"# return frames # Returns list of MFCCs for each frame\n",
|
174 |
+
"\n",
|
175 |
+
"# except Exception as e:\n",
|
176 |
+
"# print(f\"Error processing file {file_path}: {e}\")\n",
|
177 |
+
"# return None"
|
178 |
+
]
|
179 |
+
},
|
180 |
+
{
|
181 |
+
"cell_type": "code",
|
182 |
+
"execution_count": 10,
|
183 |
+
"metadata": {},
|
184 |
+
"outputs": [],
|
185 |
+
"source": [
|
186 |
+
"def extract_frame_features(file_path, frame_duration=1.0):\n",
|
187 |
+
" video_clip = VideoFileClip(file_path)\n",
|
188 |
+
" audio = video_clip.audio\n",
|
189 |
+
" fps = audio.fps\n",
|
190 |
+
" audio_samples = np.array(\n",
|
191 |
+
" list(audio.iter_frames(fps=fps, dtype=\"float32\"))\n",
|
192 |
+
" ).flatten()\n",
|
193 |
+
" buffer = io.BytesIO()\n",
|
194 |
+
" sf.write(buffer, audio_samples, fps, format=\"wav\")\n",
|
195 |
+
" buffer.seek(0)\n",
|
196 |
+
" x, sr = librosa.load(buffer, sr=None)\n",
|
197 |
+
"\n",
|
198 |
+
" # Split audio into frames of 'frame_duration' seconds\n",
|
199 |
+
" frame_length = int(frame_duration * sr)\n",
|
200 |
+
" frames = []\n",
|
201 |
+
" timestamps = []\n",
|
202 |
+
"\n",
|
203 |
+
" for i in range(0, len(x), frame_length):\n",
|
204 |
+
" if i + frame_length <= len(x):\n",
|
205 |
+
" # Extract MFCCs for each frame and store the timestamp\n",
|
206 |
+
" frame_mfcc = librosa.feature.mfcc(y=x[i: i + frame_length], sr=sr, n_mfcc=20)\n",
|
207 |
+
" frames.append(frame_mfcc)\n",
|
208 |
+
" timestamp = i / sr # Convert index to seconds\n",
|
209 |
+
" timestamps.append(timestamp)\n",
|
210 |
+
"\n",
|
211 |
+
" return frames, timestamps"
|
212 |
+
]
|
213 |
+
},
|
214 |
+
{
|
215 |
+
"cell_type": "code",
|
216 |
+
"execution_count": 11,
|
217 |
+
"metadata": {},
|
218 |
+
"outputs": [],
|
219 |
+
"source": [
|
220 |
+
"# def load_data(real_dir, fake_dir, real_files, fake_files):\n",
|
221 |
+
"# labels, features = [], []\n",
|
222 |
+
"\n",
|
223 |
+
"# # Load real audio frames with progress bar\n",
|
224 |
+
"# print(\"Loading real audio files:\")\n",
|
225 |
+
"# for file_name in tqdm(real_files, desc=\"Processing Real Files\"):\n",
|
226 |
+
"# file_path = os.path.join(real_dir, file_name)\n",
|
227 |
+
"# frame_features, timestamps = extract_frame_features(file_path)\n",
|
228 |
+
"# if frame_features:\n",
|
229 |
+
"# features.extend(frame_features)\n",
|
230 |
+
"# labels.extend([0] * len(frame_features)) # Label 0 for REAL\n",
|
231 |
+
"\n",
|
232 |
+
"# # Load fake audio frames with progress bar\n",
|
233 |
+
"# print(\"Loading fake audio files:\")\n",
|
234 |
+
"# for file_name in tqdm(fake_files, desc=\"Processing Fake Files\"):\n",
|
235 |
+
"# file_path = os.path.join(fake_dir, file_name)\n",
|
236 |
+
"# frame_features = extract_frame_features(file_path)\n",
|
237 |
+
"# if frame_features:\n",
|
238 |
+
"# features.extend(frame_features)\n",
|
239 |
+
"# labels.extend([1] * len(frame_features)) # Label 1 for FAKE\n",
|
240 |
+
"\n",
|
241 |
+
"# # Convert to numpy arrays\n",
|
242 |
+
"# features = np.array(features)\n",
|
243 |
+
"# labels = np.array(labels)\n",
|
244 |
+
"\n",
|
245 |
+
"# # Shuffle the data\n",
|
246 |
+
"# indices = np.arange(len(features))\n",
|
247 |
+
"# np.random.shuffle(indices)\n",
|
248 |
+
"# features = features[indices]\n",
|
249 |
+
"# labels = labels[indices]\n",
|
250 |
+
"\n",
|
251 |
+
"# return features, labels"
|
252 |
+
]
|
253 |
+
},
|
254 |
+
{
|
255 |
+
"cell_type": "code",
|
256 |
+
"execution_count": 12,
|
257 |
+
"metadata": {},
|
258 |
+
"outputs": [],
|
259 |
+
"source": [
|
260 |
+
"# X, y = load_data(real_audio_dir, fake_audio_dir, real_files, fake_files)\n",
|
261 |
+
"# X = X[..., np.newaxis]"
|
262 |
+
]
|
263 |
+
},
|
264 |
+
{
|
265 |
+
"cell_type": "code",
|
266 |
+
"execution_count": 13,
|
267 |
+
"metadata": {},
|
268 |
+
"outputs": [],
|
269 |
+
"source": [
|
270 |
+
"# with open(\"X_for_dl_2000.pkl\", \"wb\") as f:\n",
|
271 |
+
"# pk.dump(X, f)\n",
|
272 |
+
"# with open(\"y_for_dl_2000.pkl\", \"wb\") as f:\n",
|
273 |
+
"# pk.dump(y, f)"
|
274 |
+
]
|
275 |
+
},
|
276 |
+
{
|
277 |
+
"cell_type": "code",
|
278 |
+
"execution_count": 14,
|
279 |
+
"metadata": {},
|
280 |
+
"outputs": [],
|
281 |
+
"source": [
|
282 |
+
"with open(\"X_for_dl_2000.pkl\", \"rb\") as f:\n",
|
283 |
+
" X = pk.load(f)\n",
|
284 |
+
"with open(\"y_for_dl_2000.pkl\", \"rb\") as f:\n",
|
285 |
+
" y = pk.load(f)"
|
286 |
+
]
|
287 |
+
},
|
288 |
+
{
|
289 |
+
"cell_type": "code",
|
290 |
+
"execution_count": 15,
|
291 |
+
"metadata": {},
|
292 |
+
"outputs": [],
|
293 |
+
"source": [
|
294 |
+
"X_train, X_test, y_train, y_test = train_test_split(\n",
|
295 |
+
" X, y, test_size=0.2, random_state=30\n",
|
296 |
+
")"
|
297 |
+
]
|
298 |
+
},
|
299 |
+
{
|
300 |
+
"cell_type": "markdown",
|
301 |
+
"metadata": {},
|
302 |
+
"source": [
|
303 |
+
"## TCN"
|
304 |
+
]
|
305 |
+
},
|
306 |
+
{
|
307 |
+
"cell_type": "code",
|
308 |
+
"execution_count": 16,
|
309 |
+
"metadata": {},
|
310 |
+
"outputs": [],
|
311 |
+
"source": [
|
312 |
+
"# model = models.Sequential(\n",
|
313 |
+
"# [\n",
|
314 |
+
"# layers.Conv1D(\n",
|
315 |
+
"# 64,\n",
|
316 |
+
"# kernel_size=3,\n",
|
317 |
+
"# dilation_rate=1,\n",
|
318 |
+
"# padding=\"causal\",\n",
|
319 |
+
"# activation=\"relu\",\n",
|
320 |
+
"# input_shape=(X.shape[1], X.shape[2]),\n",
|
321 |
+
"# ),\n",
|
322 |
+
"# layers.Conv1D(\n",
|
323 |
+
"# 128, kernel_size=3, dilation_rate=2, padding=\"causal\", activation=\"relu\"\n",
|
324 |
+
"# ),\n",
|
325 |
+
"# layers.Conv1D(\n",
|
326 |
+
"# 256, kernel_size=3, dilation_rate=4, padding=\"causal\", activation=\"relu\"\n",
|
327 |
+
"# ),\n",
|
328 |
+
"# layers.GlobalAveragePooling1D(),\n",
|
329 |
+
"# layers.Dropout(0.5),\n",
|
330 |
+
"# layers.Dense(64, activation=\"relu\"),\n",
|
331 |
+
"# layers.Dense(2, activation=\"softmax\"),\n",
|
332 |
+
"# ]\n",
|
333 |
+
"# )"
|
334 |
+
]
|
335 |
+
},
|
336 |
+
{
|
337 |
+
"cell_type": "code",
|
338 |
+
"execution_count": 17,
|
339 |
+
"metadata": {},
|
340 |
+
"outputs": [],
|
341 |
+
"source": [
|
342 |
+
"from tensorflow.keras import models, layers\n",
|
343 |
+
"\n",
|
344 |
+
"model = models.Sequential(\n",
|
345 |
+
" [\n",
|
346 |
+
" layers.Conv1D(\n",
|
347 |
+
" 64,\n",
|
348 |
+
" kernel_size=3,\n",
|
349 |
+
" dilation_rate=1,\n",
|
350 |
+
" padding=\"causal\",\n",
|
351 |
+
" activation=\"relu\",\n",
|
352 |
+
" input_shape=(X.shape[1], X.shape[2]),\n",
|
353 |
+
" ),\n",
|
354 |
+
" layers.BatchNormalization(),\n",
|
355 |
+
" layers.Conv1D(\n",
|
356 |
+
" 128, kernel_size=3, dilation_rate=2, padding=\"causal\", activation=\"relu\"\n",
|
357 |
+
" ),\n",
|
358 |
+
" layers.BatchNormalization(),\n",
|
359 |
+
" layers.Conv1D(\n",
|
360 |
+
" 256, kernel_size=3, dilation_rate=4, padding=\"causal\", activation=\"relu\"\n",
|
361 |
+
" ),\n",
|
362 |
+
" layers.BatchNormalization(),\n",
|
363 |
+
" layers.GlobalAveragePooling1D(),\n",
|
364 |
+
" layers.Dropout(0.5),\n",
|
365 |
+
" layers.Dense(128, activation=\"relu\"),\n",
|
366 |
+
" layers.Dropout(0.3),\n",
|
367 |
+
" layers.Dense(2, activation=\"softmax\"),\n",
|
368 |
+
" ]\n",
|
369 |
+
")"
|
370 |
+
]
|
371 |
+
},
|
372 |
+
{
|
373 |
+
"cell_type": "code",
|
374 |
+
"execution_count": 18,
|
375 |
+
"metadata": {},
|
376 |
+
"outputs": [],
|
377 |
+
"source": [
|
378 |
+
"model.compile(\n",
|
379 |
+
" optimizer=\"adam\", loss=\"sparse_categorical_crossentropy\", metrics=[\"accuracy\"]\n",
|
380 |
+
")"
|
381 |
+
]
|
382 |
+
},
|
383 |
+
{
|
384 |
+
"cell_type": "code",
|
385 |
+
"execution_count": 19,
|
386 |
+
"metadata": {},
|
387 |
+
"outputs": [],
|
388 |
+
"source": [
|
389 |
+
"checkpoint = ModelCheckpoint(\n",
|
390 |
+
" \"model/best_model.keras\", monitor=\"val_loss\", save_best_only=True\n",
|
391 |
+
")\n",
|
392 |
+
"early_stopping = EarlyStopping(monitor=\"val_loss\", patience=3)"
|
393 |
+
]
|
394 |
+
},
|
395 |
+
{
|
396 |
+
"cell_type": "code",
|
397 |
+
"execution_count": 20,
|
398 |
+
"metadata": {},
|
399 |
+
"outputs": [
|
400 |
+
{
|
401 |
+
"data": {
|
402 |
+
"text/html": [
|
403 |
+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">Model: \"sequential\"</span>\n",
|
404 |
+
"</pre>\n"
|
405 |
+
],
|
406 |
+
"text/plain": [
|
407 |
+
"\u001b[1mModel: \"sequential\"\u001b[0m\n"
|
408 |
+
]
|
409 |
+
},
|
410 |
+
"metadata": {},
|
411 |
+
"output_type": "display_data"
|
412 |
+
},
|
413 |
+
{
|
414 |
+
"data": {
|
415 |
+
"text/html": [
|
416 |
+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\n",
|
417 |
+
"┃<span style=\"font-weight: bold\"> Layer (type) </span>┃<span style=\"font-weight: bold\"> Output Shape </span>┃<span style=\"font-weight: bold\"> Param # </span>┃\n",
|
418 |
+
"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\n",
|
419 |
+
"│ conv1d (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Conv1D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">20</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">64</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">16,768</span> │\n",
|
420 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
421 |
+
"│ batch_normalization │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">20</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">64</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span> │\n",
|
422 |
+
"│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
|
423 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
424 |
+
"│ conv1d_1 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Conv1D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">20</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">128</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">24,704</span> │\n",
|
425 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
426 |
+
"│ batch_normalization_1 │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">20</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">128</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">512</span> │\n",
|
427 |
+
"│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
|
428 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
429 |
+
"│ conv1d_2 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Conv1D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">20</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">98,560</span> │\n",
|
430 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
431 |
+
"│ batch_normalization_2 │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">20</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">1,024</span> │\n",
|
432 |
+
"│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
|
433 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
434 |
+
"│ global_average_pooling1d │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
|
435 |
+
"│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">GlobalAveragePooling1D</span>) │ │ │\n",
|
436 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
437 |
+
"│ dropout (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dropout</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
|
438 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
439 |
+
"│ dense (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">128</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">32,896</span> │\n",
|
440 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
441 |
+
"│ dropout_1 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dropout</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">128</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
|
442 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
443 |
+
"│ dense_1 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">2</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">258</span> │\n",
|
444 |
+
"└─────────────────────────────────┴────────────────────────┴───────────────┘\n",
|
445 |
+
"</pre>\n"
|
446 |
+
],
|
447 |
+
"text/plain": [
|
448 |
+
"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\n",
|
449 |
+
"┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\n",
|
450 |
+
"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\n",
|
451 |
+
"│ conv1d (\u001b[38;5;33mConv1D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m20\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m16,768\u001b[0m │\n",
|
452 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
453 |
+
"│ batch_normalization │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m20\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m256\u001b[0m │\n",
|
454 |
+
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
|
455 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
456 |
+
"│ conv1d_1 (\u001b[38;5;33mConv1D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m20\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m24,704\u001b[0m │\n",
|
457 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
458 |
+
"│ batch_normalization_1 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m20\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m512\u001b[0m │\n",
|
459 |
+
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
|
460 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
461 |
+
"│ conv1d_2 (\u001b[38;5;33mConv1D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m20\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m98,560\u001b[0m │\n",
|
462 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
463 |
+
"│ batch_normalization_2 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m20\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,024\u001b[0m │\n",
|
464 |
+
"│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
|
465 |
+
"├──────���──────────────────────────┼────────────────────────┼───────────────┤\n",
|
466 |
+
"│ global_average_pooling1d │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
|
467 |
+
"│ (\u001b[38;5;33mGlobalAveragePooling1D\u001b[0m) │ │ │\n",
|
468 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
469 |
+
"│ dropout (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
|
470 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
471 |
+
"│ dense (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m32,896\u001b[0m │\n",
|
472 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
473 |
+
"│ dropout_1 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
|
474 |
+
"├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
|
475 |
+
"│ dense_1 (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2\u001b[0m) │ \u001b[38;5;34m258\u001b[0m │\n",
|
476 |
+
"└─────────────────────────────────┴────────────────────────┴───────────────┘\n"
|
477 |
+
]
|
478 |
+
},
|
479 |
+
"metadata": {},
|
480 |
+
"output_type": "display_data"
|
481 |
+
},
|
482 |
+
{
|
483 |
+
"data": {
|
484 |
+
"text/html": [
|
485 |
+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Total params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">174,978</span> (683.51 KB)\n",
|
486 |
+
"</pre>\n"
|
487 |
+
],
|
488 |
+
"text/plain": [
|
489 |
+
"\u001b[1m Total params: \u001b[0m\u001b[38;5;34m174,978\u001b[0m (683.51 KB)\n"
|
490 |
+
]
|
491 |
+
},
|
492 |
+
"metadata": {},
|
493 |
+
"output_type": "display_data"
|
494 |
+
},
|
495 |
+
{
|
496 |
+
"data": {
|
497 |
+
"text/html": [
|
498 |
+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">174,082</span> (680.01 KB)\n",
|
499 |
+
"</pre>\n"
|
500 |
+
],
|
501 |
+
"text/plain": [
|
502 |
+
"\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m174,082\u001b[0m (680.01 KB)\n"
|
503 |
+
]
|
504 |
+
},
|
505 |
+
"metadata": {},
|
506 |
+
"output_type": "display_data"
|
507 |
+
},
|
508 |
+
{
|
509 |
+
"data": {
|
510 |
+
"text/html": [
|
511 |
+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Non-trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">896</span> (3.50 KB)\n",
|
512 |
+
"</pre>\n"
|
513 |
+
],
|
514 |
+
"text/plain": [
|
515 |
+
"\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m896\u001b[0m (3.50 KB)\n"
|
516 |
+
]
|
517 |
+
},
|
518 |
+
"metadata": {},
|
519 |
+
"output_type": "display_data"
|
520 |
+
}
|
521 |
+
],
|
522 |
+
"source": [
|
523 |
+
"model.summary()"
|
524 |
+
]
|
525 |
+
},
|
526 |
+
{
|
527 |
+
"cell_type": "code",
|
528 |
+
"execution_count": 21,
|
529 |
+
"metadata": {},
|
530 |
+
"outputs": [
|
531 |
+
{
|
532 |
+
"name": "stdout",
|
533 |
+
"output_type": "stream",
|
534 |
+
"text": [
|
535 |
+
"Epoch 1/50\n",
|
536 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m18s\u001b[0m 4ms/step - accuracy: 0.6385 - loss: 0.6350 - val_accuracy: 0.6710 - val_loss: 0.6011\n",
|
537 |
+
"Epoch 2/50\n",
|
538 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m17s\u001b[0m 4ms/step - accuracy: 0.6680 - loss: 0.6062 - val_accuracy: 0.6838 - val_loss: 0.5800\n",
|
539 |
+
"Epoch 3/50\n",
|
540 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━��━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m16s\u001b[0m 4ms/step - accuracy: 0.6856 - loss: 0.5882 - val_accuracy: 0.7069 - val_loss: 0.5591\n",
|
541 |
+
"Epoch 4/50\n",
|
542 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.6969 - loss: 0.5731 - val_accuracy: 0.7187 - val_loss: 0.5497\n",
|
543 |
+
"Epoch 5/50\n",
|
544 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7038 - loss: 0.5649 - val_accuracy: 0.7303 - val_loss: 0.5353\n",
|
545 |
+
"Epoch 6/50\n",
|
546 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7127 - loss: 0.5569 - val_accuracy: 0.7343 - val_loss: 0.5330\n",
|
547 |
+
"Epoch 7/50\n",
|
548 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7198 - loss: 0.5478 - val_accuracy: 0.7102 - val_loss: 0.5598\n",
|
549 |
+
"Epoch 8/50\n",
|
550 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7239 - loss: 0.5452 - val_accuracy: 0.7404 - val_loss: 0.5247\n",
|
551 |
+
"Epoch 9/50\n",
|
552 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7271 - loss: 0.5389 - val_accuracy: 0.7310 - val_loss: 0.5310\n",
|
553 |
+
"Epoch 10/50\n",
|
554 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7301 - loss: 0.5323 - val_accuracy: 0.7369 - val_loss: 0.5335\n",
|
555 |
+
"Epoch 11/50\n",
|
556 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7358 - loss: 0.5272 - val_accuracy: 0.7529 - val_loss: 0.5058\n",
|
557 |
+
"Epoch 12/50\n",
|
558 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7363 - loss: 0.5263 - val_accuracy: 0.7451 - val_loss: 0.5065\n",
|
559 |
+
"Epoch 13/50\n",
|
560 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m14s\u001b[0m 4ms/step - accuracy: 0.7379 - loss: 0.5212 - val_accuracy: 0.7451 - val_loss: 0.5055\n",
|
561 |
+
"Epoch 14/50\n",
|
562 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7454 - loss: 0.5105 - val_accuracy: 0.7447 - val_loss: 0.5048\n",
|
563 |
+
"Epoch 15/50\n",
|
564 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7478 - loss: 0.5100 - val_accuracy: 0.7554 - val_loss: 0.4946\n",
|
565 |
+
"Epoch 16/50\n",
|
566 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7442 - loss: 0.5087 - val_accuracy: 0.7533 - val_loss: 0.5004\n",
|
567 |
+
"Epoch 17/50\n",
|
568 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m14s\u001b[0m 4ms/step - accuracy: 0.7513 - loss: 0.5005 - val_accuracy: 0.7469 - val_loss: 0.5045\n",
|
569 |
+
"Epoch 18/50\n",
|
570 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m14s\u001b[0m 4ms/step - accuracy: 0.7507 - loss: 0.4992 - val_accuracy: 0.7519 - val_loss: 0.4980\n",
|
571 |
+
"Epoch 19/50\n",
|
572 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m14s\u001b[0m 4ms/step - accuracy: 0.7528 - loss: 0.4976 - val_accuracy: 0.7553 - val_loss: 0.4930\n",
|
573 |
+
"Epoch 20/50\n",
|
574 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7582 - loss: 0.4947 - val_accuracy: 0.7637 - val_loss: 0.4833\n",
|
575 |
+
"Epoch 21/50\n",
|
576 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7561 - loss: 0.4986 - val_accuracy: 0.7668 - val_loss: 0.4831\n",
|
577 |
+
"Epoch 22/50\n",
|
578 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m���━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7593 - loss: 0.4891 - val_accuracy: 0.7671 - val_loss: 0.4819\n",
|
579 |
+
"Epoch 23/50\n",
|
580 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m14s\u001b[0m 4ms/step - accuracy: 0.7578 - loss: 0.4900 - val_accuracy: 0.7671 - val_loss: 0.4808\n",
|
581 |
+
"Epoch 24/50\n",
|
582 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7628 - loss: 0.4851 - val_accuracy: 0.7586 - val_loss: 0.5014\n",
|
583 |
+
"Epoch 25/50\n",
|
584 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m14s\u001b[0m 4ms/step - accuracy: 0.7609 - loss: 0.4850 - val_accuracy: 0.7563 - val_loss: 0.4884\n",
|
585 |
+
"Epoch 26/50\n",
|
586 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7647 - loss: 0.4826 - val_accuracy: 0.7679 - val_loss: 0.4788\n",
|
587 |
+
"Epoch 27/50\n",
|
588 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7623 - loss: 0.4848 - val_accuracy: 0.7476 - val_loss: 0.5020\n",
|
589 |
+
"Epoch 28/50\n",
|
590 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7665 - loss: 0.4792 - val_accuracy: 0.7659 - val_loss: 0.4835\n",
|
591 |
+
"Epoch 29/50\n",
|
592 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7658 - loss: 0.4796 - val_accuracy: 0.7688 - val_loss: 0.4923\n",
|
593 |
+
"Epoch 30/50\n",
|
594 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7688 - loss: 0.4759 - val_accuracy: 0.7709 - val_loss: 0.4781\n",
|
595 |
+
"Epoch 31/50\n",
|
596 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7702 - loss: 0.4755 - val_accuracy: 0.7553 - val_loss: 0.4968\n",
|
597 |
+
"Epoch 32/50\n",
|
598 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7703 - loss: 0.4728 - val_accuracy: 0.7692 - val_loss: 0.4744\n",
|
599 |
+
"Epoch 33/50\n",
|
600 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7703 - loss: 0.4716 - val_accuracy: 0.7613 - val_loss: 0.4869\n",
|
601 |
+
"Epoch 34/50\n",
|
602 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7728 - loss: 0.4707 - val_accuracy: 0.7648 - val_loss: 0.4952\n",
|
603 |
+
"Epoch 35/50\n",
|
604 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7699 - loss: 0.4720 - val_accuracy: 0.7648 - val_loss: 0.4968\n",
|
605 |
+
"Epoch 36/50\n",
|
606 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7727 - loss: 0.4688 - val_accuracy: 0.7643 - val_loss: 0.5095\n",
|
607 |
+
"Epoch 37/50\n",
|
608 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7730 - loss: 0.4670 - val_accuracy: 0.7674 - val_loss: 0.4827\n",
|
609 |
+
"Epoch 38/50\n",
|
610 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7749 - loss: 0.4659 - val_accuracy: 0.7728 - val_loss: 0.4697\n",
|
611 |
+
"Epoch 39/50\n",
|
612 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m16s\u001b[0m 4ms/step - accuracy: 0.7772 - loss: 0.4618 - val_accuracy: 0.7753 - val_loss: 0.4774\n",
|
613 |
+
"Epoch 40/50\n",
|
614 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m16s\u001b[0m 4ms/step - accuracy: 0.7795 - loss: 0.4587 - val_accuracy: 0.7663 - val_loss: 0.4824\n",
|
615 |
+
"Epoch 41/50\n",
|
616 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m18s\u001b[0m 5ms/step - accuracy: 0.7765 - loss: 0.4638 - val_accuracy: 0.7561 - val_loss: 0.4910\n",
|
617 |
+
"Epoch 42/50\n",
|
618 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m18s\u001b[0m 4ms/step - accuracy: 0.7768 - loss: 0.4616 - val_accuracy: 0.7749 - val_loss: 0.4737\n",
|
619 |
+
"Epoch 43/50\n",
|
620 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m20s\u001b[0m 5ms/step - accuracy: 0.7800 - loss: 0.4554 - val_accuracy: 0.7698 - val_loss: 0.4747\n",
|
621 |
+
"Epoch 44/50\n",
|
622 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m20s\u001b[0m 5ms/step - accuracy: 0.7816 - loss: 0.4528 - val_accuracy: 0.7476 - val_loss: 0.4988\n",
|
623 |
+
"Epoch 45/50\n",
|
624 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m20s\u001b[0m 5ms/step - accuracy: 0.7819 - loss: 0.4553 - val_accuracy: 0.7630 - val_loss: 0.4820\n",
|
625 |
+
"Epoch 46/50\n",
|
626 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m20s\u001b[0m 5ms/step - accuracy: 0.7780 - loss: 0.4587 - val_accuracy: 0.7554 - val_loss: 0.4887\n",
|
627 |
+
"Epoch 47/50\n",
|
628 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m20s\u001b[0m 5ms/step - accuracy: 0.7832 - loss: 0.4555 - val_accuracy: 0.7773 - val_loss: 0.4709\n",
|
629 |
+
"Epoch 48/50\n",
|
630 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m21s\u001b[0m 5ms/step - accuracy: 0.7831 - loss: 0.4511 - val_accuracy: 0.7667 - val_loss: 0.4760\n",
|
631 |
+
"Epoch 49/50\n",
|
632 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m17s\u001b[0m 4ms/step - accuracy: 0.7831 - loss: 0.4513 - val_accuracy: 0.7731 - val_loss: 0.4812\n",
|
633 |
+
"Epoch 50/50\n",
|
634 |
+
"\u001b[1m3998/3998\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m15s\u001b[0m 4ms/step - accuracy: 0.7837 - loss: 0.4550 - val_accuracy: 0.7775 - val_loss: 0.4859\n"
|
635 |
+
]
|
636 |
+
}
|
637 |
+
],
|
638 |
+
"source": [
|
639 |
+
"history = model.fit(\n",
|
640 |
+
" X_train,\n",
|
641 |
+
" y_train,\n",
|
642 |
+
" epochs=50,\n",
|
643 |
+
" batch_size=16,\n",
|
644 |
+
" validation_data=(X_test, y_test),\n",
|
645 |
+
" callbacks=[checkpoint],\n",
|
646 |
+
")"
|
647 |
+
]
|
648 |
+
},
|
649 |
+
{
|
650 |
+
"cell_type": "code",
|
651 |
+
"execution_count": null,
|
652 |
+
"metadata": {},
|
653 |
+
"outputs": [],
|
654 |
+
"source": [
|
655 |
+
"model = tf.keras.models.load_model(\"model/TCN.keras\")"
|
656 |
+
]
|
657 |
+
},
|
658 |
+
{
|
659 |
+
"cell_type": "code",
|
660 |
+
"execution_count": 36,
|
661 |
+
"metadata": {},
|
662 |
+
"outputs": [
|
663 |
+
{
|
664 |
+
"name": "stdout",
|
665 |
+
"output_type": "stream",
|
666 |
+
"text": [
|
667 |
+
"\u001b[1m500/500\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 2ms/step\n",
|
668 |
+
" precision recall f1-score support\n",
|
669 |
+
"\n",
|
670 |
+
" REAL 0.89 0.62 0.73 7920\n",
|
671 |
+
" FAKE 0.71 0.92 0.80 8072\n",
|
672 |
+
"\n",
|
673 |
+
" accuracy 0.77 15992\n",
|
674 |
+
" macro avg 0.80 0.77 0.77 15992\n",
|
675 |
+
"weighted avg 0.80 0.77 0.77 15992\n",
|
676 |
+
"\n",
|
677 |
+
"[[4910 3010]\n",
|
678 |
+
" [ 623 7449]]\n"
|
679 |
+
]
|
680 |
+
}
|
681 |
+
],
|
682 |
+
"source": [
|
683 |
+
"# model = tf.keras.models.load_model(\"model/best_model.keras\")\n",
|
684 |
+
"y_pred = model.predict(X_test)\n",
|
685 |
+
"y_pred_labels = np.argmax(y_pred, axis=1)\n",
|
686 |
+
"\n",
|
687 |
+
"# Print classification report\n",
|
688 |
+
"print(classification_report(y_test, y_pred_labels, target_names=[\"REAL\", \"FAKE\"]))\n",
|
689 |
+
"print(confusion_matrix(y_test, y_pred_labels))"
|
690 |
+
]
|
691 |
+
},
|
692 |
+
{
|
693 |
+
"cell_type": "code",
|
694 |
+
"execution_count": 37,
|
695 |
+
"metadata": {},
|
696 |
+
"outputs": [
|
697 |
+
{
|
698 |
+
"name": "stdout",
|
699 |
+
"output_type": "stream",
|
700 |
+
"text": [
|
701 |
+
"\u001b[1m1/1\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 169ms/step\n",
|
702 |
+
"Found 8 deepfake frames:\n",
|
703 |
+
"Frame 1 at 0.00s: FAKE\n",
|
704 |
+
"Frame 2 at 1.00s: FAKE\n",
|
705 |
+
"Frame 3 at 2.00s: FAKE\n",
|
706 |
+
"Frame 4 at 3.00s: FAKE\n",
|
707 |
+
"Frame 5 at 4.00s: FAKE\n",
|
708 |
+
"Frame 8 at 7.00s: FAKE\n",
|
709 |
+
"Frame 11 at 10.00s: FAKE\n",
|
710 |
+
"Frame 15 at 14.00s: FAKE\n"
|
711 |
+
]
|
712 |
+
}
|
713 |
+
],
|
714 |
+
"source": [
|
715 |
+
"def test_on_video(file_path, frame_duration=1.0):\n",
|
716 |
+
" # Load the trained model\n",
|
717 |
+
" model = tf.keras.models.load_model(\"model/TCN.keras\")\n",
|
718 |
+
"\n",
|
719 |
+
" # Extract features and timestamps for each frame in the new video\n",
|
720 |
+
" frames, timestamps = extract_frame_features(file_path, frame_duration)\n",
|
721 |
+
"\n",
|
722 |
+
" if frames is None or timestamps is None:\n",
|
723 |
+
" print(\"No frames extracted.\")\n",
|
724 |
+
" return\n",
|
725 |
+
"\n",
|
726 |
+
" # Reshape frames for model input\n",
|
727 |
+
" frames = np.array(frames)[..., np.newaxis]\n",
|
728 |
+
"\n",
|
729 |
+
" # Predict on each frame\n",
|
730 |
+
" predictions = model.predict(frames)\n",
|
731 |
+
" pred_labels = np.argmax(predictions, axis=1)\n",
|
732 |
+
"\n",
|
733 |
+
" # Store deepfake frames, their timestamps, and frame indices\n",
|
734 |
+
" deepfake_frames = []\n",
|
735 |
+
" deepfake_timestamps = []\n",
|
736 |
+
" deepfake_indices = []\n",
|
737 |
+
"\n",
|
738 |
+
" # Identify deepfake frames\n",
|
739 |
+
" for i, label in enumerate(pred_labels):\n",
|
740 |
+
" if label == 1: # If the label is FAKE\n",
|
741 |
+
" deepfake_frames.append(frames[i])\n",
|
742 |
+
" deepfake_timestamps.append(timestamps[i])\n",
|
743 |
+
" deepfake_indices.append(i)\n",
|
744 |
+
"\n",
|
745 |
+
" if not deepfake_frames:\n",
|
746 |
+
" print(\"No deepfake frames detected in the video.\")\n",
|
747 |
+
" return\n",
|
748 |
+
"\n",
|
749 |
+
" # Analyze deepfake frames\n",
|
750 |
+
" print(f\"Found {len(deepfake_frames)} deepfake frames:\")\n",
|
751 |
+
" for i, (timestamp, index) in enumerate(zip(deepfake_timestamps, deepfake_indices)):\n",
|
752 |
+
" print(f\"Frame {index + 1} at {timestamp:.2f}s: FAKE\")\n",
|
753 |
+
"\n",
|
754 |
+
"\n",
|
755 |
+
"# Example usage\n",
|
756 |
+
"test_video_path = r\"REAL\\ajqslcypsw.mp4\" # Replace with your test video path\n",
|
757 |
+
"test_on_video(test_video_path)"
|
758 |
+
]
|
759 |
+
},
|
760 |
+
{
|
761 |
+
"cell_type": "code",
|
762 |
+
"execution_count": 25,
|
763 |
+
"metadata": {},
|
764 |
+
"outputs": [],
|
765 |
+
"source": [
|
766 |
+
"# def test_on_video(file_path, frame_duration=1.0):\n",
|
767 |
+
"# # Load the trained model\n",
|
768 |
+
"# model = tf.keras.models.load_model(\"model/best_model.keras\")\n",
|
769 |
+
"\n",
|
770 |
+
"# # Extract features for each frame in the new video\n",
|
771 |
+
"# frames = extract_frame_features(file_path, frame_duration)\n",
|
772 |
+
"\n",
|
773 |
+
"# if frames is None:\n",
|
774 |
+
"# print(\"No frames extracted.\")\n",
|
775 |
+
"# return\n",
|
776 |
+
"\n",
|
777 |
+
"# # Reshape frames for model input\n",
|
778 |
+
"# frames = np.array(frames)[..., np.newaxis]\n",
|
779 |
+
"\n",
|
780 |
+
"# # Predict on each frame\n",
|
781 |
+
"# predictions = model.predict(frames)\n",
|
782 |
+
"# pred_labels = np.argmax(predictions, axis=1)\n",
|
783 |
+
"\n",
|
784 |
+
"# # Output results for each frame\n",
|
785 |
+
"# for i, label in enumerate(pred_labels):\n",
|
786 |
+
"# status = \"REAL\" if label == 0 else \"FAKE\"\n",
|
787 |
+
"# print(f\"Frame {i+1}: {status}\")\n",
|
788 |
+
"\n",
|
789 |
+
"\n",
|
790 |
+
"# # Example usage\n",
|
791 |
+
"# test_video_path = r\"REAL\\bddjdhzfze.mp4\" # Replace with your test video path\n",
|
792 |
+
"# test_on_video(test_video_path)"
|
793 |
+
]
|
794 |
+
},
|
795 |
+
{
|
796 |
+
"cell_type": "code",
|
797 |
+
"execution_count": 26,
|
798 |
+
"metadata": {},
|
799 |
+
"outputs": [],
|
800 |
+
"source": [
|
801 |
+
"# @register_keras_serializable()\n",
|
802 |
+
"# class AudioModel(tf.keras.Model):\n",
|
803 |
+
"# def __init__(self, input_shape):\n",
|
804 |
+
"# super(AudioModel, self).__init__()\n",
|
805 |
+
"# self.input_shape = input_shape # Store the input shape\n",
|
806 |
+
"# # Define the model layers\n",
|
807 |
+
"# self.conv1 = layers.Conv2D(\n",
|
808 |
+
"# 32, kernel_size=(3, 3), activation=\"relu\", input_shape=input_shape\n",
|
809 |
+
"# )\n",
|
810 |
+
"# self.conv2 = layers.Conv2D(64, kernel_size=(3, 3), activation=\"relu\")\n",
|
811 |
+
"# self.pool = layers.MaxPooling2D(pool_size=(2, 2))\n",
|
812 |
+
"# self.dropout1 = layers.Dropout(0.25)\n",
|
813 |
+
"\n",
|
814 |
+
"# self.reshape = layers.Reshape((64, -1))\n",
|
815 |
+
"# self.gru = layers.Bidirectional(layers.GRU(128, return_sequences=False))\n",
|
816 |
+
"\n",
|
817 |
+
"# self.dense1 = layers.Dense(128, activation=\"relu\")\n",
|
818 |
+
"# self.dropout2 = layers.Dropout(0.5)\n",
|
819 |
+
"# self.dense2 = layers.Dense(2, activation=\"softmax\")\n",
|
820 |
+
"\n",
|
821 |
+
"# def call(self, inputs):\n",
|
822 |
+
"# # Forward pass through the layers\n",
|
823 |
+
"# x = self.conv1(inputs)\n",
|
824 |
+
"# x = self.conv2(x)\n",
|
825 |
+
"# x = self.pool(x)\n",
|
826 |
+
"# x = self.dropout1(x)\n",
|
827 |
+
"\n",
|
828 |
+
"# x = self.reshape(x)\n",
|
829 |
+
"# x = self.gru(x)\n",
|
830 |
+
"\n",
|
831 |
+
"# x = self.dense1(x)\n",
|
832 |
+
"# x = self.dropout2(x)\n",
|
833 |
+
"# return self.dense2(x)\n",
|
834 |
+
"\n",
|
835 |
+
"# def get_config(self):\n",
|
836 |
+
"# config = super(AudioModel, self).get_config()\n",
|
837 |
+
"# config.update(\n",
|
838 |
+
"# {\"input_shape\": self.input_shape} # Include input shape in config\n",
|
839 |
+
"# )\n",
|
840 |
+
"# return config\n",
|
841 |
+
"\n",
|
842 |
+
"# @classmethod\n",
|
843 |
+
"# def from_config(cls, config):\n",
|
844 |
+
"# # Create a model instance from the config\n",
|
845 |
+
"# input_shape = config.pop(\"input_shape\") # Extract input_shape from config\n",
|
846 |
+
"# return cls(input_shape) # Create an instance of the model\n",
|
847 |
+
"\n",
|
848 |
+
"\n",
|
849 |
+
"# # Function to create and compile the model\n",
|
850 |
+
"# def create_model(input_shape):\n",
|
851 |
+
"# model = AudioModel(input_shape)\n",
|
852 |
+
"# model.compile(\n",
|
853 |
+
"# optimizer=\"adam\", loss=\"sparse_categorical_crossentropy\", metrics=[\"accuracy\"]\n",
|
854 |
+
"# )\n",
|
855 |
+
"# return model\n",
|
856 |
+
"\n",
|
857 |
+
"\n",
|
858 |
+
"# # Example usage\n",
|
859 |
+
"# input_shape = (\n",
|
860 |
+
"# 64,\n",
|
861 |
+
"# 40,\n",
|
862 |
+
"# 1,\n",
|
863 |
+
"# ) # Adjust based on your data (e.g., (n_mfccs, time_steps, channels))"
|
864 |
+
]
|
865 |
+
},
|
866 |
+
{
|
867 |
+
"cell_type": "code",
|
868 |
+
"execution_count": 27,
|
869 |
+
"metadata": {},
|
870 |
+
"outputs": [],
|
871 |
+
"source": [
|
872 |
+
"# model = create_model(input_shape)\n",
|
873 |
+
"# model.summary()"
|
874 |
+
]
|
875 |
+
},
|
876 |
+
{
|
877 |
+
"cell_type": "code",
|
878 |
+
"execution_count": 28,
|
879 |
+
"metadata": {},
|
880 |
+
"outputs": [],
|
881 |
+
"source": [
|
882 |
+
"# checkpoint = ModelCheckpoint(r\"models/dl_model.keras\", monitor=\"val_loss\", save_best_only=True, verbose=1)\n",
|
883 |
+
"# early_stopping = EarlyStopping(monitor=\"val_loss\", patience=5, verbose=1)\n",
|
884 |
+
"\n",
|
885 |
+
"# history = model.fit(\n",
|
886 |
+
"# X_train, y_train, epochs=10, batch_size=16, validation_data=(X_test, y_test), callbacks=[checkpoint, early_stopping]\n",
|
887 |
+
"# )"
|
888 |
+
]
|
889 |
+
},
|
890 |
+
{
|
891 |
+
"cell_type": "code",
|
892 |
+
"execution_count": 29,
|
893 |
+
"metadata": {},
|
894 |
+
"outputs": [],
|
895 |
+
"source": [
|
896 |
+
"# model.save(r\"models/dl_model.keras\", overwrite=True)\n",
|
897 |
+
"# print(\"Model saved successfully.\")"
|
898 |
+
]
|
899 |
+
},
|
900 |
+
{
|
901 |
+
"cell_type": "code",
|
902 |
+
"execution_count": 30,
|
903 |
+
"metadata": {},
|
904 |
+
"outputs": [],
|
905 |
+
"source": [
|
906 |
+
"# # Ensure to import keras properly\n",
|
907 |
+
"# import tensorflow as tf\n",
|
908 |
+
"# from tensorflow import keras\n",
|
909 |
+
"\n",
|
910 |
+
"\n",
|
911 |
+
"# # Function to load the model\n",
|
912 |
+
"# def load_model(model_path):\n",
|
913 |
+
"# try:\n",
|
914 |
+
"# # Load the model from the specified path\n",
|
915 |
+
"# model = keras.models.load_model(model_path)\n",
|
916 |
+
"# print(\"Model loaded successfully.\")\n",
|
917 |
+
"# return model\n",
|
918 |
+
"# except Exception as e:\n",
|
919 |
+
"# print(f\"Error loading model: {e}\")\n",
|
920 |
+
"# return None"
|
921 |
+
]
|
922 |
+
},
|
923 |
+
{
|
924 |
+
"cell_type": "code",
|
925 |
+
"execution_count": 31,
|
926 |
+
"metadata": {},
|
927 |
+
"outputs": [],
|
928 |
+
"source": [
|
929 |
+
"# model_path = r\"models/dl_model.keras\"\n",
|
930 |
+
"\n",
|
931 |
+
"# # Load the model\n",
|
932 |
+
"# loaded_model = load_model(model_path)"
|
933 |
+
]
|
934 |
+
}
|
935 |
+
],
|
936 |
+
"metadata": {
|
937 |
+
"kernelspec": {
|
938 |
+
"display_name": "Python 3",
|
939 |
+
"language": "python",
|
940 |
+
"name": "python3"
|
941 |
+
},
|
942 |
+
"language_info": {
|
943 |
+
"codemirror_mode": {
|
944 |
+
"name": "ipython",
|
945 |
+
"version": 3
|
946 |
+
},
|
947 |
+
"file_extension": ".py",
|
948 |
+
"mimetype": "text/x-python",
|
949 |
+
"name": "python",
|
950 |
+
"nbconvert_exporter": "python",
|
951 |
+
"pygments_lexer": "ipython3",
|
952 |
+
"version": "3.12.2"
|
953 |
+
}
|
954 |
+
},
|
955 |
+
"nbform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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {
|
7 |
+
"colab": {
|
8 |
+
"base_uri": "https://localhost:8080/"
|
9 |
+
},
|
10 |
+
"id": "H3eVgsMsJVRY",
|
11 |
+
"outputId": "30e4d553-6ce2-4b44-8217-21d0f1875d8b"
|
12 |
+
},
|
13 |
+
"outputs": [
|
14 |
+
{
|
15 |
+
"name": "stdout",
|
16 |
+
"output_type": "stream",
|
17 |
+
"text": [
|
18 |
+
"cuda\n"
|
19 |
+
]
|
20 |
+
}
|
21 |
+
],
|
22 |
+
"source": [
|
23 |
+
"import torch\n",
|
24 |
+
"import cupy as cp\n",
|
25 |
+
"from moviepy.editor import VideoFileClip\n",
|
26 |
+
"import pandas as pd\n",
|
27 |
+
"import librosa\n",
|
28 |
+
"import scipy.stats\n",
|
29 |
+
"import soundfile as sf\n",
|
30 |
+
"import io\n",
|
31 |
+
"import os\n",
|
32 |
+
"from tqdm import tqdm\n",
|
33 |
+
"import pickle as pk\n",
|
34 |
+
"\n",
|
35 |
+
"# Set device to GPU if available\n",
|
36 |
+
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
|
37 |
+
"print(device)"
|
38 |
+
]
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"cell_type": "markdown",
|
42 |
+
"metadata": {
|
43 |
+
"id": "3A9iF-QXJVRZ"
|
44 |
+
},
|
45 |
+
"source": [
|
46 |
+
"Statistical Features \n",
|
47 |
+
"A first easy step is to compute the mean, standard deviation, minimum, maximum, median and quartiles of the frequencies of each signal. This can be done using Numpy and it always brings value to our feature extraction."
|
48 |
+
]
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"cell_type": "code",
|
52 |
+
"execution_count": 2,
|
53 |
+
"metadata": {
|
54 |
+
"id": "ibnbShbMJVRa"
|
55 |
+
},
|
56 |
+
"outputs": [],
|
57 |
+
"source": [
|
58 |
+
"def describe_freq(freqs):\n",
|
59 |
+
" freqs = cp.array(freqs) # Convert to CuPy array for GPU computation\n",
|
60 |
+
" mean = cp.mean(freqs)\n",
|
61 |
+
" std = cp.std(freqs)\n",
|
62 |
+
" maxv = cp.amax(freqs)\n",
|
63 |
+
" minv = cp.amin(freqs)\n",
|
64 |
+
" median = cp.median(freqs)\n",
|
65 |
+
" skew = scipy.stats.skew(cp.asnumpy(freqs)) # Skew not directly supported in CuPy\n",
|
66 |
+
" kurt = scipy.stats.kurtosis(cp.asnumpy(freqs)) # Kurtosis not directly supported in CuPy\n",
|
67 |
+
" q1 = cp.quantile(freqs, 0.25)\n",
|
68 |
+
" q3 = cp.quantile(freqs, 0.75)\n",
|
69 |
+
" mode = scipy.stats.mode(cp.asnumpy(freqs))[0][0] # Mode not directly supported in CuPy\n",
|
70 |
+
" iqr = cp.subtract(q3, q1)\n",
|
71 |
+
"\n",
|
72 |
+
" return [mean.get(), std.get(), maxv.get(), minv.get(), median.get(), skew, kurt, q1.get(), q3.get(), mode, iqr.get()]"
|
73 |
+
]
|
74 |
+
},
|
75 |
+
{
|
76 |
+
"cell_type": "code",
|
77 |
+
"execution_count": 3,
|
78 |
+
"metadata": {
|
79 |
+
"id": "nNifSVyDJVRa"
|
80 |
+
},
|
81 |
+
"outputs": [],
|
82 |
+
"source": [
|
83 |
+
"def get_features(x, sr):\n",
|
84 |
+
" x = torch.tensor(x, device=device) # Send to GPU\n",
|
85 |
+
" rmse = torch.mean(torch.tensor(librosa.feature.rms(y=x.cpu().numpy())[0], device=device))\n",
|
86 |
+
" zcr = torch.mean(torch.tensor(librosa.feature.zero_crossing_rate(x.cpu().numpy())[0], device=device))\n",
|
87 |
+
" tempo = torch.tensor(librosa.beat.tempo(y=x.cpu().numpy(), sr=sr)[0], device=device)\n",
|
88 |
+
" mfcc = torch.mean(torch.tensor(librosa.feature.mfcc(y=x.cpu().numpy(), sr=sr), device=device), axis=1)\n",
|
89 |
+
" spec_cen = torch.mean(torch.tensor(librosa.feature.spectral_centroid(y=x.cpu().numpy(), sr=sr), device=device))\n",
|
90 |
+
" spectral_bandwidth = torch.mean(torch.tensor(librosa.feature.spectral_bandwidth(y=x.cpu().numpy(), sr=sr), device=device))\n",
|
91 |
+
" spectral_contrast = torch.mean(torch.tensor(librosa.feature.spectral_contrast(y=x.cpu().numpy(), sr=sr), device=device))\n",
|
92 |
+
" spectral_flatness = torch.mean(torch.tensor(librosa.feature.spectral_flatness(y=x.cpu().numpy()), device=device))\n",
|
93 |
+
" spectral_rolloff = torch.mean(torch.tensor(librosa.feature.spectral_rolloff(y=x.cpu().numpy(), sr=sr), device=device))\n",
|
94 |
+
"\n",
|
95 |
+
" features = [rmse, zcr, tempo, spec_cen, spectral_bandwidth, spectral_contrast, spectral_flatness, spectral_rolloff]\n",
|
96 |
+
" features = [f.item() for f in features] + [mfcc[i].item() for i in range(mfcc.size(0))] # Convert to list\n",
|
97 |
+
" return features"
|
98 |
+
]
|
99 |
+
},
|
100 |
+
{
|
101 |
+
"cell_type": "code",
|
102 |
+
"execution_count": 4,
|
103 |
+
"metadata": {
|
104 |
+
"id": "6p0CSM2I_qGY"
|
105 |
+
},
|
106 |
+
"outputs": [],
|
107 |
+
"source": [
|
108 |
+
"def extract_features(file_path):\n",
|
109 |
+
" try:\n",
|
110 |
+
" # Load video file\n",
|
111 |
+
" video_clip = VideoFileClip(file_path)\n",
|
112 |
+
" audio = video_clip.audio\n",
|
113 |
+
" fps = audio.fps\n",
|
114 |
+
" audio_samples = cp.array(list(audio.iter_frames(fps=fps, dtype=\"float32\"))).flatten()\n",
|
115 |
+
" buffer = io.BytesIO()\n",
|
116 |
+
" sf.write(buffer, cp.asnumpy(audio_samples), fps, format=\"wav\")\n",
|
117 |
+
" buffer.seek(0)\n",
|
118 |
+
" x, sr = librosa.load(buffer, sr=None)\n",
|
119 |
+
" video_clip.close()\n",
|
120 |
+
" features = get_features(x, sr)\n",
|
121 |
+
" return features\n",
|
122 |
+
"\n",
|
123 |
+
" except Exception as e:\n",
|
124 |
+
" print(f\"Error encountered while parsing file: {file_path}, {e}\")\n",
|
125 |
+
" return None"
|
126 |
+
]
|
127 |
+
},
|
128 |
+
{
|
129 |
+
"cell_type": "code",
|
130 |
+
"execution_count": 5,
|
131 |
+
"metadata": {
|
132 |
+
"id": "fiFT26TK_tA_"
|
133 |
+
},
|
134 |
+
"outputs": [],
|
135 |
+
"source": [
|
136 |
+
"def load_data(real_dir, fake_dir, real_files, fake_files):\n",
|
137 |
+
" data = []\n",
|
138 |
+
" columns = [\"rmse\", \"zcr\", \"tempo\", \"spectral_centroid\", \"spectral_bandwidth\",\n",
|
139 |
+
" \"spectral_contrast\", \"spectral_flatness\", \"spectral_rolloff\"] + \\\n",
|
140 |
+
" [f\"mfcc{i}\" for i in range(1, 21)] + [\"label\"]\n",
|
141 |
+
"\n",
|
142 |
+
" # Set up progress bar\n",
|
143 |
+
" total_files = len(real_files) + len(fake_files)\n",
|
144 |
+
" pbar = tqdm(total=total_files, desc=\"Processing files\", unit=\"file\")\n",
|
145 |
+
"\n",
|
146 |
+
" # Process real audio files\n",
|
147 |
+
" for file_name in real_files:\n",
|
148 |
+
" file_path = os.path.join(real_dir, file_name)\n",
|
149 |
+
" features = extract_features(file_path)\n",
|
150 |
+
" if features is not None:\n",
|
151 |
+
" features.append(0) # Label: 0 for REAL\n",
|
152 |
+
" data.append(features)\n",
|
153 |
+
" pbar.update(1)\n",
|
154 |
+
"\n",
|
155 |
+
" # Process fake audio files\n",
|
156 |
+
" for file_name in fake_files:\n",
|
157 |
+
" file_path = os.path.join(fake_dir, file_name)\n",
|
158 |
+
" features = extract_features(file_path)\n",
|
159 |
+
" if features is not None:\n",
|
160 |
+
" features.append(1) # Label: 1 for FAKE\n",
|
161 |
+
" data.append(features)\n",
|
162 |
+
" pbar.update(1)\n",
|
163 |
+
"\n",
|
164 |
+
" pbar.close()\n",
|
165 |
+
" df = pd.DataFrame(data, columns=columns)\n",
|
166 |
+
" return df\n"
|
167 |
+
]
|
168 |
+
},
|
169 |
+
{
|
170 |
+
"cell_type": "code",
|
171 |
+
"execution_count": 6,
|
172 |
+
"metadata": {
|
173 |
+
"id": "nL9J7Vp9JVRa"
|
174 |
+
},
|
175 |
+
"outputs": [],
|
176 |
+
"source": [
|
177 |
+
"real_audio_dir = r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\REAL\"\n",
|
178 |
+
"fake_audio_dir = r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\FAKE\""
|
179 |
+
]
|
180 |
+
},
|
181 |
+
{
|
182 |
+
"cell_type": "code",
|
183 |
+
"execution_count": null,
|
184 |
+
"metadata": {
|
185 |
+
"id": "gfwu2Ct2E5aQ"
|
186 |
+
},
|
187 |
+
"outputs": [],
|
188 |
+
"source": [
|
189 |
+
"with open(\n",
|
190 |
+
" r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\real_files.pkl\",\n",
|
191 |
+
" \"rb\",\n",
|
192 |
+
") as f:\n",
|
193 |
+
" real_files = pk.load(f)\n",
|
194 |
+
"\n",
|
195 |
+
"with open(\n",
|
196 |
+
" r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\fake_files.pkl\",\n",
|
197 |
+
" \"rb\",\n",
|
198 |
+
") as f:\n",
|
199 |
+
" fake_files = pk.load(f)"
|
200 |
+
]
|
201 |
+
},
|
202 |
+
{
|
203 |
+
"cell_type": "code",
|
204 |
+
"execution_count": null,
|
205 |
+
"metadata": {},
|
206 |
+
"outputs": [
|
207 |
+
{
|
208 |
+
"data": {
|
209 |
+
"text/plain": [
|
210 |
+
"(19154, 99992)"
|
211 |
+
]
|
212 |
+
},
|
213 |
+
"execution_count": 8,
|
214 |
+
"metadata": {},
|
215 |
+
"output_type": "execute_result"
|
216 |
+
}
|
217 |
+
],
|
218 |
+
"source": [
|
219 |
+
"len(real_files), len(fake_files)"
|
220 |
+
]
|
221 |
+
},
|
222 |
+
{
|
223 |
+
"cell_type": "code",
|
224 |
+
"execution_count": null,
|
225 |
+
"metadata": {},
|
226 |
+
"outputs": [],
|
227 |
+
"source": [
|
228 |
+
"fake_files = fake_files[:len(real_files)]"
|
229 |
+
]
|
230 |
+
},
|
231 |
+
{
|
232 |
+
"cell_type": "code",
|
233 |
+
"execution_count": null,
|
234 |
+
"metadata": {},
|
235 |
+
"outputs": [
|
236 |
+
{
|
237 |
+
"data": {
|
238 |
+
"text/plain": [
|
239 |
+
"(19154, 19154)"
|
240 |
+
]
|
241 |
+
},
|
242 |
+
"execution_count": 10,
|
243 |
+
"metadata": {},
|
244 |
+
"output_type": "execute_result"
|
245 |
+
}
|
246 |
+
],
|
247 |
+
"source": [
|
248 |
+
"len(real_files), len(fake_files)"
|
249 |
+
]
|
250 |
+
},
|
251 |
+
{
|
252 |
+
"cell_type": "code",
|
253 |
+
"execution_count": null,
|
254 |
+
"metadata": {
|
255 |
+
"colab": {
|
256 |
+
"base_uri": "https://localhost:8080/"
|
257 |
+
},
|
258 |
+
"id": "BUS-nOHOJVRb",
|
259 |
+
"outputId": "8eee5356-bbdb-4941-a6a8-023a552db603"
|
260 |
+
},
|
261 |
+
"outputs": [
|
262 |
+
{
|
263 |
+
"name": "stderr",
|
264 |
+
"output_type": "stream",
|
265 |
+
"text": [
|
266 |
+
"Processing files: 17%|█▋ | 671/4000 [1:19:37<4:35:56, 4.97s/file] "
|
267 |
+
]
|
268 |
+
}
|
269 |
+
],
|
270 |
+
"source": [
|
271 |
+
"df = load_data(real_audio_dir, fake_audio_dir, real_files[:2000], fake_files[:2000])"
|
272 |
+
]
|
273 |
+
},
|
274 |
+
{
|
275 |
+
"cell_type": "code",
|
276 |
+
"execution_count": null,
|
277 |
+
"metadata": {
|
278 |
+
"id": "3tLFhSuVJVRc"
|
279 |
+
},
|
280 |
+
"outputs": [
|
281 |
+
{
|
282 |
+
"data": {
|
283 |
+
"text/html": [
|
284 |
+
"<div>\n",
|
285 |
+
"<style scoped>\n",
|
286 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
287 |
+
" vertical-align: middle;\n",
|
288 |
+
" }\n",
|
289 |
+
"\n",
|
290 |
+
" .dataframe tbody tr th {\n",
|
291 |
+
" vertical-align: top;\n",
|
292 |
+
" }\n",
|
293 |
+
"\n",
|
294 |
+
" .dataframe thead th {\n",
|
295 |
+
" text-align: right;\n",
|
296 |
+
" }\n",
|
297 |
+
"</style>\n",
|
298 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
299 |
+
" <thead>\n",
|
300 |
+
" <tr style=\"text-align: right;\">\n",
|
301 |
+
" <th></th>\n",
|
302 |
+
" <th>rmse</th>\n",
|
303 |
+
" <th>zcr</th>\n",
|
304 |
+
" <th>tempo</th>\n",
|
305 |
+
" <th>spectral_centroid</th>\n",
|
306 |
+
" <th>spectral_bandwidth</th>\n",
|
307 |
+
" <th>spectral_contrast</th>\n",
|
308 |
+
" <th>spectral_flatness</th>\n",
|
309 |
+
" <th>spectral_rolloff</th>\n",
|
310 |
+
" <th>mfcc1</th>\n",
|
311 |
+
" <th>mfcc2</th>\n",
|
312 |
+
" <th>...</th>\n",
|
313 |
+
" <th>mfcc12</th>\n",
|
314 |
+
" <th>mfcc13</th>\n",
|
315 |
+
" <th>mfcc14</th>\n",
|
316 |
+
" <th>mfcc15</th>\n",
|
317 |
+
" <th>mfcc16</th>\n",
|
318 |
+
" <th>mfcc17</th>\n",
|
319 |
+
" <th>mfcc18</th>\n",
|
320 |
+
" <th>mfcc19</th>\n",
|
321 |
+
" <th>mfcc20</th>\n",
|
322 |
+
" <th>label</th>\n",
|
323 |
+
" </tr>\n",
|
324 |
+
" </thead>\n",
|
325 |
+
" <tbody>\n",
|
326 |
+
" <tr>\n",
|
327 |
+
" <th>5</th>\n",
|
328 |
+
" <td>0.004624</td>\n",
|
329 |
+
" <td>0.025053</td>\n",
|
330 |
+
" <td>129.199219</td>\n",
|
331 |
+
" <td>2725.983254</td>\n",
|
332 |
+
" <td>5010.822943</td>\n",
|
333 |
+
" <td>14.822473</td>\n",
|
334 |
+
" <td>0.002854</td>\n",
|
335 |
+
" <td>4820.494920</td>\n",
|
336 |
+
" <td>-534.778259</td>\n",
|
337 |
+
" <td>154.150742</td>\n",
|
338 |
+
" <td>...</td>\n",
|
339 |
+
" <td>8.461435</td>\n",
|
340 |
+
" <td>-5.363853</td>\n",
|
341 |
+
" <td>1.651735</td>\n",
|
342 |
+
" <td>1.570598</td>\n",
|
343 |
+
" <td>-6.969818</td>\n",
|
344 |
+
" <td>-1.332273</td>\n",
|
345 |
+
" <td>-7.264575</td>\n",
|
346 |
+
" <td>-2.166896</td>\n",
|
347 |
+
" <td>-5.390424</td>\n",
|
348 |
+
" <td>1</td>\n",
|
349 |
+
" </tr>\n",
|
350 |
+
" <tr>\n",
|
351 |
+
" <th>6</th>\n",
|
352 |
+
" <td>0.012205</td>\n",
|
353 |
+
" <td>0.040296</td>\n",
|
354 |
+
" <td>123.046875</td>\n",
|
355 |
+
" <td>3647.104615</td>\n",
|
356 |
+
" <td>5343.519738</td>\n",
|
357 |
+
" <td>16.671819</td>\n",
|
358 |
+
" <td>0.007903</td>\n",
|
359 |
+
" <td>8357.563553</td>\n",
|
360 |
+
" <td>-421.535065</td>\n",
|
361 |
+
" <td>121.641014</td>\n",
|
362 |
+
" <td>...</td>\n",
|
363 |
+
" <td>16.492485</td>\n",
|
364 |
+
" <td>-15.264863</td>\n",
|
365 |
+
" <td>5.351438</td>\n",
|
366 |
+
" <td>-6.834963</td>\n",
|
367 |
+
" <td>-6.844149</td>\n",
|
368 |
+
" <td>2.524184</td>\n",
|
369 |
+
" <td>-9.907133</td>\n",
|
370 |
+
" <td>2.443203</td>\n",
|
371 |
+
" <td>-3.203485</td>\n",
|
372 |
+
" <td>1</td>\n",
|
373 |
+
" </tr>\n",
|
374 |
+
" <tr>\n",
|
375 |
+
" <th>7</th>\n",
|
376 |
+
" <td>0.000486</td>\n",
|
377 |
+
" <td>0.065730</td>\n",
|
378 |
+
" <td>123.046875</td>\n",
|
379 |
+
" <td>4911.118560</td>\n",
|
380 |
+
" <td>5816.154610</td>\n",
|
381 |
+
" <td>13.167884</td>\n",
|
382 |
+
" <td>0.020470</td>\n",
|
383 |
+
" <td>12992.775671</td>\n",
|
384 |
+
" <td>-651.358948</td>\n",
|
385 |
+
" <td>105.408440</td>\n",
|
386 |
+
" <td>...</td>\n",
|
387 |
+
" <td>22.212151</td>\n",
|
388 |
+
" <td>-8.999311</td>\n",
|
389 |
+
" <td>9.159810</td>\n",
|
390 |
+
" <td>-1.134552</td>\n",
|
391 |
+
" <td>0.878308</td>\n",
|
392 |
+
" <td>-4.592861</td>\n",
|
393 |
+
" <td>6.159277</td>\n",
|
394 |
+
" <td>-8.804791</td>\n",
|
395 |
+
" <td>4.221607</td>\n",
|
396 |
+
" <td>1</td>\n",
|
397 |
+
" </tr>\n",
|
398 |
+
" <tr>\n",
|
399 |
+
" <th>8</th>\n",
|
400 |
+
" <td>0.010587</td>\n",
|
401 |
+
" <td>0.044573</td>\n",
|
402 |
+
" <td>126.048018</td>\n",
|
403 |
+
" <td>3769.014655</td>\n",
|
404 |
+
" <td>5425.975753</td>\n",
|
405 |
+
" <td>16.238748</td>\n",
|
406 |
+
" <td>0.008020</td>\n",
|
407 |
+
" <td>8702.531203</td>\n",
|
408 |
+
" <td>-423.674591</td>\n",
|
409 |
+
" <td>125.309708</td>\n",
|
410 |
+
" <td>...</td>\n",
|
411 |
+
" <td>17.190102</td>\n",
|
412 |
+
" <td>-19.386557</td>\n",
|
413 |
+
" <td>2.690195</td>\n",
|
414 |
+
" <td>-8.972520</td>\n",
|
415 |
+
" <td>-8.547749</td>\n",
|
416 |
+
" <td>3.633717</td>\n",
|
417 |
+
" <td>-7.594123</td>\n",
|
418 |
+
" <td>5.063034</td>\n",
|
419 |
+
" <td>-3.646331</td>\n",
|
420 |
+
" <td>1</td>\n",
|
421 |
+
" </tr>\n",
|
422 |
+
" <tr>\n",
|
423 |
+
" <th>9</th>\n",
|
424 |
+
" <td>0.001556</td>\n",
|
425 |
+
" <td>0.048985</td>\n",
|
426 |
+
" <td>126.048018</td>\n",
|
427 |
+
" <td>3916.497123</td>\n",
|
428 |
+
" <td>5451.384648</td>\n",
|
429 |
+
" <td>14.959555</td>\n",
|
430 |
+
" <td>0.011601</td>\n",
|
431 |
+
" <td>8986.764496</td>\n",
|
432 |
+
" <td>-614.185364</td>\n",
|
433 |
+
" <td>123.651947</td>\n",
|
434 |
+
" <td>...</td>\n",
|
435 |
+
" <td>16.776917</td>\n",
|
436 |
+
" <td>-9.418891</td>\n",
|
437 |
+
" <td>1.858516</td>\n",
|
438 |
+
" <td>-3.961122</td>\n",
|
439 |
+
" <td>-3.926236</td>\n",
|
440 |
+
" <td>-5.990383</td>\n",
|
441 |
+
" <td>3.210501</td>\n",
|
442 |
+
" <td>-8.581244</td>\n",
|
443 |
+
" <td>4.236759</td>\n",
|
444 |
+
" <td>1</td>\n",
|
445 |
+
" </tr>\n",
|
446 |
+
" </tbody>\n",
|
447 |
+
"</table>\n",
|
448 |
+
"<p>5 rows × 29 columns</p>\n",
|
449 |
+
"</div>"
|
450 |
+
],
|
451 |
+
"text/plain": [
|
452 |
+
" rmse zcr tempo spectral_centroid spectral_bandwidth \\\n",
|
453 |
+
"5 0.004624 0.025053 129.199219 2725.983254 5010.822943 \n",
|
454 |
+
"6 0.012205 0.040296 123.046875 3647.104615 5343.519738 \n",
|
455 |
+
"7 0.000486 0.065730 123.046875 4911.118560 5816.154610 \n",
|
456 |
+
"8 0.010587 0.044573 126.048018 3769.014655 5425.975753 \n",
|
457 |
+
"9 0.001556 0.048985 126.048018 3916.497123 5451.384648 \n",
|
458 |
+
"\n",
|
459 |
+
" spectral_contrast spectral_flatness spectral_rolloff mfcc1 \\\n",
|
460 |
+
"5 14.822473 0.002854 4820.494920 -534.778259 \n",
|
461 |
+
"6 16.671819 0.007903 8357.563553 -421.535065 \n",
|
462 |
+
"7 13.167884 0.020470 12992.775671 -651.358948 \n",
|
463 |
+
"8 16.238748 0.008020 8702.531203 -423.674591 \n",
|
464 |
+
"9 14.959555 0.011601 8986.764496 -614.185364 \n",
|
465 |
+
"\n",
|
466 |
+
" mfcc2 ... mfcc12 mfcc13 mfcc14 mfcc15 mfcc16 \\\n",
|
467 |
+
"5 154.150742 ... 8.461435 -5.363853 1.651735 1.570598 -6.969818 \n",
|
468 |
+
"6 121.641014 ... 16.492485 -15.264863 5.351438 -6.834963 -6.844149 \n",
|
469 |
+
"7 105.408440 ... 22.212151 -8.999311 9.159810 -1.134552 0.878308 \n",
|
470 |
+
"8 125.309708 ... 17.190102 -19.386557 2.690195 -8.972520 -8.547749 \n",
|
471 |
+
"9 123.651947 ... 16.776917 -9.418891 1.858516 -3.961122 -3.926236 \n",
|
472 |
+
"\n",
|
473 |
+
" mfcc17 mfcc18 mfcc19 mfcc20 label \n",
|
474 |
+
"5 -1.332273 -7.264575 -2.166896 -5.390424 1 \n",
|
475 |
+
"6 2.524184 -9.907133 2.443203 -3.203485 1 \n",
|
476 |
+
"7 -4.592861 6.159277 -8.804791 4.221607 1 \n",
|
477 |
+
"8 3.633717 -7.594123 5.063034 -3.646331 1 \n",
|
478 |
+
"9 -5.990383 3.210501 -8.581244 4.236759 1 \n",
|
479 |
+
"\n",
|
480 |
+
"[5 rows x 29 columns]"
|
481 |
+
]
|
482 |
+
},
|
483 |
+
"execution_count": 12,
|
484 |
+
"metadata": {},
|
485 |
+
"output_type": "execute_result"
|
486 |
+
}
|
487 |
+
],
|
488 |
+
"source": [
|
489 |
+
"df.tail()"
|
490 |
+
]
|
491 |
+
},
|
492 |
+
{
|
493 |
+
"cell_type": "code",
|
494 |
+
"execution_count": null,
|
495 |
+
"metadata": {
|
496 |
+
"id": "zMej7SKRJVRc"
|
497 |
+
},
|
498 |
+
"outputs": [],
|
499 |
+
"source": [
|
500 |
+
"# for file in file_names:\n",
|
501 |
+
"\n",
|
502 |
+
"# clean_file = file.split(\"/\")[-1]\n",
|
503 |
+
"# video_clip = VideoFileClip(file)\n",
|
504 |
+
"# audio = video_clip.audio\n",
|
505 |
+
"# fps = audio.fps\n",
|
506 |
+
"# audio_samples = np.array(list(audio.iter_frames(fps=fps, dtype=\"float32\"))).flatten()\n",
|
507 |
+
"# buffer = io.BytesIO()\n",
|
508 |
+
"# sf.write(buffer, audio_samples, fps, format='wav')\n",
|
509 |
+
"# buffer.seek(0)\n",
|
510 |
+
"# x, sr = librosa.load(buffer, sr=None)\n",
|
511 |
+
"# label = json.load(open(\"train_sample_videos/metadata.json\"))[clean_file]['label']\n",
|
512 |
+
"# new_row = pd.DataFrame([[clean_file] + get_features(x, sr) + [label]], columns=column_ames)\n",
|
513 |
+
"# df = pd.concat([df, new_row], ignore_index=True)"
|
514 |
+
]
|
515 |
+
},
|
516 |
+
{
|
517 |
+
"cell_type": "code",
|
518 |
+
"execution_count": null,
|
519 |
+
"metadata": {
|
520 |
+
"id": "BxacOcTrJVRc"
|
521 |
+
},
|
522 |
+
"outputs": [
|
523 |
+
{
|
524 |
+
"ename": "OSError",
|
525 |
+
"evalue": "Cannot save file into a non-existent directory: '\\content\\drive\\MyDrive\\SIH2024_DATASET'",
|
526 |
+
"output_type": "error",
|
527 |
+
"traceback": [
|
528 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
529 |
+
"\u001b[1;31mOSError\u001b[0m Traceback (most recent call last)",
|
530 |
+
"Cell \u001b[1;32mIn[14], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mdf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mto_csv\u001b[49m\u001b[43m(\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m/content/drive/MyDrive/SIH2024_DATASET/full_features.csv\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mindex\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\n",
|
531 |
+
"File \u001b[1;32md:\\Python\\Lib\\site-packages\\pandas\\util\\_decorators.py:333\u001b[0m, in \u001b[0;36mdeprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 327\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(args) \u001b[38;5;241m>\u001b[39m num_allow_args:\n\u001b[0;32m 328\u001b[0m warnings\u001b[38;5;241m.\u001b[39mwarn(\n\u001b[0;32m 329\u001b[0m msg\u001b[38;5;241m.\u001b[39mformat(arguments\u001b[38;5;241m=\u001b[39m_format_argument_list(allow_args)),\n\u001b[0;32m 330\u001b[0m \u001b[38;5;167;01mFutureWarning\u001b[39;00m,\n\u001b[0;32m 331\u001b[0m stacklevel\u001b[38;5;241m=\u001b[39mfind_stack_level(),\n\u001b[0;32m 332\u001b[0m )\n\u001b[1;32m--> 333\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
|
532 |
+
"File \u001b[1;32md:\\Python\\Lib\\site-packages\\pandas\\core\\generic.py:3964\u001b[0m, in \u001b[0;36mNDFrame.to_csv\u001b[1;34m(self, path_or_buf, sep, na_rep, float_format, columns, header, index, index_label, mode, encoding, compression, quoting, quotechar, lineterminator, chunksize, date_format, doublequote, escapechar, decimal, errors, storage_options)\u001b[0m\n\u001b[0;32m 3953\u001b[0m df \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[38;5;28mself\u001b[39m, ABCDataFrame) \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mto_frame()\n\u001b[0;32m 3955\u001b[0m formatter \u001b[38;5;241m=\u001b[39m DataFrameFormatter(\n\u001b[0;32m 3956\u001b[0m frame\u001b[38;5;241m=\u001b[39mdf,\n\u001b[0;32m 3957\u001b[0m header\u001b[38;5;241m=\u001b[39mheader,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 3961\u001b[0m decimal\u001b[38;5;241m=\u001b[39mdecimal,\n\u001b[0;32m 3962\u001b[0m )\n\u001b[1;32m-> 3964\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mDataFrameRenderer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mformatter\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mto_csv\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 3965\u001b[0m \u001b[43m \u001b[49m\u001b[43mpath_or_buf\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3966\u001b[0m \u001b[43m \u001b[49m\u001b[43mlineterminator\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlineterminator\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3967\u001b[0m \u001b[43m \u001b[49m\u001b[43msep\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msep\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3968\u001b[0m \u001b[43m \u001b[49m\u001b[43mencoding\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mencoding\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3969\u001b[0m \u001b[43m \u001b[49m\u001b[43merrors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43merrors\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3970\u001b[0m \u001b[43m \u001b[49m\u001b[43mcompression\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcompression\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3971\u001b[0m \u001b[43m \u001b[49m\u001b[43mquoting\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mquoting\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3972\u001b[0m \u001b[43m \u001b[49m\u001b[43mcolumns\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcolumns\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3973\u001b[0m \u001b[43m \u001b[49m\u001b[43mindex_label\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mindex_label\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3974\u001b[0m \u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3975\u001b[0m \u001b[43m \u001b[49m\u001b[43mchunksize\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mchunksize\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3976\u001b[0m \u001b[43m \u001b[49m\u001b[43mquotechar\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mquotechar\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3977\u001b[0m \u001b[43m \u001b[49m\u001b[43mdate_format\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdate_format\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3978\u001b[0m \u001b[43m \u001b[49m\u001b[43mdoublequote\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdoublequote\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3979\u001b[0m \u001b[43m \u001b[49m\u001b[43mescapechar\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mescapechar\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3980\u001b[0m \u001b[43m \u001b[49m\u001b[43mstorage_options\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstorage_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3981\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
|
533 |
+
"File \u001b[1;32md:\\Python\\Lib\\site-packages\\pandas\\io\\formats\\format.py:1014\u001b[0m, in \u001b[0;36mDataFrameRenderer.to_csv\u001b[1;34m(self, path_or_buf, encoding, sep, columns, index_label, mode, compression, quoting, quotechar, lineterminator, chunksize, date_format, doublequote, escapechar, errors, storage_options)\u001b[0m\n\u001b[0;32m 993\u001b[0m created_buffer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[0;32m 995\u001b[0m csv_formatter \u001b[38;5;241m=\u001b[39m CSVFormatter(\n\u001b[0;32m 996\u001b[0m path_or_buf\u001b[38;5;241m=\u001b[39mpath_or_buf,\n\u001b[0;32m 997\u001b[0m lineterminator\u001b[38;5;241m=\u001b[39mlineterminator,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 1012\u001b[0m formatter\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfmt,\n\u001b[0;32m 1013\u001b[0m )\n\u001b[1;32m-> 1014\u001b[0m \u001b[43mcsv_formatter\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msave\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1016\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m created_buffer:\n\u001b[0;32m 1017\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(path_or_buf, StringIO)\n",
|
534 |
+
"File \u001b[1;32md:\\Python\\Lib\\site-packages\\pandas\\io\\formats\\csvs.py:251\u001b[0m, in \u001b[0;36mCSVFormatter.save\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 247\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 248\u001b[0m \u001b[38;5;124;03mCreate the writer & save.\u001b[39;00m\n\u001b[0;32m 249\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 250\u001b[0m \u001b[38;5;66;03m# apply compression and byte/text conversion\u001b[39;00m\n\u001b[1;32m--> 251\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[43mget_handle\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 252\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfilepath_or_buffer\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 253\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 254\u001b[0m \u001b[43m \u001b[49m\u001b[43mencoding\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mencoding\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 255\u001b[0m \u001b[43m \u001b[49m\u001b[43merrors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43merrors\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 256\u001b[0m \u001b[43m \u001b[49m\u001b[43mcompression\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcompression\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 257\u001b[0m \u001b[43m \u001b[49m\u001b[43mstorage_options\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstorage_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 258\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m handles:\n\u001b[0;32m 259\u001b[0m \u001b[38;5;66;03m# Note: self.encoding is irrelevant here\u001b[39;00m\n\u001b[0;32m 260\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mwriter \u001b[38;5;241m=\u001b[39m csvlib\u001b[38;5;241m.\u001b[39mwriter(\n\u001b[0;32m 261\u001b[0m handles\u001b[38;5;241m.\u001b[39mhandle,\n\u001b[0;32m 262\u001b[0m lineterminator\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlineterminator,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 267\u001b[0m quotechar\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mquotechar,\n\u001b[0;32m 268\u001b[0m )\n\u001b[0;32m 270\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_save()\n",
|
535 |
+
"File \u001b[1;32md:\\Python\\Lib\\site-packages\\pandas\\io\\common.py:749\u001b[0m, in \u001b[0;36mget_handle\u001b[1;34m(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)\u001b[0m\n\u001b[0;32m 747\u001b[0m \u001b[38;5;66;03m# Only for write methods\u001b[39;00m\n\u001b[0;32m 748\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m mode \u001b[38;5;129;01mand\u001b[39;00m is_path:\n\u001b[1;32m--> 749\u001b[0m \u001b[43mcheck_parent_directory\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mhandle\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 751\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m compression:\n\u001b[0;32m 752\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m compression \u001b[38;5;241m!=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mzstd\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m 753\u001b[0m \u001b[38;5;66;03m# compression libraries do not like an explicit text-mode\u001b[39;00m\n",
|
536 |
+
"File \u001b[1;32md:\\Python\\Lib\\site-packages\\pandas\\io\\common.py:616\u001b[0m, in \u001b[0;36mcheck_parent_directory\u001b[1;34m(path)\u001b[0m\n\u001b[0;32m 614\u001b[0m parent \u001b[38;5;241m=\u001b[39m Path(path)\u001b[38;5;241m.\u001b[39mparent\n\u001b[0;32m 615\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m parent\u001b[38;5;241m.\u001b[39mis_dir():\n\u001b[1;32m--> 616\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mOSError\u001b[39;00m(\u001b[38;5;124mrf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCannot save file into a non-existent directory: \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mparent\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
537 |
+
"\u001b[1;31mOSError\u001b[0m: Cannot save file into a non-existent directory: '\\content\\drive\\MyDrive\\SIH2024_DATASET'"
|
538 |
+
]
|
539 |
+
}
|
540 |
+
],
|
541 |
+
"source": [
|
542 |
+
"df.to_csv( \"full_features.csv\", index=False)"
|
543 |
+
]
|
544 |
+
},
|
545 |
+
{
|
546 |
+
"cell_type": "code",
|
547 |
+
"execution_count": null,
|
548 |
+
"metadata": {
|
549 |
+
"id": "3PTTLrLhJVRc"
|
550 |
+
},
|
551 |
+
"outputs": [],
|
552 |
+
"source": []
|
553 |
+
}
|
554 |
+
],
|
555 |
+
"metadata": {
|
556 |
+
"accelerator": "GPU",
|
557 |
+
"colab": {
|
558 |
+
"gpuType": "T4",
|
559 |
+
"provenance": []
|
560 |
+
},
|
561 |
+
"kernelspec": {
|
562 |
+
"display_name": "Python 3",
|
563 |
+
"name": "python3"
|
564 |
+
},
|
565 |
+
"language_info": {
|
566 |
+
"codemirror_mode": {
|
567 |
+
"name": "ipython",
|
568 |
+
"version": 3
|
569 |
+
},
|
570 |
+
"file_extension": ".py",
|
571 |
+
"mimetype": "text/x-python",
|
572 |
+
"name": "python",
|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
|
11 |
+
"outputId": "daa7d2ac-02a4-4258-897f-2b1dbdfa7a28"
|
12 |
+
},
|
13 |
+
"outputs": [],
|
14 |
+
"source": [
|
15 |
+
"from moviepy.editor import VideoFileClip\n",
|
16 |
+
"import numpy as np\n",
|
17 |
+
"import pandas as pd\n",
|
18 |
+
"import scipy.stats\n",
|
19 |
+
"import pandas as pd\n",
|
20 |
+
"import glob\n",
|
21 |
+
"import json\n",
|
22 |
+
"import librosa\n",
|
23 |
+
"import soundfile as sf\n",
|
24 |
+
"import io\n",
|
25 |
+
"import os\n",
|
26 |
+
"from tqdm import tqdm\n",
|
27 |
+
"import pickle as pk"
|
28 |
+
]
|
29 |
+
},
|
30 |
+
{
|
31 |
+
"cell_type": "markdown",
|
32 |
+
"metadata": {
|
33 |
+
"id": "3A9iF-QXJVRZ"
|
34 |
+
},
|
35 |
+
"source": [
|
36 |
+
"Statistical Features \n",
|
37 |
+
"A first easy step is to compute the mean, standard deviation, minimum, maximum, median and quartiles of the frequencies of each signal. This can be done using Numpy and it always brings value to our feature extraction."
|
38 |
+
]
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"cell_type": "code",
|
42 |
+
"execution_count": 2,
|
43 |
+
"metadata": {
|
44 |
+
"id": "ibnbShbMJVRa"
|
45 |
+
},
|
46 |
+
"outputs": [],
|
47 |
+
"source": [
|
48 |
+
"# freqs = np.fft.fftfreq(x.size)\n",
|
49 |
+
"\n",
|
50 |
+
"# def describe_freq(freqs):\n",
|
51 |
+
"# mean = np.mean(freqs)\n",
|
52 |
+
"# std = np.std(freqs)\n",
|
53 |
+
"# maxv = np.amax(freqs)\n",
|
54 |
+
"# minv = np.amin(freqs)\n",
|
55 |
+
"# median = np.median(freqs)\n",
|
56 |
+
"# skew = scipy.stats.skew(freqs)\n",
|
57 |
+
"# kurt = scipy.stats.kurtosis(freqs)\n",
|
58 |
+
"# q1 = np.quantile(freqs, 0.25)\n",
|
59 |
+
"# q3 = np.quantile(freqs, 0.75)\n",
|
60 |
+
"# mode = scipy.stats.mode(freqs)[0][0]\n",
|
61 |
+
"# iqr = scipy.stats.iqr(freqs)\n",
|
62 |
+
"\n",
|
63 |
+
"# return [mean, std, maxv, minv, median, skew, kurt, q1, q3, mode, iqr]"
|
64 |
+
]
|
65 |
+
},
|
66 |
+
{
|
67 |
+
"cell_type": "code",
|
68 |
+
"execution_count": 3,
|
69 |
+
"metadata": {
|
70 |
+
"id": "nNifSVyDJVRa"
|
71 |
+
},
|
72 |
+
"outputs": [],
|
73 |
+
"source": [
|
74 |
+
"# def get_features(x, sr):\n",
|
75 |
+
"# rmse = np.mean(librosa.feature.rms(y=x)[0])\n",
|
76 |
+
"# zcr = np.mean(librosa.feature.zero_crossing_rate(x)[0])\n",
|
77 |
+
"# tempo = librosa.beat.tempo(y=x, sr=sr)[0]\n",
|
78 |
+
"# mfcc = list(np.mean(librosa.feature.mfcc(y=x, sr=sr), axis=1))\n",
|
79 |
+
"# spec_cen = np.mean(librosa.feature.spectral_centroid(y=x, sr=sr))\n",
|
80 |
+
"# spectral_bandwidth = np.mean(librosa.feature.spectral_bandwidth(y=x, sr=sr))\n",
|
81 |
+
"# spectral_contrast = np.mean(librosa.feature.spectral_contrast(y=x, sr=sr))\n",
|
82 |
+
"# spectral_flatness = np.mean(librosa.feature.spectral_flatness(y=x))\n",
|
83 |
+
"# spectral_rolloff = np.mean(librosa.feature.spectral_rolloff(y=x, sr=sr))\n",
|
84 |
+
"# features = [rmse, zcr, tempo, spec_cen, spectral_bandwidth, spectral_contrast, spectral_flatness, spectral_rolloff]\n",
|
85 |
+
"# return features + mfcc"
|
86 |
+
]
|
87 |
+
},
|
88 |
+
{
|
89 |
+
"cell_type": "code",
|
90 |
+
"execution_count": 2,
|
91 |
+
"metadata": {
|
92 |
+
"id": "nL9J7Vp9JVRa"
|
93 |
+
},
|
94 |
+
"outputs": [],
|
95 |
+
"source": [
|
96 |
+
"fake_audio_dir = (\n",
|
97 |
+
" r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\FAKE\"\n",
|
98 |
+
")\n",
|
99 |
+
"real_audio_dir = (\n",
|
100 |
+
" r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\REAL\"\n",
|
101 |
+
")"
|
102 |
+
]
|
103 |
+
},
|
104 |
+
{
|
105 |
+
"cell_type": "code",
|
106 |
+
"execution_count": 3,
|
107 |
+
"metadata": {},
|
108 |
+
"outputs": [],
|
109 |
+
"source": [
|
110 |
+
"real_files = os.listdir(real_audio_dir)\n",
|
111 |
+
"fake_files = os.listdir(fake_audio_dir)"
|
112 |
+
]
|
113 |
+
},
|
114 |
+
{
|
115 |
+
"cell_type": "code",
|
116 |
+
"execution_count": 5,
|
117 |
+
"metadata": {},
|
118 |
+
"outputs": [],
|
119 |
+
"source": [
|
120 |
+
"with open(\n",
|
121 |
+
" r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\real_files.pkl\",\n",
|
122 |
+
" \"wb\",\n",
|
123 |
+
") as f:\n",
|
124 |
+
" pk.dump(real_files, f)\n",
|
125 |
+
"\n",
|
126 |
+
"with open(\n",
|
127 |
+
" r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\fake_files.pkl\",\n",
|
128 |
+
" \"wb\",\n",
|
129 |
+
") as f:\n",
|
130 |
+
" pk.dump(fake_files, f)"
|
131 |
+
]
|
132 |
+
},
|
133 |
+
{
|
134 |
+
"cell_type": "code",
|
135 |
+
"execution_count": null,
|
136 |
+
"metadata": {},
|
137 |
+
"outputs": [],
|
138 |
+
"source": [
|
139 |
+
"with open(\n",
|
140 |
+
" r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\real_files.pkl\",\n",
|
141 |
+
" \"rb\",\n",
|
142 |
+
") as f:\n",
|
143 |
+
" real_files = pk.load(f)\n",
|
144 |
+
"\n",
|
145 |
+
"with open(\n",
|
146 |
+
" r\"H:\\.shortcut-targets-by-id\\1jH_pc6mMj0Iu8wLS1r0vggMWpVElJvOU\\SIH2024_DATASET\\fake_files.pkl\",\n",
|
147 |
+
" \"rb\",\n",
|
148 |
+
") as f:\n",
|
149 |
+
" fake_files = pk.load(f)"
|
150 |
+
]
|
151 |
+
},
|
152 |
+
{
|
153 |
+
"cell_type": "code",
|
154 |
+
"execution_count": 8,
|
155 |
+
"metadata": {},
|
156 |
+
"outputs": [],
|
157 |
+
"source": [
|
158 |
+
"total_files = len(real_files) + len(fake_files)"
|
159 |
+
]
|
160 |
+
},
|
161 |
+
{
|
162 |
+
"cell_type": "code",
|
163 |
+
"execution_count": 9,
|
164 |
+
"metadata": {
|
165 |
+
"id": "BUS-nOHOJVRb"
|
166 |
+
},
|
167 |
+
"outputs": [],
|
168 |
+
"source": [
|
169 |
+
"def get_features(x, sr):\n",
|
170 |
+
" \"\"\"Extract audio features from the audio signal.\"\"\"\n",
|
171 |
+
" rmse = np.mean(librosa.feature.rms(y=x)[0])\n",
|
172 |
+
" zcr = np.mean(librosa.feature.zero_crossing_rate(x)[0])\n",
|
173 |
+
" tempo = librosa.beat.tempo(y=x, sr=sr)[0]\n",
|
174 |
+
" mfcc = list(np.mean(librosa.feature.mfcc(y=x, sr=sr), axis=1))\n",
|
175 |
+
" spec_cen = np.mean(librosa.feature.spectral_centroid(y=x, sr=sr))\n",
|
176 |
+
" spectral_bandwidth = np.mean(librosa.feature.spectral_bandwidth(y=x, sr=sr))\n",
|
177 |
+
" spectral_contrast = np.mean(librosa.feature.spectral_contrast(y=x, sr=sr))\n",
|
178 |
+
" spectral_flatness = np.mean(librosa.feature.spectral_flatness(y=x))\n",
|
179 |
+
" spectral_rolloff = np.mean(librosa.feature.spectral_rolloff(y=x, sr=sr))\n",
|
180 |
+
" features = [\n",
|
181 |
+
" rmse,\n",
|
182 |
+
" zcr,\n",
|
183 |
+
" tempo,\n",
|
184 |
+
" spec_cen,\n",
|
185 |
+
" spectral_bandwidth,\n",
|
186 |
+
" spectral_contrast,\n",
|
187 |
+
" spectral_flatness,\n",
|
188 |
+
" spectral_rolloff,\n",
|
189 |
+
" ]\n",
|
190 |
+
" return features + mfcc\n",
|
191 |
+
"\n",
|
192 |
+
"\n",
|
193 |
+
"def extract_features(file_path):\n",
|
194 |
+
" \"\"\"Extract features from a video file.\"\"\"\n",
|
195 |
+
" try:\n",
|
196 |
+
" # Load the video file\n",
|
197 |
+
" video_clip = VideoFileClip(file_path)\n",
|
198 |
+
" audio = video_clip.audio\n",
|
199 |
+
" fps = audio.fps\n",
|
200 |
+
" audio_samples = np.array(\n",
|
201 |
+
" list(audio.iter_frames(fps=fps, dtype=\"float32\"))\n",
|
202 |
+
" ).flatten()\n",
|
203 |
+
" buffer = io.BytesIO()\n",
|
204 |
+
" sf.write(buffer, audio_samples, fps, format=\"wav\")\n",
|
205 |
+
" buffer.seek(0)\n",
|
206 |
+
" x, sr = librosa.load(buffer, sr=None)\n",
|
207 |
+
" video_clip.close() # Close the video file\n",
|
208 |
+
" features = get_features(x, sr)\n",
|
209 |
+
" return features\n",
|
210 |
+
"\n",
|
211 |
+
" except Exception as e:\n",
|
212 |
+
" print(f\"Error encountered while parsing file: {file_path}, {e}\")\n",
|
213 |
+
" return None\n",
|
214 |
+
"\n",
|
215 |
+
"\n",
|
216 |
+
"def load_data(real_dir, fake_dir, real_files, fake_files):\n",
|
217 |
+
" \"\"\"Load and process audio files from real and fake directories.\"\"\"\n",
|
218 |
+
" data = []\n",
|
219 |
+
"\n",
|
220 |
+
" # Define column names\n",
|
221 |
+
" columns = (\n",
|
222 |
+
" [\n",
|
223 |
+
" \"rmse\",\n",
|
224 |
+
" \"zcr\",\n",
|
225 |
+
" \"tempo\",\n",
|
226 |
+
" \"spectral_centroid\",\n",
|
227 |
+
" \"spectral_bandwidth\",\n",
|
228 |
+
" \"spectral_contrast\",\n",
|
229 |
+
" \"spectral_flatness\",\n",
|
230 |
+
" \"spectral_rolloff\",\n",
|
231 |
+
" ]\n",
|
232 |
+
" + [f\"mfcc{i}\" for i in range(1, 21)]\n",
|
233 |
+
" + [\"label\"]\n",
|
234 |
+
" )\n",
|
235 |
+
"\n",
|
236 |
+
" # Get total number of files for progress bar\n",
|
237 |
+
" total_files = len(real_files) + len(fake_files)\n",
|
238 |
+
"\n",
|
239 |
+
" # Create progress bar\n",
|
240 |
+
" pbar = tqdm(total=total_files, desc=\"Processing files\", unit=\"file\")\n",
|
241 |
+
"\n",
|
242 |
+
" # Process real audio files\n",
|
243 |
+
" for file_name in real_files:\n",
|
244 |
+
" file_path = os.path.join(real_dir, file_name)\n",
|
245 |
+
" features = extract_features(file_path)\n",
|
246 |
+
" if features is not None:\n",
|
247 |
+
" features.append(0) # 0 for REAL\n",
|
248 |
+
" data.append(features)\n",
|
249 |
+
" pbar.update(1)\n",
|
250 |
+
" pbar.set_postfix({\"Current file\": file_name[:20]})\n",
|
251 |
+
"\n",
|
252 |
+
" # Process fake audio files\n",
|
253 |
+
" for file_name in fake_files:\n",
|
254 |
+
" file_path = os.path.join(fake_dir, file_name)\n",
|
255 |
+
" features = extract_features(file_path)\n",
|
256 |
+
" if features is not None:\n",
|
257 |
+
" features.append(1) # 1 for FAKE\n",
|
258 |
+
" data.append(features)\n",
|
259 |
+
" pbar.update(1)\n",
|
260 |
+
" pbar.set_postfix({\"Current file\": file_name[:20]})\n",
|
261 |
+
"\n",
|
262 |
+
" pbar.close()\n",
|
263 |
+
"\n",
|
264 |
+
" # Create DataFrame with the collected data\n",
|
265 |
+
" df = pd.DataFrame(data, columns=columns)\n",
|
266 |
+
" return df"
|
267 |
+
]
|
268 |
+
},
|
269 |
+
{
|
270 |
+
"cell_type": "code",
|
271 |
+
"execution_count": 10,
|
272 |
+
"metadata": {
|
273 |
+
"id": "1cxXpFqCJVRb"
|
274 |
+
},
|
275 |
+
"outputs": [],
|
276 |
+
"source": [
|
277 |
+
"df = pd.DataFrame(\n",
|
278 |
+
" columns=[\n",
|
279 |
+
" \"rmse\",\n",
|
280 |
+
" \"zcr\",\n",
|
281 |
+
" \"tempo\",\n",
|
282 |
+
" \"spectral_centroid\",\n",
|
283 |
+
" \"spectral_bandwidth\",\n",
|
284 |
+
" \"spectral_contrast\",\n",
|
285 |
+
" \"spectral_flatness\",\n",
|
286 |
+
" \"spectral_rolloff\",\n",
|
287 |
+
" \"mfcc1\",\n",
|
288 |
+
" \"mfcc2\",\n",
|
289 |
+
" \"mfcc3\",\n",
|
290 |
+
" \"mfcc4\",\n",
|
291 |
+
" \"mfcc5\",\n",
|
292 |
+
" \"mfcc6\",\n",
|
293 |
+
" \"mfcc7\",\n",
|
294 |
+
" \"mfcc8\",\n",
|
295 |
+
" \"mfcc9\",\n",
|
296 |
+
" \"mfcc10\",\n",
|
297 |
+
" \"mfcc11\",\n",
|
298 |
+
" \"mfcc12\",\n",
|
299 |
+
" \"mfcc13\",\n",
|
300 |
+
" \"mfcc14\",\n",
|
301 |
+
" \"mfcc15\",\n",
|
302 |
+
" \"mfcc16\",\n",
|
303 |
+
" \"mfcc17\",\n",
|
304 |
+
" \"mfcc18\",\n",
|
305 |
+
" \"mfcc19\",\n",
|
306 |
+
" \"mfcc20\",\n",
|
307 |
+
" \"label\",]\n",
|
308 |
+
")"
|
309 |
+
]
|
310 |
+
},
|
311 |
+
{
|
312 |
+
"cell_type": "code",
|
313 |
+
"execution_count": 11,
|
314 |
+
"metadata": {
|
315 |
+
"id": "fSpp-6btJVRb"
|
316 |
+
},
|
317 |
+
"outputs": [
|
318 |
+
{
|
319 |
+
"name": "stderr",
|
320 |
+
"output_type": "stream",
|
321 |
+
"text": [
|
322 |
+
"Processing files: 0%| | 15/119148 [01:07<176:25:02, 5.33s/file, Current file=ehgdzhkdvo.mp4]"
|
323 |
+
]
|
324 |
+
},
|
325 |
+
{
|
326 |
+
"ename": "KeyboardInterrupt",
|
327 |
+
"evalue": "",
|
328 |
+
"output_type": "error",
|
329 |
+
"traceback": [
|
330 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
331 |
+
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
332 |
+
"Cell \u001b[1;32mIn[11], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m df \u001b[38;5;241m=\u001b[39m \u001b[43mload_data\u001b[49m\u001b[43m(\u001b[49m\u001b[43mreal_audio_dir\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfake_audio_dir\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mreal_files\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfake_files\u001b[49m\u001b[43m)\u001b[49m\n",
|
333 |
+
"Cell \u001b[1;32mIn[9], line 77\u001b[0m, in \u001b[0;36mload_data\u001b[1;34m(real_dir, fake_dir, real_files, fake_files)\u001b[0m\n\u001b[0;32m 75\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m file_name \u001b[38;5;129;01min\u001b[39;00m real_files:\n\u001b[0;32m 76\u001b[0m file_path \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(real_dir, file_name)\n\u001b[1;32m---> 77\u001b[0m features \u001b[38;5;241m=\u001b[39m \u001b[43mextract_features\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile_path\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 78\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m features \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m 79\u001b[0m features\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;241m0\u001b[39m) \u001b[38;5;66;03m# 0 for REAL\u001b[39;00m\n",
|
334 |
+
"Cell \u001b[1;32mIn[9], line 29\u001b[0m, in \u001b[0;36mextract_features\u001b[1;34m(file_path)\u001b[0m\n\u001b[0;32m 26\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Extract features from a video file.\"\"\"\u001b[39;00m\n\u001b[0;32m 27\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m 28\u001b[0m \u001b[38;5;66;03m# Load the video file\u001b[39;00m\n\u001b[1;32m---> 29\u001b[0m video_clip \u001b[38;5;241m=\u001b[39m \u001b[43mVideoFileClip\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile_path\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 30\u001b[0m audio \u001b[38;5;241m=\u001b[39m video_clip\u001b[38;5;241m.\u001b[39maudio\n\u001b[0;32m 31\u001b[0m fps \u001b[38;5;241m=\u001b[39m audio\u001b[38;5;241m.\u001b[39mfps\n",
|
335 |
+
"File \u001b[1;32md:\\Python\\Lib\\site-packages\\moviepy\\video\\io\\VideoFileClip.py:88\u001b[0m, in \u001b[0;36mVideoFileClip.__init__\u001b[1;34m(self, filename, has_mask, audio, audio_buffersize, target_resolution, resize_algorithm, audio_fps, audio_nbytes, verbose, fps_source)\u001b[0m\n\u001b[0;32m 86\u001b[0m \u001b[38;5;66;03m# Make a reader\u001b[39;00m\n\u001b[0;32m 87\u001b[0m pix_fmt \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrgba\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m has_mask \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrgb24\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m---> 88\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mreader \u001b[38;5;241m=\u001b[39m \u001b[43mFFMPEG_VideoReader\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpix_fmt\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpix_fmt\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 89\u001b[0m \u001b[43m \u001b[49m\u001b[43mtarget_resolution\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtarget_resolution\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 90\u001b[0m \u001b[43m \u001b[49m\u001b[43mresize_algo\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mresize_algorithm\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 91\u001b[0m \u001b[43m \u001b[49m\u001b[43mfps_source\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfps_source\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 93\u001b[0m \u001b[38;5;66;03m# Make some of the reader's attributes accessible from the clip\u001b[39;00m\n\u001b[0;32m 94\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mduration \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mreader\u001b[38;5;241m.\u001b[39mduration\n",
|
336 |
+
"File \u001b[1;32md:\\Python\\Lib\\site-packages\\moviepy\\video\\io\\ffmpeg_reader.py:35\u001b[0m, in \u001b[0;36mFFMPEG_VideoReader.__init__\u001b[1;34m(self, filename, print_infos, bufsize, pix_fmt, check_duration, target_resolution, resize_algo, fps_source)\u001b[0m\n\u001b[0;32m 33\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfilename \u001b[38;5;241m=\u001b[39m filename\n\u001b[0;32m 34\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mproc \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m---> 35\u001b[0m infos \u001b[38;5;241m=\u001b[39m \u001b[43mffmpeg_parse_infos\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprint_infos\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcheck_duration\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 36\u001b[0m \u001b[43m \u001b[49m\u001b[43mfps_source\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 37\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfps \u001b[38;5;241m=\u001b[39m infos[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mvideo_fps\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[0;32m 38\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msize \u001b[38;5;241m=\u001b[39m infos[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mvideo_size\u001b[39m\u001b[38;5;124m'\u001b[39m]\n",
|
337 |
+
"File \u001b[1;32md:\\Python\\Lib\\site-packages\\moviepy\\video\\io\\ffmpeg_reader.py:258\u001b[0m, in \u001b[0;36mffmpeg_parse_infos\u001b[1;34m(filename, print_infos, check_duration, fps_source)\u001b[0m\n\u001b[0;32m 255\u001b[0m popen_params[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcreationflags\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0x08000000\u001b[39m\n\u001b[0;32m 257\u001b[0m proc \u001b[38;5;241m=\u001b[39m sp\u001b[38;5;241m.\u001b[39mPopen(cmd, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mpopen_params)\n\u001b[1;32m--> 258\u001b[0m (output, error) \u001b[38;5;241m=\u001b[39m \u001b[43mproc\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcommunicate\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 259\u001b[0m infos \u001b[38;5;241m=\u001b[39m error\u001b[38;5;241m.\u001b[39mdecode(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mutf8\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 261\u001b[0m \u001b[38;5;28;01mdel\u001b[39;00m proc\n",
|
338 |
+
"File \u001b[1;32md:\\Python\\Lib\\subprocess.py:1209\u001b[0m, in \u001b[0;36mPopen.communicate\u001b[1;34m(self, input, timeout)\u001b[0m\n\u001b[0;32m 1206\u001b[0m endtime \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 1208\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 1209\u001b[0m stdout, stderr \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_communicate\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mendtime\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1210\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m 1211\u001b[0m \u001b[38;5;66;03m# https://bugs.python.org/issue25942\u001b[39;00m\n\u001b[0;32m 1212\u001b[0m \u001b[38;5;66;03m# See the detailed comment in .wait().\u001b[39;00m\n\u001b[0;32m 1213\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m timeout \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
|
339 |
+
"File \u001b[1;32md:\\Python\\Lib\\subprocess.py:1626\u001b[0m, in \u001b[0;36mPopen._communicate\u001b[1;34m(self, input, endtime, orig_timeout)\u001b[0m\n\u001b[0;32m 1622\u001b[0m \u001b[38;5;66;03m# Wait for the reader threads, or time out. If we time out, the\u001b[39;00m\n\u001b[0;32m 1623\u001b[0m \u001b[38;5;66;03m# threads remain reading and the fds left open in case the user\u001b[39;00m\n\u001b[0;32m 1624\u001b[0m \u001b[38;5;66;03m# calls communicate again.\u001b[39;00m\n\u001b[0;32m 1625\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstdout \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m-> 1626\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstdout_thread\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mjoin\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_remaining_time\u001b[49m\u001b[43m(\u001b[49m\u001b[43mendtime\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1627\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstdout_thread\u001b[38;5;241m.\u001b[39mis_alive():\n\u001b[0;32m 1628\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m TimeoutExpired(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39margs, orig_timeout)\n",
|
340 |
+
"File \u001b[1;32md:\\Python\\Lib\\threading.py:1147\u001b[0m, in \u001b[0;36mThread.join\u001b[1;34m(self, timeout)\u001b[0m\n\u001b[0;32m 1144\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcannot join current thread\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 1146\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m timeout \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m-> 1147\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_wait_for_tstate_lock\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1148\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 1149\u001b[0m \u001b[38;5;66;03m# the behavior of a negative timeout isn't documented, but\u001b[39;00m\n\u001b[0;32m 1150\u001b[0m \u001b[38;5;66;03m# historically .join(timeout=x) for x<0 has acted as if timeout=0\u001b[39;00m\n\u001b[0;32m 1151\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_wait_for_tstate_lock(timeout\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mmax\u001b[39m(timeout, \u001b[38;5;241m0\u001b[39m))\n",
|
341 |
+
"File \u001b[1;32md:\\Python\\Lib\\threading.py:1167\u001b[0m, in \u001b[0;36mThread._wait_for_tstate_lock\u001b[1;34m(self, block, timeout)\u001b[0m\n\u001b[0;32m 1164\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[0;32m 1166\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 1167\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mlock\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43macquire\u001b[49m\u001b[43m(\u001b[49m\u001b[43mblock\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m)\u001b[49m:\n\u001b[0;32m 1168\u001b[0m lock\u001b[38;5;241m.\u001b[39mrelease()\n\u001b[0;32m 1169\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_stop()\n",
|
342 |
+
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
|
343 |
+
]
|
344 |
+
}
|
345 |
+
],
|
346 |
+
"source": [
|
347 |
+
"df = load_data(real_audio_dir, fake_audio_dir, real_files, fake_files)"
|
348 |
+
]
|
349 |
+
},
|
350 |
+
{
|
351 |
+
"cell_type": "code",
|
352 |
+
"execution_count": null,
|
353 |
+
"metadata": {
|
354 |
+
"id": "3tLFhSuVJVRc"
|
355 |
+
},
|
356 |
+
"outputs": [],
|
357 |
+
"source": [
|
358 |
+
"df.tail()"
|
359 |
+
]
|
360 |
+
},
|
361 |
+
{
|
362 |
+
"cell_type": "code",
|
363 |
+
"execution_count": null,
|
364 |
+
"metadata": {
|
365 |
+
"id": "zMej7SKRJVRc"
|
366 |
+
},
|
367 |
+
"outputs": [],
|
368 |
+
"source": [
|
369 |
+
"# for file in file_names:\n",
|
370 |
+
"\n",
|
371 |
+
"# clean_file = file.split(\"/\")[-1]\n",
|
372 |
+
"# video_clip = VideoFileClip(file)\n",
|
373 |
+
"# audio = video_clip.audio\n",
|
374 |
+
"# fps = audio.fps\n",
|
375 |
+
"# audio_samples = np.array(list(audio.iter_frames(fps=fps, dtype=\"float32\"))).flatten()\n",
|
376 |
+
"# buffer = io.BytesIO()\n",
|
377 |
+
"# sf.write(buffer, audio_samples, fps, format='wav')\n",
|
378 |
+
"# buffer.seek(0)\n",
|
379 |
+
"# x, sr = librosa.load(buffer, sr=None)\n",
|
380 |
+
"# label = json.load(open(\"train_sample_videos/metadata.json\"))[clean_file]['label']\n",
|
381 |
+
"# new_row = pd.DataFrame([[clean_file] + get_features(x, sr) + [label]], columns=column_ames)\n",
|
382 |
+
"# df = pd.concat([df, new_row], ignore_index=True)"
|
383 |
+
]
|
384 |
+
},
|
385 |
+
{
|
386 |
+
"cell_type": "code",
|
387 |
+
"execution_count": null,
|
388 |
+
"metadata": {
|
389 |
+
"id": "BxacOcTrJVRc"
|
390 |
+
},
|
391 |
+
"outputs": [],
|
392 |
+
"source": [
|
393 |
+
"df.to_csv( \"/content/drive/MyDrive/SIH2024_DATASET/full_features.csv\", index=False)"
|
394 |
+
]
|
395 |
+
},
|
396 |
+
{
|
397 |
+
"cell_type": "code",
|
398 |
+
"execution_count": null,
|
399 |
+
"metadata": {
|
400 |
+
"id": "3PTTLrLhJVRc"
|
401 |
+
},
|
402 |
+
"outputs": [],
|
403 |
+
"source": []
|
404 |
+
}
|
405 |
+
],
|
406 |
+
"metadata": {
|
407 |
+
"colab": {
|
408 |
+
"provenance": []
|
409 |
+
},
|
410 |
+
"kernelspec": {
|
411 |
+
"display_name": "Python 3",
|
412 |
+
"name": "python3"
|
413 |
+
},
|
414 |
+
"language_info": {
|
415 |
+
"codemirror_mode": {
|
416 |
+
"name": "ipython",
|
417 |
+
"version": 3
|
418 |
+
},
|
419 |
+
"file_extension": ".py",
|
420 |
+
"mimetype": "text/x-python",
|
421 |
+
"name": "python",
|
422 |
+
"nbconvert_exporter": "python",
|
423 |
+
"pygments_lexer": "ipython3",
|
424 |
+
"version": "3.12.2"
|
425 |
+
}
|
426 |
+
},
|
427 |
+
"nbformat": 4,
|
428 |
+
"nbformat_minor": 0
|
429 |
+
}
|
features.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
ml_training.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
test.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import soundfile as sf
|
3 |
+
import librosa
|
4 |
+
import io
|
5 |
+
from moviepy.editor import VideoFileClip
|
6 |
+
from tensorflow.keras.models import load_model
|
7 |
+
|
8 |
+
def extract_frame_features(file_path, frame_duration=1.0):
|
9 |
+
video_clip = VideoFileClip(file_path)
|
10 |
+
audio = video_clip.audio
|
11 |
+
fps = audio.fps
|
12 |
+
audio_samples = np.array(
|
13 |
+
list(audio.iter_frames(fps=fps, dtype="float32"))
|
14 |
+
).flatten()
|
15 |
+
buffer = io.BytesIO()
|
16 |
+
sf.write(buffer, audio_samples, fps, format="wav")
|
17 |
+
buffer.seek(0)
|
18 |
+
x, sr = librosa.load(buffer, sr=None)
|
19 |
+
|
20 |
+
# Split audio into frames of 'frame_duration' seconds
|
21 |
+
frame_length = int(frame_duration * sr)
|
22 |
+
frames = []
|
23 |
+
timestamps = []
|
24 |
+
|
25 |
+
for i in range(0, len(x), frame_length):
|
26 |
+
if i + frame_length <= len(x):
|
27 |
+
# Extract MFCCs for each frame and store the timestamp
|
28 |
+
frame_mfcc = librosa.feature.mfcc(
|
29 |
+
y=x[i : i + frame_length], sr=sr, n_mfcc=20
|
30 |
+
)
|
31 |
+
frames.append(frame_mfcc)
|
32 |
+
timestamp = i / sr # Convert index to seconds
|
33 |
+
timestamps.append(timestamp)
|
34 |
+
|
35 |
+
return frames, timestamps
|
36 |
+
|
37 |
+
|
38 |
+
def test_on_video(file_path, frame_duration=1.0):
|
39 |
+
# Load the trained model
|
40 |
+
model = load_model("model/TCN.keras")
|
41 |
+
|
42 |
+
# Extract features and timestamps for each frame in the new video
|
43 |
+
frames, timestamps = extract_frame_features(file_path, frame_duration)
|
44 |
+
|
45 |
+
if frames is None or timestamps is None:
|
46 |
+
print("No frames extracted.")
|
47 |
+
return
|
48 |
+
|
49 |
+
# Reshape frames for model input
|
50 |
+
frames = np.array(frames)[..., np.newaxis]
|
51 |
+
|
52 |
+
# Predict on each frame
|
53 |
+
predictions = model.predict(frames)
|
54 |
+
pred_labels = np.argmax(predictions, axis=1)
|
55 |
+
|
56 |
+
# Store deepfake frames, their timestamps, and frame indices
|
57 |
+
deepfake_frames = []
|
58 |
+
deepfake_timestamps = []
|
59 |
+
deepfake_indices = []
|
60 |
+
|
61 |
+
# Identify deepfake frames
|
62 |
+
for i, label in enumerate(pred_labels):
|
63 |
+
if label == 1: # If the label is FAKE
|
64 |
+
deepfake_frames.append(frames[i])
|
65 |
+
deepfake_timestamps.append(timestamps[i])
|
66 |
+
deepfake_indices.append(i)
|
67 |
+
|
68 |
+
if not deepfake_frames:
|
69 |
+
print("No deepfake frames detected in the video.")
|
70 |
+
return
|
71 |
+
|
72 |
+
# Analyze deepfake frames
|
73 |
+
print(f"Found {len(deepfake_frames)} deepfake frames:")
|
74 |
+
for i, (timestamp, index) in enumerate(zip(deepfake_timestamps, deepfake_indices)):
|
75 |
+
print(f"Frame {index + 1} at {timestamp:.2f}s: FAKE")
|
76 |
+
|
77 |
+
|
78 |
+
# Example usage
|
79 |
+
test_video_path = r"FAKE\aapnvogymq.mp4" # Replace with your test video path
|
80 |
+
test_on_video(test_video_path)
|
y.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c33f0a69b3bda0a6b9d709ebd3c298fcf70a5dc3637059ce3c992a698f7e9819
|
3 |
+
size 11991
|
y_for_dl_2000.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7547dbf58339beaafcb6600307cd8bbce204aa46c3a4edfa5864eb043ca232e8
|
3 |
+
size 320002
|