mirror of
https://github.com/azaion/ai-training.git
synced 2026-04-23 10:06:36 +00:00
Made some changes
This commit is contained in:
+64
-23
@@ -1,17 +1,14 @@
|
|||||||
|
import math
|
||||||
|
import datetime
|
||||||
import cv2
|
import cv2
|
||||||
import albumentations as A
|
import albumentations as A
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
file_txt = []
|
def file_magnification(folder_path):
|
||||||
file_jpg = []
|
file_txt = []
|
||||||
|
file_jpg = []
|
||||||
folder_path = ('D:\\train')
|
|
||||||
for foldername, subfolders, filenames in os.walk(folder_path):
|
|
||||||
for subfolder in subfolders:
|
|
||||||
folder_path = (f'D:\\train\\{subfolder}')
|
|
||||||
for foldername, subfolders, filenames in os.walk(folder_path):
|
for foldername, subfolders, filenames in os.walk(folder_path):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
|
|
||||||
f = filename.split('.')
|
f = filename.split('.')
|
||||||
|
|
||||||
if f[-1] == 'txt':
|
if f[-1] == 'txt':
|
||||||
@@ -19,13 +16,12 @@ for foldername, subfolders, filenames in os.walk(folder_path):
|
|||||||
elif f[-1] == 'jpg':
|
elif f[-1] == 'jpg':
|
||||||
file_jpg.append(filename)
|
file_jpg.append(filename)
|
||||||
|
|
||||||
for k in range(len(file_jpg)):
|
for k in range(len(file_jpg)):
|
||||||
image = cv2.imread(f'D:\\train\\images\\{file_jpg[k]}')
|
image = cv2.imread(f'{folder_path}\\{file_jpg[k]}')
|
||||||
annotations = []
|
annotations = []
|
||||||
with open(f'D:\\train\\labels\\{file_txt[k]}', 'r') as file:
|
with open(f'{folder_path}\\{file_txt[k]}', 'r') as file:
|
||||||
lines = file.readlines()
|
lines = file.readlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
print(line)
|
|
||||||
annotations.append(line)
|
annotations.append(line)
|
||||||
|
|
||||||
|
|
||||||
@@ -35,9 +31,7 @@ for k in range(len(file_jpg)):
|
|||||||
print(annotations)
|
print(annotations)
|
||||||
for ii in range(len(annotations)):
|
for ii in range(len(annotations)):
|
||||||
a = annotations[ii].split(' ')
|
a = annotations[ii].split(' ')
|
||||||
|
|
||||||
for i in range(len(a)):
|
for i in range(len(a)):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
main_fillet_yolo_conversion.append(int(a[i]))
|
main_fillet_yolo_conversion.append(int(a[i]))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@@ -46,16 +40,9 @@ for k in range(len(file_jpg)):
|
|||||||
fillet_yolo_class.append(main_fillet_yolo_conversion[0])
|
fillet_yolo_class.append(main_fillet_yolo_conversion[0])
|
||||||
del main_fillet_yolo_conversion[0]
|
del main_fillet_yolo_conversion[0]
|
||||||
fillet_yolo_bboxes.append(main_fillet_yolo_conversion)
|
fillet_yolo_bboxes.append(main_fillet_yolo_conversion)
|
||||||
print(fillet_yolo_bboxes)
|
|
||||||
print(fillet_yolo_class)
|
|
||||||
main_fillet_yolo_conversion = []
|
main_fillet_yolo_conversion = []
|
||||||
|
|
||||||
for o in range(10):
|
for o in range(10):
|
||||||
if image is None:
|
|
||||||
raise ValueError("Image not found or the path is incorrect")
|
|
||||||
if not isinstance(image, np.ndarray):
|
|
||||||
raise TypeError("Image must be a numpy array")
|
|
||||||
|
|
||||||
bboxes = fillet_yolo_bboxes
|
bboxes = fillet_yolo_bboxes
|
||||||
category_ids = fillet_yolo_class
|
category_ids = fillet_yolo_class
|
||||||
|
|
||||||
@@ -70,9 +57,63 @@ for k in range(len(file_jpg)):
|
|||||||
transformed_bboxes = transformed['bboxes']
|
transformed_bboxes = transformed['bboxes']
|
||||||
transformed_category_ids = transformed['category_ids']
|
transformed_category_ids = transformed['category_ids']
|
||||||
|
|
||||||
cv2.imwrite(f'D:\\python\\prodgect_2\\pythonProject1\\op\\1\\{o}_{file_jpg[k]}', transformed_image)
|
cv2.imwrite(f'{folder_path}\\{o}_{file_jpg[k]}', transformed_image)
|
||||||
with open(f'D:\\python\\prodgect_2\\pythonProject1\\op\\1\\{o}_{file_txt[k]}', 'w') as f:
|
with open(f'{folder_path}\\{o}_{file_txt[k]}', 'w') as f:
|
||||||
for bbox, category_id in zip(transformed_bboxes, transformed_category_ids):
|
for bbox, category_id in zip(transformed_bboxes, transformed_category_ids):
|
||||||
x_center, y_center, width, height = bbox
|
x_center, y_center, width, height = bbox
|
||||||
cla = category_id
|
cla = category_id
|
||||||
f.write(f"{cla} {x_center} {y_center} {width} {height}\n")
|
f.write(f"{cla} {x_center} {y_center} {width} {height}\n")
|
||||||
|
file_txt_1 = []
|
||||||
|
file_jpg_1 = []
|
||||||
|
file_start = 'Zombobase-'+str(datetime.date.today())
|
||||||
|
folder_path = ('train')
|
||||||
|
for foldername, subfolders, filenames in os.walk(folder_path):
|
||||||
|
for subfolder in subfolders:
|
||||||
|
folder_path = (f'train\\{subfolder}')
|
||||||
|
for foldername, subfolders, filenames in os.walk(folder_path):
|
||||||
|
for filename in filenames:
|
||||||
|
|
||||||
|
f = filename.split('.')
|
||||||
|
|
||||||
|
if f[-1] == 'txt':
|
||||||
|
file_txt_1.append(filename)
|
||||||
|
elif f[-1] == 'jpg':
|
||||||
|
file_jpg_1.append(filename)
|
||||||
|
|
||||||
|
annotations = []
|
||||||
|
os.makedirs(file_start)
|
||||||
|
file = ['test', 'train']
|
||||||
|
percent_fille = [0.20,0.10]
|
||||||
|
for fi, p_f in zip(file, percent_fille):
|
||||||
|
os.makedirs(f'{file_start}\\{fi}')
|
||||||
|
|
||||||
|
for i in range(math.ceil(len(file_txt_1)* p_f)):
|
||||||
|
image = cv2.imread(f'D:\\train\\images\\{file_jpg_1[i]}')
|
||||||
|
with open(f'D:\\train\\labels\\{file_txt_1[i]}', 'r') as file:
|
||||||
|
lines = file.readlines()
|
||||||
|
for line in lines:
|
||||||
|
annotations.append(line)
|
||||||
|
cv2.imwrite(f'{file_start}\\{fi}\\{file_jpg_1[i]}', image)
|
||||||
|
with open(f'{file_start}\\{fi}\\{file_txt_1[i]}', 'w') as f:
|
||||||
|
for iii in range(len(annotations)):
|
||||||
|
f.write(annotations[iii])
|
||||||
|
|
||||||
|
annotations = []
|
||||||
|
del file_txt_1[i]
|
||||||
|
del file_jpg_1[i]
|
||||||
|
|
||||||
|
os.makedirs(f'{file_start}\\validation')
|
||||||
|
for a, j in zip(file_txt_1, file_jpg_1):
|
||||||
|
image = cv2.imread(f'D:\\train\\images\\{j}')
|
||||||
|
with open(f'D:\\train\\labels\\{a}', 'r') as file:
|
||||||
|
lines = file.readlines()
|
||||||
|
for line in lines:
|
||||||
|
annotations.append(line)
|
||||||
|
cv2.imwrite(f'{file_start}\\Validation\\{j}', image)
|
||||||
|
with open(f'{file_start}\\Validation\\{a}', 'w') as f:
|
||||||
|
for iii in range(len(annotations)):
|
||||||
|
f.write(annotations[iii])
|
||||||
|
annotations = []
|
||||||
|
file = ['test', 'train','validation']
|
||||||
|
for i in file:
|
||||||
|
file_magnification(f'{file_start}\\{i}')
|
||||||
Reference in New Issue
Block a user