Странная ошибка Assert d == self.d в FAISS с ResNet50Python

Программы на Python
Anonymous
Странная ошибка Assert d == self.d в FAISS с ResNet50

Сообщение Anonymous »

Код, который я написал:

Код: Выделить всё

import faiss
import os
import numpy as np
import torch
from torchvision.models import resnet50
from torchvision.models import ResNet50_Weights
from torchvision import transforms
from PIL import Image

accepted_formats = [".jpg", ".png", ".jpeg"]

image_dir = "images"

preprocess = transforms.Compose([
transforms.Resize((256, 256)),
transforms.ToTensor()
])

weights = ResNet50_Weights.DEFAULT

def load_images_into_index(index):
images = os.listdir(image_dir)
model = resnet50(weights=weights)
model.eval()
for image in images:
if image.lower().endswith(tuple(accepted_formats)):
image_tensor = preprocess(Image.open(image_dir + "/" + image).convert("RGB"))
with torch.no_grad():
features = model(image_tensor.unsqueeze(0))
features = features.detach().cpu().numpy()
faiss.normalize_L2(features)
index.add(features)

index = faiss.IndexFlatL2()
load_images_into_index(index)

Я получил ошибку: «assert d == self.d» AssertionError.

Подробнее здесь: https://stackoverflow.com/questions/789 ... h-resnet50

Вернуться в «Python»