Look Up a Result by Object ID#
This notebook shows how to retrieve the inference result for a specific object using Hyrax’s lookup verb.
We’ll use the pre-computed inference results from the Getting Started notebook, where the built-in HyraxCNN model was trained on the CIFAR-10 dataset.
As always, we start by creating a Hyrax instance.
[1]:
from hyrax import Hyrax
h = Hyrax()
Look up a single result with h.lookup()#
h.lookup() returns the model prediction for a given object ID — useful for a quick sanity check on a specific object or similarity search when used with a vector database.
The results_dir argument is optional. If omitted, Hyrax will automatically use the most recent inference output directory.
Note: Object IDs in Hyrax are always strings, even if they look like numbers.
[2]:
example_id = "00326"
result_directory = "./example_results/getting_started_results"
h.lookup(id=example_id, results_dir=result_directory)
[2]:
array([[-0.66786087, -3.1095357 , 1.1876142 , 1.2289915 , 1.4235748 ,
0.5107451 , 1.1837559 , 0.40907362, -0.5396151 , -0.86201495]],
dtype=float32)
As a simple exercise we can find the predicted class using numpy.
[3]:
import numpy as np
prediction = h.lookup(id=example_id, results_dir=result_directory)
print(f"Predicted class: {np.argmax(prediction)}")
Predicted class: 4