@@ -49,31 +49,35 @@ def __init__(
49
49
super ().__init__ (root , dependencies = ("scipy" ,), skip_integrity_check = skip_integrity_check )
50
50
51
51
def _resources (self ) -> List [OnlineResource ]:
52
- archive = HttpResource (
53
- "https://www2.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/semantic_contours/benchmark.tgz" ,
54
- sha256 = "6a5a2918d5c73ce032fdeba876574d150d9d04113ab87540a1304cbcc715be53" ,
55
- )
56
- extra_split = HttpResource (
57
- "http://home.bharathh.info/pubs/codes/SBD/train_noval.txt" ,
58
- sha256 = "0b2068f7a359d2907431803e1cd63bf6162da37d7d503b589d3b08c6fd0c2432" ,
59
- )
60
- return [archive , extra_split ]
52
+ resources = [
53
+ HttpResource (
54
+ "https://www2.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/semantic_contours/benchmark.tgz" ,
55
+ sha256 = "6a5a2918d5c73ce032fdeba876574d150d9d04113ab87540a1304cbcc715be53" ,
56
+ )
57
+ ]
58
+ if self ._split == "train_noval" :
59
+ resources .append (
60
+ HttpResource (
61
+ "http://home.bharathh.info/pubs/codes/SBD/train_noval.txt" ,
62
+ sha256 = "0b2068f7a359d2907431803e1cd63bf6162da37d7d503b589d3b08c6fd0c2432" ,
63
+ )
64
+ )
65
+ return resources
61
66
62
67
def _classify_archive (self , data : Tuple [str , Any ]) -> Optional [int ]:
63
68
path = pathlib .Path (data [0 ])
64
69
parent , grandparent , * _ = path .parents
65
70
66
- if parent .name == "dataset" :
67
- return 0
68
- elif grandparent .name == "dataset" :
71
+ if grandparent .name == "dataset" :
69
72
if parent .name == "img" :
70
- return 1
73
+ return 0
71
74
elif parent .name == "cls" :
72
- return 2
73
- else :
74
- return None
75
- else :
76
- return None
75
+ return 1
76
+
77
+ if parent .name == "dataset" and self ._split != "train_noval" :
78
+ return 2
79
+
80
+ return None
77
81
78
82
def _prepare_sample (self , data : Tuple [Tuple [Any , Tuple [str , BinaryIO ]], Tuple [str , BinaryIO ]]) -> Dict [str , Any ]:
79
83
split_and_image_data , ann_data = data
@@ -93,21 +97,24 @@ def _prepare_sample(self, data: Tuple[Tuple[Any, Tuple[str, BinaryIO]], Tuple[st
93
97
)
94
98
95
99
def _datapipe (self , resource_dps : List [IterDataPipe ]) -> IterDataPipe [Dict [str , Any ]]:
96
- archive_dp , extra_split_dp = resource_dps
97
-
98
- archive_dp = resource_dps [0 ]
99
- split_dp , images_dp , anns_dp = Demultiplexer (
100
- archive_dp ,
101
- 3 ,
102
- self ._classify_archive ,
103
- buffer_size = INFINITE_BUFFER_SIZE ,
104
- drop_none = True ,
105
- )
106
- split_dp , to_be_closed_dp = (
107
- (extra_split_dp , split_dp ) if self ._split == "train_noval" else (split_dp , extra_split_dp )
108
- )
109
- for _ , file in to_be_closed_dp :
110
- file .close ()
100
+ if self ._split == "train_noval" :
101
+ archive_dp , split_dp = resource_dps
102
+ images_dp , anns_dp = Demultiplexer (
103
+ archive_dp ,
104
+ 2 ,
105
+ self ._classify_archive ,
106
+ buffer_size = INFINITE_BUFFER_SIZE ,
107
+ drop_none = True ,
108
+ )
109
+ else :
110
+ archive_dp = resource_dps [0 ]
111
+ images_dp , anns_dp , split_dp = Demultiplexer (
112
+ archive_dp ,
113
+ 3 ,
114
+ self ._classify_archive ,
115
+ buffer_size = INFINITE_BUFFER_SIZE ,
116
+ drop_none = True ,
117
+ )
111
118
112
119
split_dp = Filter (split_dp , path_comparator ("name" , f"{ self ._split } .txt" ))
113
120
split_dp = LineReader (split_dp , decode = True )
0 commit comments