Repository navigation
Releases
Releases · kjsman/NeuralHash-Classifier
Hashes of ILSVRC2021 images
NeuralHash of ILSVRC2012 dataset.
This is an SQLite file. You can open this file and read data like this:
import sqlite3
con = sqlite3.connect('ilsnrc.db')
cur = con.cursor()
cur.execute('select * from images')
raw_data = cur.fetchall()
con.close()Models
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.