libffcv / ffcv

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

Error while converting to torch image #166

Closed AmmaraRazzaq closed 2 years ago

AmmaraRazzaq commented 2 years ago

I am getting this error while converting an image to torch image

numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend) Failed in nopython mode pipeline (step: nopython frontend) Untyped global name 'self': Cannot determine Numba type of <class 'ffcv.transforms.ops.ToTorchImage'>

File "../../../../../miniconda3/envs/ffcv5/lib/python3.8/site-packages/ffcv/transforms/ops.py", line 88: def to_torch_image(inp: ch.Tensor, dst):

        # If channels last, it's already contiguous so we're good
        if self.channels_last:
        ^
loaders = {}
for name in ['train', 'val']:
    label_pipeline: List[Operation] = [NDArrayDecoder()]
    image_pipeline: List[Operation] = [SimpleRGBImageDecoder()]
    if name == 'train':
        image_pipeline.extend([
            ToTorchImage()
        ])

    # Create loaders
    loaders[name] = Loader(
        paths[f'{name}_beton_path'],
        batch_size=14,
        num_workers=6,
        order=OrderOption.RANDOM,
        drop_last=(name=='train'),
        pipelines={
            'image': image_pipeline,
            'label': label_pipeline
        }
    )
AmmaraRazzaq commented 2 years ago

It is fixed. Image had to be converted to tensor First.