Skip to content

Commit 0ab31ba

Browse files
committed
runs check_example only if values are provided while initialising DataSet
having this flag drastically reduces time to load & sanity check large image datasets for practical ML tasks
1 parent 6404d1d commit 0ab31ba

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

learning.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def __init__(self, examples=None, attrs=None, attrnames=None, target=-1,
7575
self.source = source
7676
self.values = values
7777
self.distance = distance
78+
if values is None:
79+
self.got_values_flag = False
80+
else:
81+
self.got_values_flag = True
7882

7983
# Initialize .examples from string or list or data directory
8084
if isinstance(examples, str):
@@ -85,7 +89,7 @@ def __init__(self, examples=None, attrs=None, attrnames=None, target=-1,
8589
self.examples = examples
8690
# Attrs are the indices of examples, unless otherwise stated.
8791
if attrs is None and self.examples is not None:
88-
attrs = list(range(len(self.examples[0])))
92+
attrs = list(range(len(self.examples[0])))
8993
self.attrs = attrs
9094
# Initialize .attrnames from string, list, or by default
9195
if isinstance(attrnames, str):
@@ -117,7 +121,9 @@ def check_me(self):
117121
assert self.target in self.attrs
118122
assert self.target not in self.inputs
119123
assert set(self.inputs).issubset(set(self.attrs))
120-
list(map(self.check_example, self.examples))
124+
if self.got_values_flag:
125+
# no need to check if values aren't provided while initializing DataSet
126+
list(map(self.check_example, self.examples))
121127

122128
def add_example(self, example):
123129
"Add an example to the list of examples, checking it first."

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy