forked from amd/RyzenAI-SW
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassification_utils.py
More file actions
68 lines (49 loc) · 2.12 KB
/
Copy pathclassification_utils.py
File metadata and controls
68 lines (49 loc) · 2.12 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from pathlib import Path
import sys
import os
import shutil
def get_directories():
current_dir = Path(__file__).resolve().parent
# models directory for resnet sample
models_dir = current_dir / "models"
models_dir.mkdir(parents=True, exist_ok=True)
return current_dir, models_dir
def calib_data_formatting():
source_folder = 'val_images'
calib_data_path = 'calib_data'
if not os.path.exists(source_folder):
print("The provided data path does not exist.")
sys.exit(1)
files = os.listdir(source_folder)
for filename in files:
if not filename.startswith('ILSVRC2012_val_') or not filename.endswith(
'.JPEG'):
continue
n_identifier = filename.split('_')[-1].split('.')[0]
folder_name = n_identifier
folder_path = os.path.join(source_folder, folder_name)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
file_path = os.path.join(source_folder, filename)
destination = os.path.join(folder_path, filename)
shutil.move(file_path, destination)
print("File organization complete.")
if not os.path.exists(calib_data_path):
os.makedirs(calib_data_path)
destination_folder = calib_data_path
subfolders = os.listdir(source_folder)
for subfolder in subfolders:
source_subfolder = os.path.join(source_folder, subfolder)
destination_subfolder = os.path.join(destination_folder, subfolder)
os.makedirs(destination_subfolder, exist_ok=True)
files = os.listdir(source_subfolder)
if files:
file_to_copy = files[0]
source_file = os.path.join(source_subfolder, file_to_copy)
destination_file = os.path.join(destination_subfolder, file_to_copy)
shutil.copy(source_file, destination_file)
print("Creating calibration dataset complete.")