libffcv / ffcv

FFCV: Fast Forward Computer Vision (and other ML workloads!)
https://ffcv.io
Apache License 2.0
2.8k stars 180 forks source link

ffcv with torch.Tensor #244

Open rahimentezari opened 1 year ago

rahimentezari commented 1 year ago

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)`
andrewilyas commented 1 year ago

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