Commit
·
efe22c5
1
Parent(s):
4f8c25a
[feat] - add utility
Browse files- utilities.py +44 -0
utilities.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
def main():
|
4 |
+
print("This is the main function of the utilities module.")
|
5 |
+
# Variables
|
6 |
+
totalFeatureCount = 0
|
7 |
+
totalJsonFileCount = 0
|
8 |
+
cnns = ['incp3', 'vgg19']
|
9 |
+
sources = ['full_movies', 'movie_shots', 'movie_trailers']
|
10 |
+
# Create the loop
|
11 |
+
for cnn in cnns:
|
12 |
+
for source in sources:
|
13 |
+
print(f"- Processing CNN: {cnn}, Source: {source}")
|
14 |
+
# Variables
|
15 |
+
featureCount = 0
|
16 |
+
jsonFileCount = 0
|
17 |
+
# Root directory
|
18 |
+
rootDir = f"{source}/{cnn}"
|
19 |
+
# Go through each folder in the root directory
|
20 |
+
for folder in os.listdir(rootDir):
|
21 |
+
movieFolder = os.path.join(rootDir, folder)
|
22 |
+
if os.path.isdir(movieFolder):
|
23 |
+
files = os.listdir(movieFolder)
|
24 |
+
jsonFileCount += len([f for f in files if f.endswith('.json')])
|
25 |
+
# Go inside each JSON file and count its inner items
|
26 |
+
for file in files:
|
27 |
+
if file.endswith('.json'):
|
28 |
+
jsonFilePath = os.path.join(movieFolder, file)
|
29 |
+
with open(jsonFilePath, 'r') as f:
|
30 |
+
data = f.read()
|
31 |
+
# Check the number of 'frameId' in the JSON file
|
32 |
+
featureCount += data.count('"frameId"')
|
33 |
+
# Print the results
|
34 |
+
print(f"-- Found {jsonFileCount} feature packets (JSON files) in {movieFolder}")
|
35 |
+
print(f"-- Found {featureCount} features embeddings in {movieFolder}")
|
36 |
+
# Update the total counts
|
37 |
+
totalFeatureCount += featureCount
|
38 |
+
totalJsonFileCount += jsonFileCount
|
39 |
+
# Print the total counts
|
40 |
+
print(f"Total feature embeddings count: {totalFeatureCount}")
|
41 |
+
print(f"Total feature packets (JSON files) count: {totalJsonFileCount}")
|
42 |
+
|
43 |
+
if __name__ == "__main__":
|
44 |
+
main()
|