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