1、简述
接近实时获取相似图像是图像检索系统的重要用例 。在这里,我们使用局部敏感哈希 (LSH) 和顶部的随机投影构建类似的图像搜索实用程序,由预训练图像分类器计算的图像表示。 这种搜索引擎也是众所周知的 作为近似重复(或近重复)图像检测器。 我们还将研究优化在GPU上使用TensorRT的搜索实用程序。
2、导入包
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
import time
import tensorflow_datasets as tfds
tfds.disable_progress_bar()
3、加载数据集
为了缩短示例的运行时间,我们将使用 1000 张图像的子集。
train_ds, validation_ds = tfds.load(
"tf_flowers", split=["train[:85%]", "train[85%:]"], as_supervised=True
)
IMAGE_SIZE = 224
NUM_IMAGES = 1000
images = []
labels = []
for (image, label) in train_ds.take(NUM_IMAGES):
image = tf.image.resize(image, (IMAGE_SIZE, IMAGE_SIZE))
images.append(image.numpy())
labels.append(label.numpy())
images = np.array(images)
labels = np.array(labels)