|
|
|
|
|
|
|
|
|
|
|
import sys |
|
|
import random |
|
|
import pathlib |
|
|
import subprocess |
|
|
import PIL.Image |
|
|
|
|
|
|
|
|
|
|
|
REPO_ROOT = pathlib.Path(__file__).parent.resolve() |
|
|
NOVIC_DIR = REPO_ROOT / 'novic' |
|
|
NOVIC_TEST = NOVIC_DIR / '__init__.py' |
|
|
if not NOVIC_TEST.exists(): |
|
|
print("Initialising git submodules as NOVIC code was not found yet...") |
|
|
subprocess.run(['git', 'submodule', 'update', '--init', '--recursive'], cwd=REPO_ROOT, check=True) |
|
|
if not NOVIC_TEST.exists(): |
|
|
raise RuntimeError("Failed to find NOVIC code") |
|
|
if str(NOVIC_DIR) not in sys.path: |
|
|
sys.path.insert(0, str(NOVIC_DIR)) |
|
|
|
|
|
|
|
|
import infer |
|
|
print(infer) |
|
|
|
|
|
|
|
|
def classify_image(image: PIL.Image.Image, checkpoint: str) -> dict[str, float]: |
|
|
|
|
|
print(image, checkpoint) |
|
|
labels = ('thing', 'item', 'stuff', 'object', 'entity') |
|
|
probs = [random.random() for _ in labels] |
|
|
prob_sum = sum(probs) |
|
|
return {label: prob / prob_sum for label, prob in zip(labels, probs)} |
|
|
|
|
|
|