• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ContinualAI / avalanche / 5268393053

pending completion
5268393053

Pull #1397

github

web-flow
Merge 60d244754 into e91562200
Pull Request #1397: Specialize benchmark creation helpers

417 of 538 new or added lines in 30 files covered. (77.51%)

43 existing lines in 5 files now uncovered.

16586 of 22630 relevant lines covered (73.29%)

2.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/avalanche/benchmarks/classic/openloris.py
1
################################################################################
2
# Copyright (c) 2021 ContinualAI.                                              #
3
# Copyrights licensed under the MIT License.                                   #
4
# See the accompanying LICENSE file for terms.                                 #
5
#                                                                              #
6
# Date: 19-12-2020                                                             #
7
# Author(s): ContinualAI                                                       #
8
# E-mail: contact@continualai.org                                              #
9
# Website: www.continualai.org                                                 #
10
################################################################################
11

12
""" This module contains the high-level OpenLORIS benchmark/factor generator.
4✔
13
It basically returns a iterable benchmark object :class:`ClassificationScenario`
14
given a number of configuration parameters."""
15

16
from pathlib import Path
4✔
17
from typing import Union, Any, Optional
4✔
18
from typing_extensions import Literal
4✔
19

20
from avalanche.benchmarks.classic.classic_benchmarks_utils import (
4✔
21
    check_vision_benchmark,
22
)
23
from avalanche.benchmarks.datasets.openloris import (
4✔
24
    OpenLORIS as OpenLORISDataset,
25
)
26
from avalanche.benchmarks.scenarios.classification_benchmark_creation import (
4✔
27
    create_classification_benchmark_from_filelists,
28
)
29
from avalanche.benchmarks.scenarios.classification_scenario import (
4✔
30
    CommonClassificationScenarioType,
31
)
32

33

34
nbatch = {
4✔
35
    "clutter": 9,
36
    "illumination": 9,
37
    "occlusion": 9,
38
    "pixel": 9,
39
    "mixture-iros": 12,
40
}
41

42
fac2dirs = {
4✔
43
    "clutter": "batches_filelists/domain/clutter",
44
    "illumination": "batches_filelists/domain/illumination",
45
    "occlusion": "batches_filelists/domain/occlusion",
46
    "pixel": "batches_filelists/domain/pixel",
47
    "mixture-iros": "batches_filelists/domain/iros",
48
}
49

50

51
def OpenLORIS(
4✔
52
    *,
53
    factor: Literal[
54
        "clutter", "illumination", "occlusion", "pixel", "mixture-iros"
55
    ] = "clutter",
56
    train_transform: Optional[Any] = None,
57
    eval_transform: Optional[Any] = None,
58
    dataset_root: Optional[Union[str, Path]] = None
59
):
60
    """
61
    Creates a CL benchmark for OpenLORIS.
62

63
    If the dataset is not present in the computer, **this method will NOT be
64
    able automatically download** and store it.
65

66
    This generator can be used to obtain scenarios based on different "factors".
67
    Valid factors include 'clutter', 'illumination', 'occlusion', 'pixel', or
68
    'mixture-iros'.
69

70
    The benchmark instance returned by this method will have two fields,
71
    `train_stream` and `test_stream`, which can be iterated to obtain
72
    training and test :class:`Experience`. Each Experience contains the
73
    `dataset` and the associated task label.
74

75
    The task label 0 will be assigned to each experience.
76

77
    The benchmark API is quite simple and is uniform across all benchmark
78
    generators. It is recommended to check the tutorial of the "benchmark" API,
79
    which contains usage examples ranging from "basic" to "advanced".
80

81
    :param factor: OpenLORIS main factors, indicating different environmental
82
        variations. It can be chosen between 'clutter', 'illumination',
83
        'occlusion', 'pixel', or 'mixture-iros'. The first three factors are
84
        included in the ICRA 2020 paper and the last factor (mixture-iros) is
85
        the benchmark setting for IROS 2019 Lifelong robotic vision competition.
86
    :param train_transform: The transformation to apply to the training data,
87
        e.g. a random crop, a normalization or a concatenation of different
88
        transformations (see torchvision.transform documentation for a
89
        comprehensive list of possible transformations). Defaults to None.
90
    :param eval_transform: The transformation to apply to the test data,
91
        e.g. a random crop, a normalization or a concatenation of different
92
        transformations (see torchvision.transform documentation for a
93
        comprehensive list of possible transformations). Defaults to None.
94
    :param dataset_root: The root path of the dataset.
95
        Defaults to None, which means that the default location for
96
        'openloris' will be used.
97

98
    :returns: a properly initialized :class:`ClassificationScenario` instance.
99
    """
100

101
    assert factor in nbatch.keys(), (
×
102
        "The selected factor is note "
103
        "recognized: it should be 'clutter',"
104
        "'illumination', 'occlusion', "
105
        "'pixel', or 'mixture-iros'."
106
    )
107

108
    # Dataset created just to download it
109
    dataset = OpenLORISDataset(dataset_root, download=True)
×
110

111
    # Use the root produced by the dataset implementation
112
    dataset_root = dataset.root
×
113

114
    filelists_bp = fac2dirs[factor] + "/"
×
115
    train_failists_paths = []
×
116
    for i in range(nbatch[factor]):
×
117
        train_failists_paths.append(
×
118
            dataset_root
119
            / filelists_bp
120
            / ("train_batch_" + str(i).zfill(2) + ".txt")
121
        )
122

NEW
123
    factor_obj: CommonClassificationScenarioType = \
×
124
        create_classification_benchmark_from_filelists(
125
            dataset_root,
126
            train_failists_paths,
127
            [dataset_root / filelists_bp / "test.txt"],
128
            task_labels=[0 for _ in range(nbatch[factor])],
129
            complete_test_set_only=True,
130
            train_transform=train_transform,
131
            eval_transform=eval_transform,
132
        )
133

134
    return factor_obj
×
135

136

137
__all__ = ["OpenLORIS"]
4✔
138

139
if __name__ == "__main__":
4✔
140
    import sys
×
141

142
    # Untested!
143
    benchmark_instance = OpenLORIS()
×
144
    check_vision_benchmark(benchmark_instance)
×
145
    sys.exit(0)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc