Skip to content

Models

Choose a tag to compare

@kjsman kjsman released this 21 Aug 04:47
· 5 commits to main since this release
28047f9

I can't provide NeuralHash model because it is proprietary. Check out AsuharietYgvar/AppleNeuralHash2ONNX to extract the NeuralHash model.

NeuralHash Classifier code:

from PIL import Image
import numpy as np
import onnxruntime
from ast import literal_eval

neuralhash = "2273310f003ae9db0c3ff2f2"

oc_session = onnxruntime.InferenceSession("oc.onnx")

with open('imagenet1000_clsidx_to_labels.txt') as f:
    idx2name = literal_eval(f.read())

data = np.unpackbits(np.frombuffer(bytes.fromhex(neuralhash), dtype=np.uint8)).reshape((-1, 96)).astype(np.float32)

inputs = {oc_session.get_inputs()[0].name: data}
outs = oc_session.run(None, inputs)

result = np.argsort(-outs[0][0])[:10]

names = map(lambda x: idx2name[x], result)
probs = (outs[0][0][result] * 100).tolist()
pretty_result = map(lambda x: f"({x[1]:5.2f}%) {x[0]}", zip(names, probs))
print('\n'.join(pretty_result))

oc.zip is the TF SavedModel of classifier.