File size: 1,216 Bytes
7ad5fd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# NOVIC interface

# Imports
import sys
import random  # TODO: TEMP
import pathlib
import subprocess
import PIL.Image
# TODO: Then start coding infer.py (ANY additional import has to be clarified with novic_spaces/requirements.txt (pip install -r requirements.txt) and novic/requirements-infer.txt

# Ensure access to NOVIC code
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))

# NOVIC imports
import infer  # TODO: TEMP
print(infer)  # TODO: TEMP

# Classify an image
def classify_image(image: PIL.Image.Image, checkpoint: str) -> dict[str, float]:
	# TODO: TEMP
	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)}
# EOF