fastai / fastai

The fastai deep learning library
http://docs.fast.ai
Apache License 2.0
26.34k stars 7.57k forks source link

dblock.dataloaders() - TypeError: 'L' object is not callable #3736

Open danielbellsa opened 2 years ago

danielbellsa commented 2 years ago

Goal: create a model using FastAI's DataBlock().

I want to create a DataBrick() based on documentation.

I think 'L' object refers to fastcore.foundation.L type.

How can I fix this?

Error occurs on:

return dblock.dataloaders()
import glob
from pathlib import Path

from fastai.data.all import *
from fastai.vision.all import *

def _label_func():
    return glob.glob('yasmine-sftp/Slides/*.svs.geojson')

def load(root: Path) -> DataBlock:
    batch_tfms = [aug_transforms(max_lighting=0.2),
                  aug_transforms(max_rotate=90),
                  aug_transforms(max_rotate=90, max_lighting=0.2),
                  aug_transforms(max_rotate=180),
                  aug_transforms(max_rotate=180, max_lighting=0.2),
                  aug_transforms(max_rotate=270),
                  aug_transforms(max_rotate=270, max_lighting=0.2)]

    dblock = DataBlock(get_items=get_image_files(str(root), recurse=True),
                       splitter=RandomSplitter(seed=42),
                       get_y=Pipeline(_label_func()),
                       batch_tfms=batch_tfms)  # <fastai.data.block.DataBlock object at 0x7fb91d79a400>

    return dblock.dataloaders(root, bs=16)

ROOT = Path('images/')  # Detection Folder
load(ROOT)

Traceback:

  File "/home/daniel/PycharmProjects/project/load_data.py", line 26, in <module>
    dblock.dataloaders(root, bs=16)  # <fastai.data.block.DataBlock object at 0x7fb91d79a400>
  File "/home/daniel/miniconda3/envs/venv/lib/python3.6/site-packages/fastai/data/block.py", line 113, in dataloaders
    dsets = self.datasets(source, verbose=verbose)
  File "/home/daniel/miniconda3/envs/venv/lib/python3.6/site-packages/fastai/data/block.py", line 107, in datasets
    items = (self.get_items or noop)(source) ; pv(f"Found {len(items)} items", verbose)
TypeError: 'L' object is not callable
bdsaglam commented 2 years ago

I think it's because of this line

    dblock = DataBlock(get_items=get_image_files(str(root), recurse=True),

get_items should be a function which takes root as an argument and returns items. Whereas, here it's a list.