
0. Pre-requisites
python 기초
[Summary] Python 정리
Programming Language and Python 소개2023.10.23 - [Python] - [Python] Programming Language and Introduction of Python. [Python] Programming Language and Introduction of Python.Computer and Programhttps://dsaint31.tistory.com/436: computer 의 정의와 pr
ds31x.tistory.com
colab 다루기
https://dsaint31.me/mkdocs_site/CE/colab/hw_spec/
BME
colab ipynb ipython jupyter notebook Colab이란 Google Colaboratory = Google Drive + Jupyter Notebook 구글 계정 전용의 가상 머신 지원 – GPU 및 TPU를 제공 Google drive 문서와 같이 링크만으로 접근 가능: 공동작업 가능 J
dsaint31.me
Tensor 다루기
[DL] Tensor 다루기 기초 - PyTorch 중심
https://dsaint31.tistory.com/891 [ML] Tensor: Scalar, Vector, Matrix.Tensor 종류1. Scalar (0차원 tensor)하나의 숫자로 표현되는 가장 기본적인 형태.크기(magnitude)만을 가지며 방향은 없음.예시: 온도(25°C), 나이(20),
ds31x.tistory.com
Image에 대한 정의, DIP와 CV등의 개념 정리
https://dsaint31.tistory.com/790
[CV] DIP, Image Analysis, and Computer Vision
Image Processing과 Computer Vision(CV)은 상당 부분 겹쳐있으며, 명확하게 구분하기 어려운 분야들임. 이 두 분야는 연속선상에 있으며, 상당히 경계가 모호함. 공통적으로 두 분야 모두linear algebra, probabi
dsaint31.tistory.com
1. Image 열고 저장하기
ML에서 주로 사용되는 Image처리 관련 라이브러리는 pillow, openCV, scikit-image가 있음: torch에선 pillow기반 (cpu기준).
PIL, Pillow, OpenCV, and Scikit-image
[Python] PIL, Pillow, OpenCV, and Scikit-image
PIL, Pillow, OpenCV, and Scikit-imagePython에서 이미지를 다룰 때 이용되는 주요 패키지들은 다음과 같음.1.PIL (Python Imaging Library)PIL은 1995년에 처음 개발(Fredrik Lundh)된 Python의 최초 이미지 처리 라이브러리
ds31x.tistory.com
연구 분야에선 scikit-image도 꽤나 많이 사용되므로 기본적인 부분은 알고 있어야 함.
scikit-image: Image Load, Save, Display
scikit-image: Image Load, Save, Display
이 문서는 scikit-image (skimage) 를 사용해이미지를 읽고(imread), 저장(imsave)하고, 표시(plt.imshow)하는 방법을 설명함.https://gist.github.com/dsaint31x/9c2c9d9cf91594a0180bdd222373820b scikit-image Image Load, Save, Display.ipyn
ds31x.tistory.com
pillow(~PIL)는 전용 클래스로 image를 추상화하지만, openCV와 scikit-image, 그리고 torch등은 cpu에서는 NumPy의 ndarray로 image를 추상화한다. 이들간의 변환은 매우 간단함.
https://dsaint31.tistory.com/236
PIL과 opencv에서의 image 변환.
PIL과 opencv에서의 image 변환.필요성tensorflow 나 pytorch등에서의 이미지 로딩의 경우,일반적으로, PIL.Image.Image를 기본적으로 이미지를 위한 class 타입으로 사용함.from tensorflow.keras.preprocessing import image
dsaint31.tistory.com
일반적으로 pillow의 Image 객체에서 Tensor로 변환하지만, 직접 이미지 파일에서 Tensor를 얻을 수도 있음.
[torchvision] image로부터 torch.tensor 객체 얻기
[torchvision] image로부터 torch.tensor 객체 얻기
0. torchvision.io.read_image torchvision.io.read_image는 현재 Obsolete 상태로 유지되고 있으며, 파일 경로나 raw byte 데이터 모두를 처리할 수 있는 decode_image가 공식적으로 권장되는 이미지 로딩 API임.더보기obs
ds31x.tistory.com
저장도 pillow를 거치는 방식이 보다 일반적이나 Tensor에서 직접 저장도 가능하다.
[torchvision] torchvision.utils.save_image and torchvision.io.encode_jpeg, torchvision.io.encode_png
[torchvision] torchvision.utils.save_image and torchvision.io.encode_jpeg, torchvision.io.encode_png
주로 다음의 3가지를 개인적으로 사용함.save_image: 파일 직접 저장, 배치 그리드 배열, 정규화/시각화 기능 내장encode_jpeg: 손실 압축, 더 작은 파일 크기, RGB/Grayscale만 지원encode_png: 무손실 압축, 더
ds31x.tistory.com
torch를 사용한 기계학습이나 딥러닝에선 이들을 사용하여 이미지 파일을 로딩하지만,
이들의 API를 직접 이용하기 보다는 torch 또는 torchvision에서 제공하는 다양한 Dataset 클래스를 통해 로딩을 수행한다.
특히 모델 학습에선 절대적으로 Dataset과 DataLoader의 사용을 통해 이미지 로딩이 수행됨
[PyTorch] Dataset and DataLoader
[PyTorch] Dataset and DataLoader
1. Dataset 이란 : PyTorch 의 tensor 와학습에 사용될 일반 raw data (흔히, storage에 저장된 파일들) 사이에 위치하며,raw-data로부터 PyTorch의 module 객체 등이 접근가능한 데이터 셋을 추상화한 객체를 얻게
ds31x.tistory.com
2. image 기반의 Dataset - VisionDataset ( vision task를 위한 base class )
torchvision은 Dataset을 확장하여 transform, target_transform, transforms 등 vision 관련 변환 처리를 표준화한 VisionDataset을 제공하고, 이를 상속하여 다양한 실제 Dataset 구현 클래스들을 함께 제공한다.
분류(Classification) 작업의 대표적인 예로는 ImageFolder가 있으며, 객체 검출(Object Detection)의 경우 CocoDetection, 분할(Segmentation) 작업의 경우 VOCSegmentation, Cityscapes 등이 대표적이다.
Classification을 위한 Dataset:
torchvision.datasets.ImageFolder 사용하기.
torchvision.datasets.ImageFolder 사용하기.
torchvision.datasets.ImageFolder는 PyTorch에서 Image Classification Task를 위한 Dataset을 쉽게 구성할 수 있게 해주는 클래스임. 정확한 Full qualified name은 torchvision.datasets.folder.ImageFolder 임: torchvision.datasets 에 reex
ds31x.tistory.com
Object Detection 을 위한 Dataset:
( 4번의 실습 항목의 MS COCO를 읽고나서 볼 것.)
torchvision.datasets.CocoDetection 간단 소개.
torchvision.datasets.CocoDetection 간단 소개.
소개torchvision.datasets.CocoDetection은 PyTorch에서 MS COCO 데이터셋을 기반으로 Object Detection Task 모델 개발을 위한 Dataset 클래스임. 다음의 상속 관계를 가짐:torch.utils.data.Dataset ↑torchvision.datasets.vision.Vis
ds31x.tistory.com
3. torchvision.transforms 모듈: 영상처리 구현물
Image에 대한 처리는 주로 torchvision.transforms 모듈에 클래스와 함수 형태로 구현되어 제공된다.
torch를 기반으로 한 기계학습 및 딥러닝 학습 파이프라인에서는, 기존의 OpenCV, Pillow, scikit-image와 같은 범용 영상 처리 라이브러리보다 torchvision.transforms 모듈을 사용하는 것이 일반적이다. 이는
Dataset–DataLoader 구조 및 Tensor 기반 연산과 자연스럽게 연동되기 때문이다.
다음 글에서 torch를 이용한 ML 및 딥러닝 환경에서 영상 처리를 담당하는 torchvision.transforms의 개념과 사용법을 소개한다.
[Python] - [PyTorch] torchvision.transforms 사용법 - transforms란?
[PyTorch] torchvision.transforms 사용법 - transforms란?
PyTorch의 torchvision.transforms:이미지 전처리와 데이터 증강을 위한 도구torchvision.transforms는PyTorch에서 제공하는 이미지 전처리 및 data augmentation을 위한 module.이 모듈은 이미지 데이터를 이용한 딥러
ds31x.tistory.com
참고로, 현재는 torchvision.transforms 보다는 그의 submodule인 v2 사용을 보다 권장한다.
모듈화로 만드는 건 class 방식의 transforms가 낫지만 내부 구현의 경우엔 functional 모듈의 함수들이 보다 많이 애용된다.
다음은 v2 서브모듈을 구성하는 class와 function, kernel에 대한 소개임.
[Python] - [torchvision] transforms.v2, transforms.v2.functional, 그리고 kernel
[torchvision] transforms.v2, transforms.v2.functional, 그리고 kernel
torchvision.transforms는 PyTorch에서 제공하는 이미지 preprocessing 및 data augmentation을 위한 module. 이 모듈은 현재 v2 서브모듈의 사용을 권함:v2 transforms는 image뿐만 아니라bounding boxes, masks, videos도 변환할
ds31x.tistory.com
보다 자세한 내용은 다음을 참고하라.
[Python] - [PyTorch] torchvision.transforms.v2 - Summary (작성중)
[PyTorch] torchvision.transforms.v2 - Summary (작성중)
다음의 공식문서를 기반으로 정리한 것임.https://docs.pytorch.org/vision/main/auto_examples/transforms/plot_transforms_illustrations.html#sphx-glr-auto-examples-transforms-plot-transforms-illustrations-py Illustration of transforms — Torch
ds31x.tistory.com
4. 실습
Object Detection을 해본다.
가장 널리 사용되는 COCO의 구조를 이용하여 Object Detection Model을 훈련 시키는 예제로, 중점을 둔 것은 v2의 transforms를 이용한 composit input 에 기하학적 변환의 적용 및 COCO API를 통한 evaluation 임.
MS COCO (Microsoft의 Common Object in Context) Dataset
MS COCO (Microsoft의 Common Object in Context) Dataset
COCO 데이터셋은 여러 종류의 task 에 대한 모델을 훈련시킬 수 있음: 다음의 task들로 구분됨.1. Object Detection (객체 탐지)목적: 이미지 안에 있는 객체의 location 과 class (=category)를 추출 : things만annotat
ds31x.tistory.com
pycocotools COCO API 기초
pycocotools COCO API에서 자주 쓰는 메서드들에 대한 정리:getAnnIdsgetCatIdsgetImgIdsloadAnnsloadCatsloadImgsloadResshowAnns2025.12.16 - [ML] - MS COCO (Microsoft의 Common Object in Context) Dataset MS COCO (Microsoft의 Common Object in Cont
ds31x.tistory.com
다음은 Object Detection을 위한 toy COCO dataset임
실습 gist
위의 toy_coco_shapes.zip을 사용하여 다음의 gist를 수행시켜보자.
https://gist.github.com/dsaint31x/56feffe9b8c7f039e24ec429ebe089ab
dl_COCO_Detection_Simple_Example.ipynb
dl_COCO_Detection_Simple_Example.ipynb. GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
같이 보면 좋은 자료들
2025.06.17 - [분류 전체보기] - (바이오) 영상처리 실습 (20250618)
(바이오) 영상처리 실습 (20250618)
0. Prerequisitestensor 및 관련 기초내용 참고자료.더보기Colab 다루기https://dsaint31.me/mkdocs_site/CE/colab/hw_spec/ BMEColab이란 Google Colaboratory = Google Drive + Jupyter Notebook 구글 계정 전용의 가상 머신 지원 – GPU
ds31x.tistory.com
'Pages' 카테고리의 다른 글
| [Python] String : 문자열 (1) | 2023.10.06 |
|---|---|
| [Python] Control Structure and Control Flow (1) | 2023.10.06 |
| [Python] function 과 Scope, Name Space 정리 - Summary (0) | 2023.10.06 |
| [Python] Collections (0) | 2023.10.06 |
| Shell 관련 정리 (0) | 2023.10.02 |