Files
hpos-data/scripts/image_class_subfolder.py
Pritimay Sarkar 7bcdbff123 14 dec data
2023-12-14 21:03:09 +05:30

24 lines
787 B
Python

import os
import shutil
import pandas as pd
# Assuming you have a DataFrame named df with columns 'id', 'class', and 'image_path'
# 'image_path' should contain the path to each image
# Example DataFrame creation (replace this with your actual data)
data = {'id': [1, 2, 3],
'class': ['A', 'B', 'A'],
'image_path': ['/path/to/img1.jpg', '/path/to/img2.jpg', '/path/to/img3.jpg']}
df = pd.DataFrame(data)
# Iterate through rows and move images
for index, row in df.iterrows():
class_folder = os.path.join(os.getcwd(), row['class'])
# Create subfolder if it doesn't exist
if not os.path.exists(class_folder):
os.makedirs(class_folder)
# Move image to subfolder
shutil.move(row['_id'], os.path.join(class_folder, f"{row['id']}.jpg"))