weecology / weecology/DeepForest

Weighted Random Sampler for Multi-class detection

Open
#792 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature Request Ideas for Machine Learning!
Dominant language
Python
Stars
774
Forks
265
PR merge metrics
No merged PRs in 30d

Description

The vast majority of ecological data are imbalanced. We should have some default weighted random sampler options

from torch.utils.data import WeightedRandomSampler
from deepforest import main

m = main.deepforest()

[setup and load data]

dataset = m.train_ds

# Assuming 'dataset' is your PyTorch Dataset object
class_counts = [0] * len(dataset.classes)
for _, label in dataset:
    class_counts[label] += 1

class_weights = 1. / torch.tensor(class_counts, dtype=torch.float)
sample_weights = [class_weights[label] for _, label in dataset]
sampler = WeightedRandomSampler(sample_weights, len(dataset))

and would get synced up through load dataset

https://github.com/weecology/DeepForest/blob/e14bc6dccbaa2a276cb69a3b16fd7fb8d3301b61/deepforest/main.py#L289

and into the dataloader object

https://github.com/weecology/DeepForest/blob/e14bc6dccbaa2a276cb69a3b16fd7fb8d3301b61/deepforest/main.py#L270

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in deepforest/main.py around the dataloader at line 270 and dataset loading at line 289, then trace how the training dataset reaches the loader. Determine how default weighted-random-sampler options should be configured and synchronized through dataset loading. Done means multi-class training can use the requested sampler through the dataloader.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.