728x90
반응형
class RawDataset(Dataset):
def __init__(self, root):
self.rgb = True
self.image_path_list = []
for dirpath, dirnames, filenames in os.walk(root, followlinks=True):
for name in filenames:
_, ext = os.path.splitext(name)
ext = ext.lower()
if ext == ".jpg" or ext == ".jpeg" or ext == ".png":
self.image_path_list.append(os.path.join(dirpath, name))
self.image_path_list = natsorted(self.image_path_list)
self.nSamples = len(self.image_path_list)
def __len__(self):
return self.nSamples
def __getitem__(self, index):
img = np.array(Image.open(self.image_path_list[index]).convert("RGB")) # for color image
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_gray = np.dstack([img_gray,img_gray,img_gray])
pil_image = Image.fromarray(img_gray)
return (pil_image, self.image_path_list[index])
728x90
반응형
'머신러닝 > Computer Vision' 카테고리의 다른 글
[cv2] image input 3-channel Grayscale (0) | 2023.09.14 |
---|---|
[cv2] rotated text(box) image cropping (0) | 2023.09.01 |
[Python/PIL] 텍스트에 취소선 넣기 (0) | 2023.05.04 |
PIL Image Font 속성 (0) | 2023.04.27 |
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 16 but got size 15 for tensor number 1 in the list. / CV모델 image input size 조정 (0) | 2023.04.18 |