以图搜图如何生成向量?

可以使用 image2vector

安装方式很简单

pip install image2vector

用起来就更简单了,你不用关心任何深度学习的东西,只要指定 image 就能无脑生成图片的向量

from pathlib import Path
from typing import List
from iv import ResNet, l2

# Initialize a residual neural network
resnet: ResNet = ResNet(
    weight_file='weight/gl18-tl-resnet50-gem-w-83fdc30.pth'
)


# Generate a vector of specified images
# The generated vector is a List[float] data structure,
# the length of the list is 512, which means the vector is of 512 dimensions
vector_1: List[float] = resnet.gen_vector('example-1.jpg')

vector_2: List[float] = resnet.gen_vector('example-2.jpg')

# Compare the Euclidean distance of two vectors

distance: float = l2(vector_1, vector_2)

print('Euclidean Distance is ', distance)

你可能感兴趣的:(python)