our_knp/objects/fetch_fresh_test.py
int 8f126bc29a Exact spiking pipeline simulator, fresh test set, night log
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 00:13:52 +03:00

40 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Download CIFAR-10 JPEG mirror TEST images 0700–0999 for cat and dog (never used: a fresh final test set).
Same source and commit as cats-dogs/prepare_jpeg.py. Existing files are skipped.
usage: python3 fetch_more.py
"""
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
import time
import urllib.request
COMMIT = 'd7d05618061fe37d830fb0419063d113c575ccbc'
BASE = f'https://raw.githubusercontent.com/YoongiKim/CIFAR-10-images/{COMMIT}'
cache = Path('/home/int/run/cats-dogs/data/github-jpeg-cache')
def load(item):
label, index = item
path = cache / f'test-{label}-{index:04d}.jpg'
if path.exists():
return 0
for attempt in range(6):
try:
with urllib.request.urlopen(f'{BASE}/test/{label}/{index:04d}.jpg', timeout=30) as r:
data = r.read()
tmp = path.with_suffix('.part')
tmp.write_bytes(data)
tmp.rename(path)
return 1
except Exception:
if attempt == 5:
raise
time.sleep(3 * (attempt + 1))
items = [(label, i) for label in ('cat', 'dog') for i in range(700, 1000)]
with ThreadPoolExecutor(max_workers=8) as pool:
for n, _ in enumerate(pool.map(load, items)):
if n % 500 == 0:
print('done', n, flush=True)
print('all', len(items), flush=True)