-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflower_classifier.py
More file actions
26 lines (21 loc) · 1014 Bytes
/
flower_classifier.py
File metadata and controls
26 lines (21 loc) · 1014 Bytes
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
import os
import shutil
import scipy.io
# Load imagelabels.mat
mat_data = scipy.io.loadmat('imagelabels.mat')
labels = mat_data['labels'].flatten() # Ensure labels is a 1D array
# Path to the directory containing unlabeled images
unlabeled_directory = r'E:\Camera Roll\jpg' # Adjust the path to your images
# Assuming labels and image filenames are in the same order
for i, label in enumerate(labels):
numerical_label = str(label)
# Adjust the filename pattern based on your data
image_filename = f'image_{i + 1:05d}.jpg'
image_path = os.path.join(unlabeled_directory, image_filename)
# Check if the image file exists before moving
if os.path.exists(image_path):
category_directory = os.path.join(unlabeled_directory, numerical_label)
os.makedirs(category_directory, exist_ok=True)
# Move the labeled image to the corresponding directory
shutil.move(image_path, os.path.join(
category_directory, image_filename))