How to use the fastai.vision.ImageList.from_folder function in fastai

To help you get started, we’ve selected a few fastai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fastai / fastai / tests / test_data_block.py View on Github external
def test_wrong_order():
    this_tests('na')
    path = untar_data(URLs.MNIST_TINY)
    with pytest.raises(Exception, match="Your data isn't split*"):
        ImageList.from_folder(path).label_from_folder().split_by_folder()
github microsoft / computervision-recipes / tests / unit / classification / test_classification_model.py View on Github external
def tiny_ic_data(tiny_ic_data_path):
    """ Returns tiny ic data bunch """
    return (
        ImageList.from_folder(tiny_ic_data_path)
        .split_by_rand_pct(valid_pct=0.2, seed=10)
        .label_from_folder()
        .transform(size=299)
        .databunch(bs=16)
        .normalize(imagenet_stats)
    )
github microsoft / computervision-recipes / classification / python / 03_training_accuracy_vs_speed.py View on Github external
#
# Once complete, update the `DATA_PATH` variable to point to `out_dir` so that this notebook uses these resized images.
#

# ## Training <a name="training"></a>
#
# We'll now re-apply the same steps we did in the [01_training_introduction](01_training_introduction.ipynb) notebook here.

# Load the data:

# In[8]:


label_list = (
    (
        ImageList.from_folder(Path(DATA_PATH))
        .split_by_rand_pct(valid_pct=0.2, seed=10)
        .label_from_folder()
    )
    if not multilabel
    else (
        ImageList.from_csv(Path(DATA_PATH), "labels.csv", folder="images")
        .split_by_rand_pct(valid_pct=0.2, seed=10)
        .label_from_df(label_delim=" ")
    )
)


# In[9]:


data = (
github microsoft / computervision-recipes / classification / python / 01_training_introduction.py View on Github external
# ```
#
# We have already set the data to this format structure.

# # Load Images
#
# In `fastai`, an `ImageDataBunch` can easily use multiple images (mini-batches) during training time. We create the `ImageDataBunch` by using [data_block apis](https://docs.fast.ai/data_block.html).
#
# For training and validation, we randomly split the data in an `8:2` ratio, holding 80% of the data for training and 20% for validation.
#

# In[5]:


data = (
    ImageList.from_folder(path)
    .split_by_rand_pct(valid_pct=0.2, seed=10)
    .label_from_folder()
    .transform(size=IMAGE_SIZE)
    .databunch(bs=BATCH_SIZE)
    .normalize(imagenet_stats)
)


# We examine some sample data using the `databunch` we created.

# In[6]:


data.show_batch(rows=3, figsize=(15, 11))
github microsoft / computervision-recipes / utils_cv / classification / parameter_sweeper.py View on Github external
Create ImageDataBunch and return it. TODO in future version is to allow
        users to pass in their own image bunch or their own Transformation
        objects (instead of using fastai's )

        Args:
            path (Union[Path, str]): path to data to create databunch with
            transform (bool): a flag to set fastai default transformations (get_transforms())
            im_size (int): image size of databunch
            bs (int): batch size of databunch
        Returns:
            ImageDataBunch
        """
        path = path if type(path) is Path else Path(path)
        tfms = get_transforms() if transform else None
        return (
            ImageList.from_folder(path)
            .split_by_rand_pct(valid_pct=0.33)
            .label_from_folder()
            .transform(tfms=tfms, size=im_size)
            .databunch(bs=bs, num_workers=db_num_workers())
            .normalize(imagenet_stats)
        )