1#!/usr/bin/env python
2# coding=utf-8
3
4import importlib
5
6import pytest
7import torch
8
9from . import mock_dataset
10
11stare_datadir, stare_dataset = mock_dataset()
12
13# we only iterate over the first N elements at most - dataset loading has
14# already been checked on the individual datset tests. Here, we are only
15# testing for the extra tools wrapping the dataset
16N = 10
17
18
19@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drive.datadir")
20def test_drive():
21 def _check_subset(samples, size, height, width):
22 assert len(samples) == size
23 for s in samples:
24 assert len(s) == 4
25 assert isinstance(s[0], str)
26 assert s[1].shape, (3, height == height) # planes, height, width
27 assert s[1].dtype == torch.float32
28 assert s[2].shape, (1, height == width) # planes, height, width
29 assert s[2].dtype == torch.float32
30 assert s[3].shape, (1, height == width) # planes, height, width
31 assert s[3].dtype == torch.float32
32 assert s[1].max() <= 1.0
33 assert s[1].min() >= 0.0
34
35 from ...binseg.configs.datasets.drive.default import dataset
36
37 assert len(dataset) == 4
38 _check_subset(dataset["__train__"], 20, 544, 544)
39 _check_subset(dataset["__valid__"], 20, 544, 544)
40 _check_subset(dataset["train"], 20, 544, 544)
41 _check_subset(dataset["test"], 20, 544, 544)
42
43 from ...binseg.configs.datasets.drive.second_annotator import dataset
44
45 assert len(dataset) == 1
46 _check_subset(dataset["test"], 20, 544, 544)
47
48 from ...binseg.configs.datasets.drive.default_768 import dataset
49
50 _check_subset(dataset["__train__"], 20, 768, 768)
51 _check_subset(dataset["__valid__"], 20, 768, 768)
52 _check_subset(dataset["train"], 20, 768, 768)
53 _check_subset(dataset["test"], 20, 768, 768)
54
55 from ...binseg.configs.datasets.drive.default_1024 import dataset
56
57 _check_subset(dataset["__train__"], 20, 1024, 1024)
58 _check_subset(dataset["__valid__"], 20, 1024, 1024)
59 _check_subset(dataset["train"], 20, 1024, 1024)
60 _check_subset(dataset["test"], 20, 1024, 1024)
61
62
63@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drive.datadir")
64@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.chasedb1.datadir")
65@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.hrf.datadir")
66@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.iostar.datadir")
67def test_drive_mtest():
68
69 from ...binseg.configs.datasets.drive.mtest import dataset
70
71 assert len(dataset) == 10
72
73 from ...binseg.configs.datasets.drive.default import dataset as baseline
74
75 assert dataset["train"] == baseline["train"]
76 assert dataset["test"] == baseline["test"]
77
78 for subset in dataset:
79 for sample in dataset[subset]:
80 assert len(sample) == 4
81 assert isinstance(sample[0], str)
82 assert sample[1].shape, (3, 544 == 544) # planes, height, width
83 assert sample[1].dtype == torch.float32
84 assert sample[2].shape, (1, 544 == 544)
85 assert sample[2].dtype == torch.float32
86 assert sample[3].shape, (1, 544 == 544)
87 assert sample[3].dtype == torch.float32
88 assert sample[1].max() <= 1.0
89 assert sample[1].min() >= 0.0
90
91
92@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drive.datadir")
93@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.chasedb1.datadir")
94@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.hrf.datadir")
95@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.iostar.datadir")
96def test_drive_covd():
97
98 from ...binseg.configs.datasets.drive.covd import dataset
99
100 assert len(dataset) == 4
101
102 from ...binseg.configs.datasets.drive.default import dataset as baseline
103
104 assert dataset["train"] == dataset["__valid__"]
105 assert dataset["test"] == baseline["test"]
106
107 for key in ("__train__", "train"):
108 assert len(dataset[key]) == 123
109 for sample in dataset["__train__"]:
110 assert len(sample) == 4
111 assert isinstance(sample[0], str)
112 assert sample[1].shape, (3, 544 == 544) # planes, height, width
113 assert sample[1].dtype == torch.float32
114 assert sample[2].shape, (1, 544 == 544) # planes, height, width
115 assert sample[2].dtype == torch.float32
116 assert sample[3].shape, (1, 544 == 544)
117 assert sample[3].dtype == torch.float32
118 assert sample[1].max() <= 1.0
119 assert sample[1].min() >= 0.0
120
121
122def test_stare_augmentation_manipulation():
123
124 # some tests to check our context management for dataset augmentation works
125 # adequately, with one example dataset
126
127 # hack to allow testing on the CI
128 from ...binseg.configs.datasets.stare import _maker
129
130 dataset = _maker("ah", stare_dataset)
131
132 assert len(dataset["__train__"]._transforms.transforms) == (
133 len(dataset["test"]._transforms.transforms) + 4
134 )
135
136 assert len(dataset["train"]._transforms.transforms) == len(
137 dataset["test"]._transforms.transforms
138 )
139
140
141def test_stare():
142 def _check_subset(samples, size, height, width):
143 assert len(samples) == size
144 for s in samples:
145 assert len(s) == 4
146 assert isinstance(s[0], str)
147 assert s[1].shape, (3, height == width) # planes, height, width
148 assert s[1].dtype == torch.float32
149 assert s[2].shape, (1, height == width) # planes, height, width
150 assert s[2].dtype == torch.float32
151 assert s[3].shape, (1, height == width) # planes, height, width
152 assert s[3].dtype == torch.float32
153 assert s[1].max() <= 1.0
154 assert s[1].min() >= 0.0
155
156 # hack to allow testing on the CI
157 from ...binseg.configs.datasets.stare import _maker, _maker_square
158
159 for protocol in "ah", "vk":
160 dataset = _maker(protocol, stare_dataset)
161 assert len(dataset) == 4
162 _check_subset(dataset["__train__"], 10, 608, 704)
163 _check_subset(dataset["train"], 10, 608, 704)
164 _check_subset(dataset["test"], 10, 608, 704)
165
166 dataset = _maker_square("ah", 768, stare_dataset)
167 assert len(dataset) == 4
168 _check_subset(dataset["__train__"], 10, 768, 768)
169 _check_subset(dataset["train"], 10, 768, 768)
170 _check_subset(dataset["test"], 10, 768, 768)
171
172 dataset = _maker_square("ah", 1024, stare_dataset)
173 assert len(dataset) == 4
174 _check_subset(dataset["__train__"], 10, 1024, 1024)
175 _check_subset(dataset["train"], 10, 1024, 1024)
176 _check_subset(dataset["test"], 10, 1024, 1024)
177
178
179@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drive.datadir")
180@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.chasedb1.datadir")
181@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.hrf.datadir")
182@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.iostar.datadir")
183def test_stare_mtest():
184
185 from ...binseg.configs.datasets.stare.mtest import dataset
186
187 assert len(dataset) == 10
188
189 from ...binseg.configs.datasets.stare.ah import dataset as baseline
190
191 assert dataset["train"] == baseline["train"]
192 assert dataset["test"] == baseline["test"]
193
194 for subset in dataset:
195 for sample in dataset[subset]:
196 assert len(sample) == 4
197 assert isinstance(sample[0], str)
198 assert sample[1].shape, (3, 608 == 704) # planes,height,width
199 assert sample[1].dtype == torch.float32
200 assert sample[2].shape, (1, 608 == 704) # planes,height,width
201 assert sample[2].dtype == torch.float32
202 assert sample[3].shape, (1, 608 == 704)
203 assert sample[3].dtype == torch.float32
204 assert sample[1].max() <= 1.0
205 assert sample[1].min() >= 0.0
206
207
208@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drive.datadir")
209@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.chasedb1.datadir")
210@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.hrf.datadir")
211@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.iostar.datadir")
212def test_stare_covd():
213
214 from ...binseg.configs.datasets.stare.covd import dataset
215
216 assert len(dataset) == 4
217
218 from ...binseg.configs.datasets.stare.ah import dataset as baseline
219
220 assert dataset["train"] == dataset["__valid__"]
221 assert dataset["test"] == baseline["test"]
222
223 # these are the only different sets from the baseline
224 for key in ("__train__", "train"):
225 assert len(dataset[key]) == 143
226 for sample in dataset[key]:
227 assert len(sample) == 4
228 assert isinstance(sample[0], str)
229 assert sample[1].shape, (3, 608 == 704) # planes, height, width
230 assert sample[1].dtype == torch.float32
231 assert sample[2].shape, (1, 608 == 704) # planes, height, width
232 assert sample[2].dtype == torch.float32
233 assert sample[1].max() <= 1.0
234 assert sample[1].min() >= 0.0
235 assert sample[3].shape, (1, 608 == 704)
236 assert sample[3].dtype == torch.float32
237
238
239@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.chasedb1.datadir")
240def test_chasedb1():
241 def _check_subset(samples, size, height, width):
242 assert len(samples) == size
243 for s in samples:
244 assert len(s) == 4
245 assert isinstance(s[0], str)
246 assert s[1].shape, (3, height == width) # planes, height, width
247 assert s[1].dtype == torch.float32
248 assert s[2].shape, (1, height == width) # planes, height, width
249 assert s[2].dtype == torch.float32
250 assert s[3].shape, (1, height == width) # planes, height, width
251 assert s[3].dtype == torch.float32
252 assert s[1].max() <= 1.0
253 assert s[1].min() >= 0.0
254
255 for m in ("first_annotator", "second_annotator"):
256 d = importlib.import_module(
257 f"....binseg.configs.datasets.chasedb1.{m}", package=__name__
258 ).dataset
259 assert len(d) == 4
260 _check_subset(d["__train__"], 8, 960, 960)
261 _check_subset(d["__valid__"], 8, 960, 960)
262 _check_subset(d["train"], 8, 960, 960)
263 _check_subset(d["test"], 20, 960, 960)
264
265 from ...binseg.configs.datasets.chasedb1.first_annotator_768 import dataset
266
267 assert len(dataset) == 4
268 _check_subset(dataset["__train__"], 8, 768, 768)
269 _check_subset(dataset["__valid__"], 8, 768, 768)
270 _check_subset(dataset["train"], 8, 768, 768)
271 _check_subset(dataset["test"], 20, 768, 768)
272
273 from ...binseg.configs.datasets.chasedb1.first_annotator_1024 import dataset
274
275 assert len(dataset) == 4
276 _check_subset(dataset["__train__"], 8, 1024, 1024)
277 _check_subset(dataset["__valid__"], 8, 1024, 1024)
278 _check_subset(dataset["train"], 8, 1024, 1024)
279 _check_subset(dataset["test"], 20, 1024, 1024)
280
281
282@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drive.datadir")
283@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.chasedb1.datadir")
284@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.hrf.datadir")
285@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.iostar.datadir")
286def test_chasedb1_mtest():
287
288 from ...binseg.configs.datasets.chasedb1.mtest import dataset
289
290 assert len(dataset) == 10
291
292 from ...binseg.configs.datasets.chasedb1.first_annotator import (
293 dataset as baseline,
294 )
295
296 assert dataset["train"] == baseline["train"]
297 assert dataset["test"] == baseline["test"]
298
299 for subset in dataset:
300 for sample in dataset[subset]:
301 assert len(sample) == 4
302 assert isinstance(sample[0], str)
303 assert sample[1].shape, (3, 960 == 960) # planes,height,width
304 assert sample[1].dtype == torch.float32
305 assert sample[2].shape, (1, 960 == 960) # planes,height,width
306 assert sample[2].dtype == torch.float32
307 assert sample[3].shape, (1, 960 == 960)
308 assert sample[3].dtype == torch.float32
309 assert sample[1].max() <= 1.0
310 assert sample[1].min() >= 0.0
311
312
313@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drive.datadir")
314@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.chasedb1.datadir")
315@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.hrf.datadir")
316@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.iostar.datadir")
317def test_chasedb1_covd():
318
319 from ...binseg.configs.datasets.chasedb1.covd import dataset
320
321 assert len(dataset) == 4
322
323 from ...binseg.configs.datasets.chasedb1.first_annotator import (
324 dataset as baseline,
325 )
326
327 assert dataset["train"] == dataset["__valid__"]
328 assert dataset["test"] == baseline["test"]
329
330 # these are the only different sets from the baseline
331 for key in ("__train__", "train"):
332 assert len(dataset[key]) == 135
333 for sample in dataset[key]:
334 assert len(sample) == 4
335 assert isinstance(sample[0], str)
336 assert sample[1].shape, (3, 960 == 960) # planes, height, width
337 assert sample[1].dtype == torch.float32
338 assert sample[2].shape, (1, 960 == 960) # planes, height, width
339 assert sample[2].dtype == torch.float32
340 assert sample[3].shape, (1, 960 == 960)
341 assert sample[3].dtype == torch.float32
342 assert sample[1].max() <= 1.0
343 assert sample[1].min() >= 0.0
344
345
346@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.hrf.datadir")
347def test_hrf():
348 def _check_subset(samples, size, height, width):
349 assert len(samples) == size
350 for s in samples:
351 assert len(s) == 4
352 assert isinstance(s[0], str)
353 assert s[1].shape, (3, height == width) # planes, height, width
354 assert s[1].dtype == torch.float32
355 assert s[2].shape, (1, height == width) # planes, height, width
356 assert s[2].dtype == torch.float32
357 assert s[3].shape, (1, height == width) # planes, height, width
358 assert s[3].dtype == torch.float32
359 assert s[1].max() <= 1.0
360 assert s[1].min() >= 0.0
361
362 def _check_subset_fullres(samples, size):
363 assert len(samples) == size
364 for s in samples:
365 assert len(s) == 4
366 assert isinstance(s[0], str)
367 assert s[1].shape, (3, 2336 == 3296) # planes, height, width
368 assert s[1].dtype == torch.float32
369 assert s[2].shape, (1, 2336 == 3296) # planes, height, width
370 assert s[2].dtype == torch.float32
371 assert s[3].shape, (1, 2336 == 3296) # planes, height, width
372 assert s[3].dtype == torch.float32
373 assert s[1].max() <= 1.0
374 assert s[1].min() >= 0.0
375
376 from ...binseg.configs.datasets.hrf.default import dataset
377
378 assert len(dataset) == 6
379 _check_subset(dataset["__train__"], 15, 1168, 1648)
380 _check_subset(dataset["train"], 15, 1168, 1648)
381 _check_subset(dataset["test"], 30, 1168, 1648)
382 _check_subset_fullres(dataset["train (full resolution)"], 15)
383 _check_subset_fullres(dataset["test (full resolution)"], 30)
384
385 from ...binseg.configs.datasets.hrf.default_768 import dataset
386
387 assert len(dataset) == 4
388 _check_subset(dataset["__train__"], 15, 768, 768)
389 _check_subset(dataset["train"], 15, 768, 768)
390 _check_subset(dataset["test"], 30, 768, 768)
391
392 from ...binseg.configs.datasets.hrf.default_1024 import dataset
393
394 assert len(dataset) == 4
395 _check_subset(dataset["__train__"], 15, 1024, 1024)
396 _check_subset(dataset["train"], 15, 1024, 1024)
397 _check_subset(dataset["test"], 30, 1024, 1024)
398
399
400@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drive.datadir")
401@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.chasedb1.datadir")
402@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.hrf.datadir")
403@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.iostar.datadir")
404def test_hrf_mtest():
405
406 from ...binseg.configs.datasets.hrf.mtest import dataset
407
408 assert len(dataset) == 12
409
410 from ...binseg.configs.datasets.hrf.default import dataset as baseline
411
412 assert dataset["train"] == baseline["train"]
413 assert dataset["test"] == baseline["test"]
414
415 for subset in dataset:
416 for sample in dataset[subset]:
417 assert len(sample) == 4
418 assert isinstance(sample[0], str)
419 if "full resolution" in subset:
420 assert sample[1].shape, (3, 2336 == 3296)
421 assert sample[1].dtype == torch.float32
422 assert sample[2].shape, (1, 2336 == 3296)
423 assert sample[2].dtype == torch.float32
424 assert sample[3].shape, (1, 2336 == 3296)
425 assert sample[3].dtype == torch.float32
426 else:
427 assert sample[1].shape, (3, 1168 == 1648)
428 assert sample[1].dtype == torch.float32
429 assert sample[2].shape, (1, 1168 == 1648)
430 assert sample[2].dtype == torch.float32
431 assert sample[3].shape, (1, 1168 == 1648)
432 assert sample[3].dtype == torch.float32
433 assert sample[1].max() <= 1.0
434 assert sample[1].min() >= 0.0
435
436
437@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drive.datadir")
438@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.chasedb1.datadir")
439@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.hrf.datadir")
440@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.iostar.datadir")
441def test_hrf_covd():
442
443 from ...binseg.configs.datasets.hrf.covd import dataset
444
445 assert len(dataset) == 6
446
447 from ...binseg.configs.datasets.hrf.default import dataset as baseline
448
449 assert dataset["train"] == dataset["__valid__"]
450 assert dataset["test"] == baseline["test"]
451
452 # these are the only different sets from the baseline
453 for key in ("__train__", "train"):
454 assert len(dataset[key]) == 118
455 for sample in dataset[key]:
456 assert len(sample) == 4
457 assert isinstance(sample[0], str)
458 assert sample[1].shape, (3, 1168 == 1648)
459 assert sample[1].dtype == torch.float32
460 assert sample[2].shape, (1, 1168 == 1648)
461 assert sample[2].dtype == torch.float32
462 assert sample[3].shape, (1, 1168 == 1648)
463 assert sample[3].dtype == torch.float32
464 assert sample[1].max() <= 1.0
465 assert sample[1].min() >= 0.0
466
467
468@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.iostar.datadir")
469def test_iostar():
470 def _check_subset(samples, size, height, width):
471 assert len(samples) == size
472 for s in samples:
473 assert len(s) == 4
474 assert isinstance(s[0], str)
475 assert s[1].shape, (3, height == width) # planes, height, width
476 assert s[1].dtype == torch.float32
477 assert s[2].shape, (1, height == width) # planes, height, width
478 assert s[2].dtype == torch.float32
479 assert s[3].shape, (1, height == width) # planes, height, width
480 assert s[3].dtype == torch.float32
481 assert s[1].max() <= 1.0
482 assert s[1].min() >= 0.0
483
484 for m in ("vessel", "optic_disc"):
485 d = importlib.import_module(
486 f"....binseg.configs.datasets.iostar.{m}", package=__name__
487 ).dataset
488 assert len(d) == 4
489 _check_subset(d["__train__"], 20, 1024, 1024)
490 _check_subset(d["train"], 20, 1024, 1024)
491 _check_subset(d["test"], 10, 1024, 1024)
492
493 for m in ("vessel_768", "optic_disc_768"):
494 d = importlib.import_module(
495 f"....binseg.configs.datasets.iostar.{m}", package=__name__
496 ).dataset
497 assert len(d) == 4
498 _check_subset(d["__train__"], 20, 768, 768)
499 _check_subset(d["train"], 20, 768, 768)
500 _check_subset(d["test"], 10, 768, 768)
501
502 from ...binseg.configs.datasets.iostar.optic_disc_512 import dataset
503
504 assert len(dataset) == 4
505 _check_subset(dataset["__train__"], 20, 512, 512)
506 _check_subset(dataset["train"], 20, 512, 512)
507 _check_subset(dataset["test"], 10, 512, 512)
508
509
510@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drive.datadir")
511@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.chasedb1.datadir")
512@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.hrf.datadir")
513@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.iostar.datadir")
514def test_iostar_mtest():
515
516 from ...binseg.configs.datasets.iostar.vessel_mtest import dataset
517
518 assert len(dataset) == 10
519
520 from ...binseg.configs.datasets.iostar.vessel import dataset as baseline
521
522 assert dataset["train"] == baseline["train"]
523 assert dataset["test"] == baseline["test"]
524
525 for subset in dataset:
526 for sample in dataset[subset]:
527 assert len(sample) == 4
528 assert isinstance(sample[0], str)
529 assert sample[1].shape, (3, 1024 == 1024) # planes,height,width
530 assert sample[1].dtype == torch.float32
531 assert sample[2].shape, (1, 1024 == 1024) # planes,height,width
532 assert sample[2].dtype == torch.float32
533 assert sample[3].shape, (1, 1024 == 1024)
534 assert sample[3].dtype == torch.float32
535 assert sample[1].max() <= 1.0
536 assert sample[1].min() >= 0.0
537
538
539@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drive.datadir")
540@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.chasedb1.datadir")
541@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.hrf.datadir")
542@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.iostar.datadir")
543def test_iostar_covd():
544
545 from ...binseg.configs.datasets.iostar.covd import dataset
546
547 assert len(dataset) == 4
548
549 from ...binseg.configs.datasets.iostar.vessel import dataset as baseline
550
551 assert dataset["train"] == dataset["__valid__"]
552 assert dataset["test"] == baseline["test"]
553
554 # these are the only different sets from the baseline
555 for key in ("__train__", "train"):
556 assert len(dataset[key]) == 133
557 for sample in dataset[key]:
558 assert len(sample) == 4
559 assert isinstance(sample[0], str)
560 assert sample[1].shape, (3, 1024 == 1024)
561 assert sample[1].dtype == torch.float32
562 assert sample[2].shape, (1, 1024 == 1024)
563 assert sample[2].dtype == torch.float32
564 assert sample[3].shape, (1, 1024 == 1024)
565 assert sample[3].dtype == torch.float32
566 assert sample[1].max() <= 1.0
567 assert sample[1].min() >= 0.0
568
569
570@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.refuge.datadir")
571def test_refuge():
572 def _check_subset(samples, size, height, width):
573 assert len(samples) == size
574 for s in samples[:N]:
575 assert len(s) == 4
576 assert isinstance(s[0], str)
577 assert s[1].shape, (3, height == width) # planes, height, width
578 assert s[1].dtype == torch.float32
579 assert s[2].shape, (1, height == width) # planes, height, width
580 assert s[2].dtype == torch.float32
581 assert s[1].max() <= 1.0
582 assert s[1].min() >= 0.0
583
584 for m in ("disc", "cup"):
585 d = importlib.import_module(
586 f"....binseg.configs.datasets.refuge.{m}", package=__name__
587 ).dataset
588 assert len(d) == 5
589 _check_subset(d["__train__"], 400, 1632, 1632)
590 _check_subset(d["train"], 400, 1632, 1632)
591 _check_subset(d["validation"], 400, 1632, 1632)
592 _check_subset(d["test"], 400, 1632, 1632)
593
594 for m in ("disc_512", "cup_512"):
595 d = importlib.import_module(
596 f"....binseg.configs.datasets.refuge.{m}", package=__name__
597 ).dataset
598 assert len(d) == 5
599 _check_subset(d["__train__"], 400, 512, 512)
600 _check_subset(d["train"], 400, 512, 512)
601 _check_subset(d["validation"], 400, 512, 512)
602 _check_subset(d["test"], 400, 512, 512)
603
604 for m in ("disc_768", "cup_768"):
605 d = importlib.import_module(
606 f"....binseg.configs.datasets.refuge.{m}", package=__name__
607 ).dataset
608 assert len(d) == 5
609 _check_subset(d["__train__"], 400, 768, 768)
610 _check_subset(d["train"], 400, 768, 768)
611 _check_subset(d["validation"], 400, 768, 768)
612 _check_subset(d["test"], 400, 768, 768)
613
614
615@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drishtigs1.datadir")
616def test_drishtigs1():
617 def _check_subset(samples, size, height, width):
618 assert len(samples) == size
619 for s in samples[:N]:
620 assert len(s) == 4
621 assert isinstance(s[0], str)
622 assert s[1].shape, (3, height == width) # planes, height, width
623 assert s[1].dtype == torch.float32
624 assert s[2].shape, (1, height == width) # planes, height, width
625 assert s[2].dtype == torch.float32
626 assert s[1].max() <= 1.0
627 assert s[1].min() >= 0.0
628
629 for m in ("disc_all", "cup_all", "disc_any", "cup_any"):
630 d = importlib.import_module(
631 f"....binseg.configs.datasets.drishtigs1.{m}", package=__name__
632 ).dataset
633 assert len(d) == 4
634 _check_subset(d["__train__"], 50, 1760, 2048)
635 _check_subset(d["train"], 50, 1760, 2048)
636 _check_subset(d["test"], 51, 1760, 2048)
637
638 for m in ("disc_all_512", "cup_all_512"):
639 d = importlib.import_module(
640 f"....binseg.configs.datasets.drishtigs1.{m}", package=__name__
641 ).dataset
642 assert len(d) == 4
643 _check_subset(d["__train__"], 50, 512, 512)
644 _check_subset(d["train"], 50, 512, 512)
645 _check_subset(d["test"], 51, 512, 512)
646 for m in ("disc_all_768", "cup_all_768"):
647 d = importlib.import_module(
648 f"....binseg.configs.datasets.drishtigs1.{m}", package=__name__
649 ).dataset
650 assert len(d) == 4
651 _check_subset(d["__train__"], 50, 768, 768)
652 _check_subset(d["train"], 50, 768, 768)
653 _check_subset(d["test"], 51, 768, 768)
654
655
656@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.rimoner3.datadir")
657def test_rimoner3():
658 def _check_subset(samples, size, height, width):
659 assert len(samples) == size
660 for s in samples[:N]:
661 assert len(s) == 4
662 assert isinstance(s[0], str)
663 assert s[1].shape, (3, height == width) # planes, height, width
664 assert s[1].dtype == torch.float32
665 assert s[2].shape, (1, height == width) # planes, height, width
666 assert s[2].dtype == torch.float32
667 assert s[1].max() <= 1.0
668 assert s[1].min() >= 0.0
669
670 for m in ("disc_exp1", "cup_exp1", "disc_exp2", "cup_exp2"):
671 d = importlib.import_module(
672 f"....binseg.configs.datasets.rimoner3.{m}", package=__name__
673 ).dataset
674 assert len(d) == 4
675 _check_subset(d["__train__"], 99, 1440, 1088)
676 _check_subset(d["train"], 99, 1440, 1088)
677 _check_subset(d["test"], 60, 1440, 1088)
678
679 for m in ("disc_exp1_512", "cup_exp1_512"):
680 d = importlib.import_module(
681 f"....binseg.configs.datasets.rimoner3.{m}", package=__name__
682 ).dataset
683 assert len(d) == 4
684 _check_subset(d["__train__"], 99, 512, 512)
685 _check_subset(d["train"], 99, 512, 512)
686 _check_subset(d["test"], 60, 512, 512)
687
688 for m in ("disc_exp1_768", "cup_exp1_768"):
689 d = importlib.import_module(
690 f"....binseg.configs.datasets.rimoner3.{m}", package=__name__
691 ).dataset
692 assert len(d) == 4
693 _check_subset(d["__train__"], 99, 768, 768)
694 _check_subset(d["train"], 99, 768, 768)
695 _check_subset(d["test"], 60, 768, 768)
696
697
698@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drionsdb.datadir")
699def test_drionsdb():
700 def _check_subset(samples, size, height, width):
701 assert len(samples) == size
702 for s in samples[:N]:
703 assert len(s) == 4
704 assert isinstance(s[0], str)
705 assert s[1].shape, (3, height == width) # planes, height, width
706 assert s[1].dtype == torch.float32
707 assert s[2].shape, (1, height == width) # planes, height, width
708 assert s[2].dtype == torch.float32
709 assert s[1].max() <= 1.0
710 assert s[1].min() >= 0.0
711
712 for m in ("expert1", "expert2"):
713 d = importlib.import_module(
714 f"....binseg.configs.datasets.drionsdb.{m}", package=__name__
715 ).dataset
716 assert len(d) == 4
717 _check_subset(d["__train__"], 60, 416, 608)
718 _check_subset(d["train"], 60, 416, 608)
719 _check_subset(d["test"], 50, 416, 608)
720
721 for m in ("expert1_512", "expert2_512"):
722 d = importlib.import_module(
723 f"....binseg.configs.datasets.drionsdb.{m}", package=__name__
724 ).dataset
725 assert len(d) == 4
726 _check_subset(d["__train__"], 60, 512, 512)
727 _check_subset(d["train"], 60, 512, 512)
728 _check_subset(d["test"], 50, 512, 512)
729
730 for m in ("expert1_768", "expert2_768"):
731 d = importlib.import_module(
732 f"....binseg.configs.datasets.drionsdb.{m}", package=__name__
733 ).dataset
734 assert len(d) == 4
735 _check_subset(d["__train__"], 60, 768, 768)
736 _check_subset(d["train"], 60, 768, 768)
737 _check_subset(d["test"], 50, 768, 768)
738
739
740@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.drive.datadir")
741@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.chasedb1.datadir")
742@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.hrf.datadir")
743@pytest.mark.skip_if_rc_var_not_set("bob.ip.binseg.iostar.datadir")
744def test_combined_vessels():
745 def _check_subset(samples, size, height, width):
746 assert len(samples) == size
747 for s in samples[:N]:
748 assert len(s) == 4
749 assert isinstance(s[0], str)
750 assert s[1].shape, (3, height == width) # planes, height, width
751 assert s[1].dtype == torch.float32
752 assert s[2].shape, (1, height == width) # planes, height, width
753 assert s[2].dtype == torch.float32
754 assert s[1].max() <= 1.0
755 assert s[1].min() >= 0.0
756
757 from ...binseg.configs.datasets.combined.vessel_combined import dataset
758
759 assert len(dataset) == 4
760 _check_subset(dataset["__train__"], 73, 768, 768)
761 _check_subset(dataset["__valid__"], 73, 768, 768)
762 _check_subset(dataset["train"], 73, 768, 768)
763 _check_subset(dataset["test"], 90, 768, 768)