File size: 1,678 Bytes
d656622 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | from __future__ import annotations
import base64
import io
import os
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
def main() -> int:
print("[1/3] Load ImageNet-100 challenge candidate")
from perturbnet.imagenet100_bootstrap import load_imagenet100
dataset = load_imagenet100()
example = dataset[0]
buffer = io.BytesIO()
example["image"].convert("RGB").save(buffer, format="JPEG", quality=95)
image_bytes = buffer.getvalue()
print(f" dataset rows={int(dataset.num_rows)} sample=row 0")
image_b64 = base64.b64encode(image_bytes).decode("utf-8")
print("[2/3] Run EfficientNetV2-L inference")
import torch
from perturbnet.image_io import decode_image_b64
from perturbnet.model import load_efficientnet_v2_l, predict_label
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = load_efficientnet_v2_l(device=device)
image = decode_image_b64(image_b64).to(device)
prediction = predict_label(model=model, image_chw=image)
print(f" model_prediction={prediction}")
print("[3/3] Challenge target label will use model prediction directly")
if not prediction:
raise RuntimeError("Model prediction is empty")
print("Smoke test passed.")
return 0
if __name__ == "__main__":
try:
exit_code = main()
except Exception as exc:
print(f"Smoke test failed: {exc}", file=sys.stderr)
exit_code = 1
# Hard-exit: pyarrow/datasets can leave non-joinable IO threads that
# deadlock normal interpreter shutdown.
sys.stdout.flush()
sys.stderr.flush()
os._exit(exit_code)
|