Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
from deepface import DeepFace
import os
import pandas as pd
# Load the CSV file
csv_file_path = 'train.csv'
df = pd.read_csv(csv_file_path)
# Specify the directory path to your folder with images
folder_path = 'train\\train\\'
# Dictionary to keep track of how many times each category has been used
category_counts = {}
# Loop through the dataframe and rename files
for index, row in df.iterrows():
current_name = row['File Name']
category = row['Category']
# Update category count
if category in category_counts:
category_counts[category] += 1
else:
category_counts[category] = 1
# Generate new file name
new_name = f"{category}_{category_counts[category]}.jpg"
# Full path for current and new file names
current_file_path = os.path.join(folder_path, current_name)
new_file_path = os.path.join(folder_path, new_name)
# Rename file
os.rename(current_file_path, new_file_path)
# Note: This script assumes all images are in '.jpg' format. Adjust the extension as needed.
image_names = []
for filename in os.listdir(folder_path):
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
image_names.append(filename)
print(image_names)
""" dfs = DeepFace.find(img_path = "test\\test\\0.jpg", db_path = "train_small\\train_small\\", enforce_detection= True)
print(dfs) """