How to integrate with PyTorch DataLoaders
@jantonguirao 已經在處理了。
開始於 2024年10月29日。
評估
這個 Issue 還沒有評估資料。
描述
Describe the question.
Hi,
I'm hoping to integrate nvImageCode with PyTorch DataLoaders (torch utils DataLoader, or FFCV DataLoader, or LitData DataLoader), but I'm struggling.
If I include the decoder as a transform to be used in my dataset.__getitem__ method, I get the dreaded cudaErrorInitializationError:
RuntimeError: Unhandled CUDA error: cudaErrorInitializationError initialization error
class CustomDataSet(StreamingDataset):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.decoder = nvimgcodec.Decoder() # cudaErrorInitializationError
def __getitem__(self, idx):
sample = super().__getitem__(idx)
sample['image'] = self.decoder(sample['image'])
return sample
I can have my dataset return the raw image bytes, and apply the decoder to the list of bytes which is fast, but then I have to loop over items to transform them into pytorch tensors which is slow because it operates over the entire batch sequentially (not in parallel workers). This single step is slow enough that it negates the advantage of using the nvimgcodec.Decoder().
class CustomDataSet(StreamingDataset):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def __getitem__(self, idx):
sample = super().__getitem__(idx)
return sample
dataset = CustomDataSet(...)
dataloader = DataLoader(dataset, ...)
for batch in tqdm(dataloader):
imgs = decoder.decode(batch['image'])
imgs = [torch.tensor(img).moveaxis(-1,0) for img in imgs] # need to do this in the worker processes
I also tried to have my dataset return decode sources with ROIs, but this fails because DecodeSource is not pickleable.
class CustomDataset(StreamingDataset):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def __getitem__(self, idx):
sample = super().__getitem__(idx) # <- Whatever you returned from the DatasetOptimizer prepare_item method.
roi = nvimgcodec.Region(0, 0, 224, 224) # replace with random crop later...
sample['image'] = nvimgcodec.DecodeSource(sample['image'], roi)
return sample
In any case, I've checked open bugs/issues, and the docs, and I can't find a good example of using nvimgcodec in the context of a dataloader with parallel workers. Any guidance or suggestions for how to handle this would be greatly appreciated.
Check for duplicates
- I have searched the open bugs/issues and have found no duplicates for this bug report
- 主要語言
- Jupyter Notebook
- 星號
- 164
- 分支
- 26
- 平均合併
- 27 分鐘
- 30 天內合併 PR
- 1
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
NVIDIA/nvImageCodec 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 79/100
NVIDIA/nvImageCodec#65 · 1 則留言 ·
-
難度 3/5 1-2 天 新手友好度 72/100
NVIDIA/nvImageCodec#66 · 1 則留言 ·
-
難度 5/5 一週以上 新手友好度 38/100
NVIDIA/nvImageCodec#64 ·
-
nvjpeg2k error 3 (Bad jpeg) on valid JPEG 2000 aerial photos that OpenJPEG and ffmpeg decode identically可能已有人在做 @mkepa-nv 於 6 天前認領。 未關閉bug
NVIDIA/nvImageCodec#63 · 2 則留言 · 已指派 1 人 ·
-
難度 5/5 一週以上 新手友好度 8/100
NVIDIA/nvImageCodec#60 ·