Spaces:
Paused
Paused
victorli commited on
Commit ·
c963ad3
1
Parent(s): aa37a55
partially fixed rexvqa benchmark
Browse files
benchmarking/benchmarks/rexvqa_benchmark.py
CHANGED
|
@@ -152,39 +152,58 @@ class ReXVQABenchmark(Benchmark):
|
|
| 152 |
print("Images already extracted.")
|
| 153 |
else:
|
| 154 |
try:
|
| 155 |
-
# Stream extract with filtering for test-only images
|
| 156 |
-
print("Stream extracting zstd-compressed tar file with filtering...")
|
| 157 |
-
|
| 158 |
# Create a decompressor
|
| 159 |
dctx = zstd.ZstdDecompressor()
|
| 160 |
-
|
| 161 |
# Stream extract with filtering
|
| 162 |
extracted_count = 0
|
| 163 |
-
|
| 164 |
-
|
| 165 |
with open(tar_path, 'rb') as compressed_file:
|
| 166 |
with dctx.stream_reader(compressed_file) as decompressed_stream:
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
# Clean up compressed tar file after successful extraction
|
| 190 |
print("Cleaning up compressed tar file...")
|
|
|
|
| 152 |
print("Images already extracted.")
|
| 153 |
else:
|
| 154 |
try:
|
| 155 |
+
# Stream extract with filtering for test-only images (no seeking)
|
| 156 |
+
print("Stream extracting zstd-compressed tar file with filtering (streaming mode)...")
|
| 157 |
+
|
| 158 |
# Create a decompressor
|
| 159 |
dctx = zstd.ZstdDecompressor()
|
| 160 |
+
|
| 161 |
# Stream extract with filtering
|
| 162 |
extracted_count = 0
|
| 163 |
+
total_png_members = 0
|
| 164 |
+
|
| 165 |
with open(tar_path, 'rb') as compressed_file:
|
| 166 |
with dctx.stream_reader(compressed_file) as decompressed_stream:
|
| 167 |
+
# Use streaming tar mode to avoid seeks
|
| 168 |
+
with tarfile.open(fileobj=decompressed_stream, mode='r|') as tar:
|
| 169 |
+
for member in tar:
|
| 170 |
+
# Only consider PNG files
|
| 171 |
+
if not member.isfile() or not member.name.endswith('.png'):
|
| 172 |
+
continue
|
| 173 |
+
total_png_members += 1
|
| 174 |
+
|
| 175 |
+
# Normalize name to match entries gathered from JSON
|
| 176 |
+
normalized_name = member.name.lstrip('./')
|
| 177 |
+
|
| 178 |
+
# Decide whether to extract this file
|
| 179 |
+
should_extract = True
|
| 180 |
+
if test_only:
|
| 181 |
+
should_extract = normalized_name in test_image_paths
|
| 182 |
+
|
| 183 |
+
if not should_extract:
|
| 184 |
+
# Must still advance the stream for this member
|
| 185 |
+
tar.members = [] # no-op in stream mode; ensure we don't hold refs
|
| 186 |
+
continue
|
| 187 |
+
|
| 188 |
+
# Ensure parent directories exist and write file by streaming
|
| 189 |
+
target_path = Path(images_dir) / normalized_name
|
| 190 |
+
target_path.parent.mkdir(parents=True, exist_ok=True)
|
| 191 |
+
|
| 192 |
+
extracted_file_obj = tar.extractfile(member)
|
| 193 |
+
if extracted_file_obj is None:
|
| 194 |
+
continue
|
| 195 |
+
with open(target_path, 'wb') as out_f:
|
| 196 |
+
while True:
|
| 197 |
+
chunk = extracted_file_obj.read(1024 * 1024)
|
| 198 |
+
if not chunk:
|
| 199 |
+
break
|
| 200 |
+
out_f.write(chunk)
|
| 201 |
+
|
| 202 |
+
extracted_count += 1
|
| 203 |
+
if extracted_count % 100 == 0:
|
| 204 |
+
print(f"Extracted {extracted_count} test images...")
|
| 205 |
+
|
| 206 |
+
print(f"Extraction completed! Extracted {extracted_count} matching PNGs out of {total_png_members} PNG members in the archive")
|
| 207 |
|
| 208 |
# Clean up compressed tar file after successful extraction
|
| 209 |
print("Cleaning up compressed tar file...")
|