Skip to content

Open In Colab

Disclaimer

This notebook won't work in Colab, due to an incompatibility with the fiftyone library.

Using Fiftyone in IceVision

Install IceVision

The following downloads and runs a short shell script. The script installs IceVision, IceData, the MMDetection library, and Yolo v5 as well as the fastai and pytorch lightning engines.

Install from pypi...

# # Torch - Torchvision - IceVision - IceData - MMDetection - YOLOv5 - EfficientDet Installation
# !wget https://raw.githubusercontent.com/airctic/icevision/master/icevision_install.sh

# # Choose your installation target: cuda11 or cuda10 or cpu
# !bash icevision_install.sh cuda11

... or from icevision master

# Torch - Torchvision - IceVision - IceData - MMDetection - YOLOv5 - EfficientDet Installation
!wget https://raw.githubusercontent.com/airctic/icevision/master/icevision_install.sh

# Choose your installation target: cuda11 or cuda10 or cpu
!bash icevision_install.sh cuda11 master

fiftyone is not part of IceVision. We need to install it separately.

# Install fiftyone
%pip install fiftyone -U
# Restart kernel after installation
import IPython
IPython.Application.instance().kernel.do_shutdown(True)

Imports

All of the IceVision components can be easily imported with a single line.

from icevision.all import *
from icevision.models import * # Needed for inference later
import icedata  # Needed for sample data
import fiftyone as fo

Visualizing datasets

The fiftyone integration of IceVision can be used on either IceVision Datasets or IceVision Prediction. Let's start by visualizing a dataset.

If you don't know fiftyone yet, visit the website and read about the concepts: https://voxel51.com/docs/fiftyone.

Fiftyone Summary

Fiftyone is a tool to analyze datasets and detections of all forms.

For object detection these concepts are most relevant:

Fiftyone is structured into fo.Datasets. So every viewable entity is related to a fo.Dataset. An image is represented by a fo.Sample. After you created a fo.Sample you can add fo.Detections, which is constructed by a list of fo.Detection. Finally, you need to add a fo.Sample to your fo.Dataset and then launch your app by calling fo.launch_app(dataset). IceVision enables you to create all of these fo objects from IceVision classes.

Before we train or execute inference, we need to create an icevision.Dataset. From this dataset, we can create a fo.Dataset. Since fiftyone operates on filepaths, you dataset needs filepath as component and you cannot use Dataset.from_images as it stores the images in RAM.

We use the fridge object dataset available from IceData.

# List all available fiftyone datasets on your machine:
fo.list_datasets()

# Download dataset
infer_ds_path = icedata.fridge.load_data()
train_records, valid_records = icedata.fridge.parser(infer_ds_path).parse()

# Set fo dataset name
fo_dataset_name = "inference_dataset"

#RandomSplitter Create fiftyone dataset
fo_dataset = data.create_fo_dataset(valid_records, fo_dataset_name)
# See your new dataset in the lists
fo.list_datasets()
fo.launch_app(fo_dataset)

[]

['inference_dataset']