ffcv icon indicating copy to clipboard operation
ffcv copied to clipboard

ffcv with torch.Tensor

Open rahimentezari opened this issue 2 years ago • 1 comments

Hi I have a dataset in the form of 'torch.Tensor' and was wondering how to use the DatasetWriter? I am trying to use FFCV for SimCLR, where dataset is torch.utils.data.Dataset, including pairs of augmented images in tensor.

I tried different options like RGBImageFields but this does not work as the inputs are tensors, not images, getting this error TypeError: Unsupported image type <class 'torch.Tensor'>

writer = DatasetWriter(write_path, { 'image': RGBImageField(), # 'image': FloatField(), # 'image':NDArrayField(shape=(2,), dtype=np.dtype('float64')), 'label': IntField() }, num_workers=16)

rahimentezari avatar Jul 31 '22 14:07 rahimentezari

Hi @rahimentezari ! Sorry for the very late response -- you should use the NDArrayField and convert the torch tensors to numpy arrays with .numpy().

andrewilyas avatar Feb 28 '23 17:02 andrewilyas