2023-01-29 22:18:19 +01:00
|
|
|
import numpy as np
|
|
|
|
import os
|
|
|
|
from skimage.io import imread
|
|
|
|
import cv2 as cv
|
|
|
|
from pathlib import Path
|
|
|
|
|
2023-01-29 23:18:50 +01:00
|
|
|
|
2023-02-01 19:55:12 +01:00
|
|
|
def load_source(filename: str) -> np.ndarray:
|
|
|
|
return cv.imread(filename)[..., ::-1]
|
|
|
|
|
|
|
|
|
|
|
|
def load_data(input_dir):
|
2023-01-29 22:18:19 +01:00
|
|
|
image_path = Path(input_dir)
|
|
|
|
file_names = os.listdir(image_path)
|
|
|
|
categories_name = []
|
2023-01-29 23:18:50 +01:00
|
|
|
categories_count = []
|
2023-01-29 22:18:19 +01:00
|
|
|
count = 0
|
|
|
|
n = file_names[0]
|
|
|
|
for name in file_names:
|
|
|
|
if name != n:
|
|
|
|
categories_count.append(count)
|
|
|
|
n = name
|
|
|
|
count = 1
|
|
|
|
else:
|
|
|
|
count += 1
|
|
|
|
if not name in categories_name:
|
|
|
|
categories_name.append(name)
|
|
|
|
categories_count.append(count)
|
|
|
|
test_img = []
|
2023-01-29 23:18:50 +01:00
|
|
|
labels = []
|
2023-01-29 22:18:19 +01:00
|
|
|
|
|
|
|
for n in file_names:
|
|
|
|
p = image_path / n
|
2023-02-01 19:55:12 +01:00
|
|
|
img = load_source(str(p)) # zwraca ndarry postaci xSize x ySize x colorDepth
|
2023-01-29 22:18:19 +01:00
|
|
|
test_img.append(img)
|
|
|
|
labels.append(n)
|
|
|
|
|
2023-01-29 23:18:50 +01:00
|
|
|
X = {}
|
2023-01-29 22:18:19 +01:00
|
|
|
X["values"] = np.array(test_img)
|
2023-01-29 23:18:50 +01:00
|
|
|
X["name"] = categories_name
|
|
|
|
X["names_count"] = categories_count
|
|
|
|
X["labels"] = labels
|
|
|
|
return X
|