MoViFex_Dataset / utilities.py
alitourani's picture
[feat] - add utility
efe22c5
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()