机器学习笔记 - 使用 ResNet-50 和余弦相似度的基于图像的推荐系统

一、简述

        这里的代码主要是基于图像的推荐系统,该系统利用 ResNet-50 深度学习模型作为特征提取器,并采用余弦相似度来查找给定输入图像的最相似嵌入。

        该系统旨在根据所提供图像的视觉内容为用户提供个性化推荐。

二、所需环境

Python 3.x
tensorflow ==2.5.0
numpy==1.21.0
streamlit
pillow==8.3.1
pandas

三、特征提取

        首先加载ResNet50的基于imagenet预训练模型。

        冻结模型的权重,使其在训练过程中不会更新。

        创建一个新模型,在ResNet50模型之后添加一个GlobalMaxPooling2D层。

        使用预先训练的模型从图像中提取特征。

import tensorflow as tf
import numpy as np
from numpy.linalg import norm
import os
from tqdm import tqdm
import pickle

# Load the pre-trained ResNet50 model
model = tf.keras.applications.resnet50.ResNet50(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
# Freeze the model's weights, so they won't be updated during training
model.trainable = False

# Create a ne

猜你喜欢

转载自blog.csdn.net/bashendixie5/article/details/132128621