Nvidia 에서 만든 data loading library인 DALI 공부 중
n년전 pytorch가 그랬듯, 툴 자체는 좋아보이는데 아직 사용자가 많지 않은지 error에 대한 정보를 얻기가 힘들다 ㅜ
일단 현재까지 파악한 건,
- TF 처럼 define and run 구조. -> 따라서 random 성이 있는 모듈은 구현되어 있지 않음
- pipe를 define할때는 transform을 추가하고, run할 때 transform에 들어갈 변수들을 parameter로 전달
ex. define할때 crop이 들어가면 run할때 crop size를 넣어줌
=> 기본적으론 아래와 같이 돌아가고, custom dataset에서는 어떻게 줘야하는지 자꾸 오류가 나서
일단 Nvidia측에서 제공하는 dataset으로 이것저것 실험 중
=> ToDo: crop 등등 transform하기 / CPU, GPU Mixed 성능비교하기 / torch랑 학습 시간 비교하기
DALI 공식문서
https://docs.nvidia.com/deeplearning/dali/user-guide/docs/
NVIDIA DALI Documentation — NVIDIA DALI 1.18.0 documentation
Multiple data formats support - LMDB, RecordIO, TFRecord, COCO, JPEG, JPEG 2000, WAV, FLAC, OGG, H.264, VP9 and HEVC.
docs.nvidia.com
Nvidia에서 DALI repo에 제공하는 dataset
https://github.com/NVIDIA/DALI/tree/main/docs/examples/data/images
GitHub - NVIDIA/DALI: A GPU-accelerated library containing highly optimized building blocks and an execution engine for data pro
A GPU-accelerated library containing highly optimized building blocks and an execution engine for data processing to accelerate deep learning training and inference applications. - GitHub - NVIDIA/...
github.com
# 돌리는데 성공한거
def simple_mixed_pipeline():
jpegs, labels = fn.readers.file(file_root=data_dir)
images = fn.decoders.image(jpegs, device="mixed")
return images, labels
if __name__ == "__main__":
pipe = simple_mixed_pipeline(batch_size=8, num_threads=2, device_id=0)
start = time()
pipe.build()
pipe_out = pipe.run()
end = time()
print(pipe_out)
# 앞으로 돌려봐야할 것
from nvidia.dali.pipeline import Pipeline
from nvidia.dali import pipeline_def
import nvidia.dali.fn as fn
import nvidia.dali.types as types
from nvidia.dali.plugin.pytorch import DALIGenericIterator
import torchvision.models as models
resnet18 = models.resnet18()
from time import time
data_dir = "./test_DALI/images/"
@pipeline_def(batch_size=128, num_threads=4, device_id=0)
def get_dali_pipeline(data_dir, crop_size):
images, labels = fn.readers.file(file_root=data_dir)
# decode data on the GPU
images = fn.decoders.image_random_crop(images, device="mixed", output_type=types.RGB)
# the rest of processing happens on the GPU as well
images = fn.resize(images, resize_x=crop_size, resize_y=crop_size)
images = fn.crop_mirror_normalize(images,
mean=[0.485 * 255,0.456 * 255,0.406 * 255],
std=[0.229 * 255,0.224 * 255,0.225 * 255],
mirror=fn.random.coin_flip())
return images, label
train_data = DALIGenericIterator(
[get_dali_pipeline(data_dir, (224, 224))], ['data', 'label'], reader_name='Reader')
for i, data in enumerate(train_data):
x, y = data[0]['data'], data[0]['label']
pred = resnet18(x)
# loss = loss_func(pred, y)
# backward(loss, model)
'Code 공부 > tool 및 code 실행법' 카테고리의 다른 글
[환경세팅] pytorch3d 가상환경 세팅 시 trial and error 로그 (1) | 2023.04.20 |
---|---|
[tensorboard] linux 원격 server에서 킨 tensorboard window local에서 사용하기 (0) | 2022.10.21 |
[python] import 상대경로 한번에 해결하기 (0) | 2022.07.13 |
[vim 팁] vim 사용 시 indentation 자동으로 맞추기 (0) | 2022.04.03 |
[python] 문자열 접미사 다루기 (0) | 2022.03.22 |