|
--- |
|
task_categories: |
|
- image-segmentation |
|
- image-classification |
|
language: |
|
- en |
|
tags: |
|
- agritech |
|
- hyperspectral |
|
- spectroscopy |
|
- fruit |
|
- sub-class classification |
|
- detection |
|
size_categories: |
|
- 10K<n<100K |
|
license: mit |
|
--- |
|
# Living Optics Hyperspectral Fruit Dataset |
|
## Overview |
|
This dataset contains 100 images of various fruits and vegetables captured under controlled lighting, with the [Living Optics Camera](livingoptics.com). |
|
|
|
The data consists of RGB images, sparse spectral samples and instance segmentation masks. |
|
|
|
From the 100 images, we extract >430,000 spectral samples, of which >85,000 belong to one of the 19 classes in the dataset. The rest of the spectra can be used for negative sampling when training classifiers. |
|
|
|
An additional 11 labelled images are provided as a validation set. |
|
|
|
Additionally, we provide a set of demo videos in `.lo` format which are unannotated but which can be used to qualititively test algorithms built on this dataset. |
|
|
|
|
|
### Classes |
|
|
|
The training dataset contains 19 classes: |
|
- π lemon - 8275 total spectral samples |
|
- π melon - 9507 total spectral samples |
|
- π₯ cucumber - 227 total spectral samples |
|
- π granny smith apple - 3984 total spectral samples |
|
- π jazz apple - 272 total spectral samples |
|
- π plastic apple - 6693 total spectral samples |
|
- π pink lady apple - 17311 total spectral samples |
|
- π royal gala apple - 21319 total spectral samples |
|
- π
tomato - 3748 total spectral samples |
|
- π
cherry tomato - 360 total spectral samples |
|
- π
plastic tomato - 569 total spectral samples |
|
- π« green pepper - 226 total spectral samples |
|
- π« yellow pepper - 4752 total spectral samples |
|
- π« orange pepper - 552 total spectral samples |
|
- π orange - 4641 total spectral samples |
|
- π easy peeler orange - 2720 total spectral samples |
|
- π pear - 194 total samples |
|
- π green grape - 106 total spectral samples |
|
- πβπ© lime - 43 total spectral samples |
|
|
|
|
|
## Requirements |
|
|
|
- [lo-sdk](https://www.livingoptics.com/register-for-download-sdk/) |
|
- [lo-data](https://huggingface.co/spaces/LivingOptics/README/discussions/3) |
|
|
|
|
|
## Download instructions |
|
|
|
### Command line |
|
```commandline |
|
mkdir -p hyperspectral-fruit |
|
huggingface-cli download LivingOptics/hyperspectral-fruit --repo-type dataset --local-dir hyperspectral-fruit |
|
``` |
|
|
|
### Python |
|
```python |
|
from huggingface_hub import snapshot_download |
|
dataset_path = snapshot_download(repo_id="LivingOptics/hyperspectral-fruit", repo_type="dataset") |
|
print(dataset_path) |
|
``` |
|
|
|
## Usage |
|
|
|
```python |
|
import os.path as op |
|
import numpy.typing as npt |
|
from typing import List, Dict, Generator |
|
from lo.data.tools import Annotation, LODataItem, LOJSONDataset, draw_annotations |
|
from lo.data.dataset_visualisation import get_object_spectra, plot_labelled_spectra |
|
from lo.sdk.api.acquisition.io.open import open as lo_open |
|
|
|
# Load the dataset |
|
path_to_download = op.expanduser("~/Downloads/hyperspectral-fruit") |
|
dataset = LOJSONDataset(path_to_download) |
|
|
|
# Get the training data as an iterator |
|
training_data: List[LODataItem] = dataset.load("train") |
|
|
|
# Inspect the data |
|
lo_data_item: LODataItem |
|
for lo_data_item in training_data[:3]: |
|
|
|
draw_annotations(lo_data_item) |
|
|
|
ann: Annotation |
|
for ann in lo_data_item.annotations: |
|
print(ann.class_name, ann.category, ann.subcategories) |
|
|
|
# Plot the spectra for each class |
|
fig, ax = plt.subplots(1) |
|
object_spectra_dict = {} |
|
class_numbers_to_labels = {0: "background_class"} |
|
for lo_data_item in training_data: |
|
object_spectra_dict, class_numbers_to_labels = get_object_spectra( |
|
lo_data_item, object_spectra_dict, class_numbers_to_labels |
|
) |
|
|
|
plot_labelled_spectra(object_spectra_dict, class_numbers_to_labels, ax) |
|
plt.show() |
|
``` |
|
|
|
See our [Spatial Spectral ML](https://github.com/livingoptics/spatial-spectral-ml) project for an example of how to train and run a segmentation and spectral classification algoirthm using this dataset. |