Выход vgg16 — NAN, torchvision 0,19Python

Программы на Python
Anonymous
Выход vgg16 — NAN, torchvision 0,19

Сообщение Anonymous »

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

vgg16=models.vgg16(weights=models.VGG16_Weights.IMAGENET1K_FEATURES).eval()

for param in vgg16.parameters():
param.requires_grad = False

def load_image(img_path):

input_image = Image.open(img_path)
if input_image.mode == 'RGBA':
input_image = input_image.convert('RGB')
input_image = np.array(input_image)
convert_tensor = transforms.ToTensor()
input_image=convert_tensor(input_image)
input_image=input_image
preprocess= models.VGG16_Weights.IMAGENET1K_FEATURES.transforms()
done=preprocess(input_image)
print(done.shape)
#print(done.shape, type(done))
#resized_image = input_image.resize((224, 224))
return done

def img_embeddings(image):
#print(image)
image_embedding = vgg16(image)
return image_embedding

def simmilarity(image_one, image_two):
first=load_image(image_one)
second=load_image(image_two)
first_vector= img_embeddings(first)
second_vector=img_embeddings(second)
Я пытаюсь вычислить косинусное сходство двух изображений. Я понятия не имею, почему vgg16 возвращает значения NaN в тензоре при внедрении изображений. Есть идеи?

Подробнее здесь: https://stackoverflow.com/questions/790 ... ision-0-19

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