Skip to content

Commit

Permalink
Remove dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
sadda committed Oct 31, 2024
1 parent b750bde commit 0c65fd3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 82 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ dependencies=[
'scikit-learn>=1.0.1',
'matplotlib>=3.5.1',
'pycocotools>=2.0.1',
'torchvision>=0.18.0',
'datasets',
'gdown',
'kaggle',
Expand Down
121 changes: 40 additions & 81 deletions wildlife_datasets/preparation/prepare_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import numpy as np
import pandas as pd
import torchvision.transforms as T
from tqdm import tqdm
from .. import datasets
from typing import Optional, List
Expand Down Expand Up @@ -87,215 +86,175 @@ def get_every_k(
idx = dataset.df.index.get_indexer(idx)
return np.sort(idx)

def prepare_aau_zebrafish(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_aau_zebrafish(root, new_root, transform=None, **kwargs):
dataset = datasets.AAUZebraFish(root, img_load="bbox", transform=transform, remove_unknown=True)
idx = get_every_k(dataset, 20, 'identity')
return resize_dataset(dataset, new_root, idx=idx, **kwargs)

def prepare_aerial_cattle_2017(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_aerial_cattle_2017(root, new_root, transform=None, **kwargs):
dataset = datasets.AerialCattle2017(root, img_load="full", transform=transform, remove_unknown=True)
idx = get_every_k(dataset, 20, 'identity')
return resize_dataset(dataset, new_root, idx=idx, **kwargs)

def prepare_amvrakikos_turtles(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_amvrakikos_turtles(root, new_root, transform=None, **kwargs):
dataset = datasets.AmvrakikosTurtles(root, img_load="bbox", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_atrw(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_atrw(root, new_root, transform=None, **kwargs):
dataset = datasets.ATRW(root, img_load="bbox", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_beluga_id(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_beluga_id(root, new_root, transform=None, **kwargs):
dataset = datasets.BelugaIDv2(root, img_load="bbox", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_bird_individual_id(root, new_root, size=None, segmented=True, **kwargs):
def prepare_bird_individual_id(root, new_root, transform=None, segmented=True, **kwargs):
if segmented:
root = root + "Segmented"
transform = None if size is None else T.Resize(size=size)
dataset = datasets.BirdIndividualIDSegmented(root, img_load="crop_black", transform=transform, remove_unknown=True)
idx = get_every_k(dataset, 20, 'identity')
return resize_dataset(dataset, new_root, idx=idx, **kwargs)

def prepare_cat_individual_images(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_cat_individual_images(root, new_root, transform=None, **kwargs):
dataset = datasets.CatIndividualImages(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_chicks4free_id(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_chicks4free_id(root, new_root, transform=None, **kwargs):
dataset = datasets.Chicks4FreeID(root, img_load="full", transform=transform, remove_unknown=True)
# Change the path from np.nan so that it is saved correctly
dataset.df['path'] = 'images/' + dataset.df['image_id'].astype('str') + '.jpg'
return resize_dataset(dataset, new_root, **kwargs)

def prepare_cow_dataset(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_cow_dataset(root, new_root, transform=None, **kwargs):
dataset = datasets.CowDataset(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_cows2021(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_cows2021(root, new_root, transform=None, **kwargs):
dataset = datasets.Cows2021v2(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_ctai(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_ctai(root, new_root, transform=None, **kwargs):
dataset = datasets.CTai(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_czoo(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_czoo(root, new_root, transform=None, **kwargs):
dataset = datasets.CZoo(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_dog_facenet(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_dog_facenet(root, new_root, transform=None, **kwargs):
dataset = datasets.DogFaceNet(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_drosophila(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_drosophila(root, new_root, transform=None, **kwargs):
dataset = datasets.Drosophila(root, img_load="full", transform=transform, remove_unknown=True)
idx = get_every_k(dataset, 1000, 'identity')
return resize_dataset(dataset, new_root, idx=idx, **kwargs)

def prepare_friesian_cattle_2015(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_friesian_cattle_2015(root, new_root, transform=None, **kwargs):
dataset = datasets.FriesianCattle2015v2(root, img_load="crop_black", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_friesian_cattle_2017(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_friesian_cattle_2017(root, new_root, transform=None, **kwargs):
dataset = datasets.FriesianCattle2017(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_giraffes(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_giraffes(root, new_root, transform=None, **kwargs):
dataset = datasets.Giraffes(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_giraffe_zebra_id(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_giraffe_zebra_id(root, new_root, transform=None, **kwargs):
dataset = datasets.GiraffeZebraID(root, img_load="bbox", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_happy_whale(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_happy_whale(root, new_root, transform=None, **kwargs):
dataset = datasets.HappyWhale(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_humpback_whale_id(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_humpback_whale_id(root, new_root, transform=None, **kwargs):
dataset = datasets.HumpbackWhaleID(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_hyena_id_2022(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_hyena_id_2022(root, new_root, transform=None, **kwargs):
dataset = datasets.HyenaID2022(root, img_load="bbox", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_ipanda_50(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_ipanda_50(root, new_root, transform=None, **kwargs):
dataset = datasets.IPanda50(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_leopard_id_2022(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_leopard_id_2022(root, new_root, transform=None, **kwargs):
dataset = datasets.LeopardID2022(root, img_load="bbox", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_macaque_faces(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_macaque_faces(root, new_root, transform=None, **kwargs):
dataset = datasets.MacaqueFaces(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_mpdd(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_mpdd(root, new_root, transform=None, **kwargs):
dataset = datasets.MPDD(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_ndd20(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_ndd20(root, new_root, transform=None, **kwargs):
dataset = datasets.NDD20v2(root, img_load="bbox_mask", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_noaa_right_whale(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_noaa_right_whale(root, new_root, transform=None, **kwargs):
dataset = datasets.NOAARightWhale(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_nyala_data(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_nyala_data(root, new_root, transform=None, **kwargs):
dataset = datasets.NyalaData(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_open_cows_2020(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_open_cows_2020(root, new_root, transform=None, **kwargs):
dataset = datasets.OpenCows2020(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_polar_bear_vidid(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_polar_bear_vidid(root, new_root, transform=None, **kwargs):
dataset = datasets.PolarBearVidID(root, img_load="full", transform=transform, remove_unknown=True)
idx = get_every_k(dataset, 100, 'identity')
return resize_dataset(dataset, new_root, idx=idx, **kwargs)

def prepare_reunion_turtles(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_reunion_turtles(root, new_root, transform=None, **kwargs):
dataset = datasets.ReunionTurtles(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_seal_id(root, new_root, size=None, segmented=True, **kwargs):
def prepare_seal_id(root, new_root, transform=None, segmented=True, **kwargs):
if segmented:
root = root + "Segmented"
transform = None if size is None else T.Resize(size=size)
dataset = datasets.SealIDSegmented(root, img_load="crop_black", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_sea_star_reid_2023(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_sea_star_reid_2023(root, new_root, transform=None, **kwargs):
dataset = datasets.SeaStarReID2023(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_sea_turtle_id_2022(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_sea_turtle_id_2022(root, new_root, transform=None, **kwargs):
dataset = datasets.SeaTurtleID2022(root, img_load="bbox", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_smalst(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_smalst(root, new_root, transform=None, **kwargs):
dataset = datasets.SMALST(root, img_load="bbox_mask", transform=transform, remove_unknown=True)
idx = get_every_k(dataset, 10, 'identity')
return resize_dataset(dataset, new_root, idx=idx, **kwargs)

def prepare_southern_province_turtles(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_southern_province_turtles(root, new_root, transform=None, **kwargs):
dataset = datasets.SouthernProvinceTurtles(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_stripe_spotter(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_stripe_spotter(root, new_root, transform=None, **kwargs):
dataset = datasets.StripeSpotter(root, img_load="bbox", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_whaleshark_id(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_whaleshark_id(root, new_root, transform=None, **kwargs):
dataset = datasets.WhaleSharkID(root, img_load="bbox", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_zakynthos_turtles(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_zakynthos_turtles(root, new_root, transform=None, **kwargs):
dataset = datasets.ZakynthosTurtles(root, img_load="bbox", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

def prepare_zindi_turtle_recall(root, new_root, size=None, **kwargs):
transform = None if size is None else T.Resize(size=size)
def prepare_zindi_turtle_recall(root, new_root, transform=None, **kwargs):
dataset = datasets.ZindiTurtleRecall(root, img_load="full", transform=transform, remove_unknown=True)
return resize_dataset(dataset, new_root, **kwargs)

Expand Down

0 comments on commit 0c65fd3

Please sign in to comment.