in searcher/main.py [0:0]
def main(index_endpoint_name: str, deployed_index_id: str, image_path: str) -> None:
print("===== Started making vector =====")
model = tf.keras.applications.EfficientNetB0(include_top=False, pooling="avg")
raw = tf.io.read_file(image_path)
image = tf.image.decode_jpeg(raw, channels=3)
image = tf.image.resize(image, [224, 224])
vector = model.predict(np.array([image.numpy()]))[0].tolist()
# https://github.com/googleapis/python-aiplatform/blob/v1.22.0/google/cloud/aiplatform/matching_engine/matching_engine_index_endpoint.py#L85
endpoint = MatchingEngineIndexEndpoint(index_endpoint_name=index_endpoint_name)
print("===== Started query =====")
# https://github.com/googleapis/python-aiplatform/blob/v1.22.0/google/cloud/aiplatform/matching_engine/matching_engine_index_endpoint.py#L902
res = endpoint.match(
deployed_index_id=deployed_index_id, queries=[vector], num_neighbors=5
)
print("===== Finished query =====")
for neighbor in res[0]:
print(f"{neighbor.id}: distance={neighbor.distance}")