如何使用深度学习模型构建推荐系统?具体案例分析

放大字体  缩小字体 发布日期:2020-02-01  来源:来自互联网  作者:来自互联网  浏览次数:601
导读

本文将解释如何整合深度学习模型,构建服装推荐系统。我们想要建立一个服装推荐系统,可以使用四种深度学习模型来获取用户服装使用的重要特征。 基于一篇名为《利用Keras和转移学习从人脸图像中估计身体质量指数…

全文共3095字,预计学习时长9分钟

全文共3095字,预计学习时长9分钟

来源:Pexels

本文将解释如何整合深度学习模型,构建服装推荐系统。我们想要建立一个服装推荐系统,可以使用四种深度学习模型来获取用户服装使用的重要特征。 推荐系统可分为4类:

  • 基于产品特性的推荐
    • 基于其他用户对产品的行为的推荐
    • 基于用户一般特征的推荐
    • 基于上述多项标准的推荐

    来源:Pexels

    在案例中,我们将根据用户和产品特性提出建议。计入考虑的用户特征是性别、年龄和体重指数(BMI)。计入考虑的产品特征是用户所穿的衣服类型。因此,我们需要一张用户的照片,对所有特征进行预测,推荐相应的服装。 将从用户的全身图像中获得服装特征。 使用名为AlphaPose的人体姿态估计系统来确定用户是否完整。AlphaPose检测一个人的19个点。如果检测到至少17个点,就认定是完整人形。

    图1: AlphaPose估计系统

    我们重新训练了网上最知名的其中一种分类器——YOLO v3。YOLO同时也是最精确的图像分类器之一。用于训练的数据集是一组巨大的 MMLAB 数据集,DeepFashion。 使用的另一个模型是 Dlib,get_frontal_face_detector()函数。

    此模型由 5 个 HOG 筛选器构建。模型检测前视图面和侧视图面。之所以选择该模型是因为它速度快且精确。在检测年龄和性别时,我们根据数据科学的文章,使用 openCV 和卷积神经网络对年龄和性别进行分类。 基于一篇名为《利用Keras和转移学习从人脸图像中估计身体质量指数》(Estimating Body Mass Index from face images using Keras andtransfer learning)的文章对IMC进行估计。

    图2:推荐系统的体系结构

    模型集成

    所有代码都是使用一些计算机视觉库(如 OpenCV)和一些深度学习框架(如Keras)在 Python3.5 中编写的。

    • detector =dlib.get_frontal_face_detector()# Carga de modelos# CNNage_net, gender_net =load_caffe_models()# Boddy Mass Indexmodel_bmi = get_trained_model()### Face Detectionimg_h, img_w, _ = np.shape(image)detected = detector(image, 1)faces=np.empty((1,config.RESNET50_DEFAULT_IMG_WIDTH, 3))config.RESNET50_DEFAULT_IMG_WIDTH,detection= {}if len(detected) > 0: for i,d in enumerate(detected): x1, y1, x2, y2, w, h = d.left(),d.top(), d.right() + 1, d.bottom() + 1, d.width(), d.height() xw1 = max(int(x1 - margin * w), 0) yw1 = max(int(y1 - margin * h), 0) xw2 = min(int(x2 + margin * w), img_w - 1) yw2 = min(int(y2 + margin * h), img_h - 1) cv2.rectangle(image, (xw1, yw1),(xw2, yw2), (255, 0, 0), 2) #Get Face face_img = frame[yw1:yw2,xw1:xw2].copy() # Estimación age, gender = get_age_and_gender(face_img,age_net, gender_net) # Boddy Mass Index faces[0,:,:,:]=cv2.resize(face_img,(config.RESNET50_DEFAULT_IMG_WIDTH,3 )) /255.00 bmi = round(float(model_bmi.predict(faces)[0][0]),2) detection[i]={'gender':gender, 'age':age, 'bmi':bmi}

    通过这些代码,将模型加载到RAM中进行姿态估计(poseestimation)。

    为了估测年龄、性别和BMI,我们还剪切了脸部所在的区域。然后,使用 YOLO 对衣服进行分类,显示推荐的衣服类型。

    • def eval_cloth(img_test,categoria_test, size_test): filename = './ClothEmbedding/X_reduced2.sav' X_reduced, hasher, pca, df =joblib.load(filename) img = cv2.imread(img_test) img_c = cv2.resize(img, (80, 80), interpolation=cv2.INTER_CUBIC) img_data_test = img_c.reshape(-1).astype(np.float32) img_transformed =hasher.transform(img_data_test.reshape(1, -1)) img_reduced =pca.transform(img_transformed) # Distancia entre la muestra y la basede datos dist = [np.linalg.norm(img_reduced-e) for e in X_reduced] df['distance'] =dist df_test = df.sort_values(['distance']) # Se conserva sólo la categiríarequerida df_test = df_test[df_test['categoria2'] == categoria_test] # Se conservan sólo las tallasrequeridas cat_ns = ['tacones', 'chanclas', 'botas', 'bolsa', 'ropa_interior'] ifnot(categoria_test in cat_ns): if(len(size_test) == 2): true_table = [(size_test[0] in sizes_r or size_test[1] in sizes_r) for sizes_r in df_test['tallas']] else: true_table = [size_test[0] in sizes_r for sizes_r in df_test['tallas']] df_test = df_test[true_table] returndf_test
    • 最后一个功能会接收人和衣服的所有信息。将服装特性与数据库中的服装进行比对。会推荐与用户身着相似的服装。 最后,考虑到用户体验,就做了一个前端。

    图3:为推荐系统构建Web试图

    感谢阅读!记得踊跃发言哟~

    留言点赞发个朋友圈

    我们一起分享AI学习与发展的干货编译组:张淑霏、王小燕

    如转载,请后台留言,遵守转载规范

  • 基于其他用户对产品的行为的推荐
  • 基于用户一般特征的推荐
  • 基于上述多项标准的推荐

来源:Pexels

在案例中,我们将根据用户和产品特性提出建议。计入考虑的用户特征是性别、年龄和体重指数(BMI)。计入考虑的产品特征是用户所穿的衣服类型。因此,我们需要一张用户的照片,对所有特征进行预测,推荐相应的服装。 将从用户的全身图像中获得服装特征。 使用名为AlphaPose的人体姿态估计系统来确定用户是否完整。AlphaPose检测一个人的19个点。如果检测到至少17个点,就认定是完整人形。

图1: AlphaPose估计系统

我们重新训练了网上最知名的其中一种分类器——YOLO v3。YOLO同时也是最精确的图像分类器之一。用于训练的数据集是一组巨大的 MMLAB 数据集,DeepFashion。 使用的另一个模型是 Dlib,get_frontal_face_detector()函数。

此模型由 5 个 HOG 筛选器构建。模型检测前视图面和侧视图面。之所以选择该模型是因为它速度快且精确。在检测年龄和性别时,我们根据数据科学的文章,使用 openCV 和卷积神经网络对年龄和性别进行分类。 基于一篇名为《利用Keras和转移学习从人脸图像中估计身体质量指数》(Estimating Body Mass Index from face images using Keras andtransfer learning)的文章对IMC进行估计。

图2:推荐系统的体系结构

模型集成

所有代码都是使用一些计算机视觉库(如 OpenCV)和一些深度学习框架(如Keras)在 Python3.5 中编写的。

  • detector =dlib.get_frontal_face_detector()# Carga de modelos# CNNage_net, gender_net =load_caffe_models()# Boddy Mass Indexmodel_bmi = get_trained_model()### Face Detectionimg_h, img_w, _ = np.shape(image)detected = detector(image, 1)faces=np.empty((1,config.RESNET50_DEFAULT_IMG_WIDTH, 3))config.RESNET50_DEFAULT_IMG_WIDTH,detection= {}if len(detected) > 0: for i,d in enumerate(detected): x1, y1, x2, y2, w, h = d.left(),d.top(), d.right() + 1, d.bottom() + 1, d.width(), d.height() xw1 = max(int(x1 - margin * w), 0) yw1 = max(int(y1 - margin * h), 0) xw2 = min(int(x2 + margin * w), img_w - 1) yw2 = min(int(y2 + margin * h), img_h - 1) cv2.rectangle(image, (xw1, yw1),(xw2, yw2), (255, 0, 0), 2) #Get Face face_img = frame[yw1:yw2,xw1:xw2].copy() # Estimación age, gender = get_age_and_gender(face_img,age_net, gender_net) # Boddy Mass Index faces[0,:,:,:]=cv2.resize(face_img,(config.RESNET50_DEFAULT_IMG_WIDTH,3 )) /255.00 bmi = round(float(model_bmi.predict(faces)[0][0]),2) detection[i]={'gender':gender, 'age':age, 'bmi':bmi}

通过这些代码,将模型加载到RAM中进行姿态估计(poseestimation)。

为了估测年龄、性别和BMI,我们还剪切了脸部所在的区域。然后,使用 YOLO 对衣服进行分类,显示推荐的衣服类型。

  • def eval_cloth(img_test,categoria_test, size_test): filename = './ClothEmbedding/X_reduced2.sav' X_reduced, hasher, pca, df =joblib.load(filename) img = cv2.imread(img_test) img_c = cv2.resize(img, (80, 80), interpolation=cv2.INTER_CUBIC) img_data_test = img_c.reshape(-1).astype(np.float32) img_transformed =hasher.transform(img_data_test.reshape(1, -1)) img_reduced =pca.transform(img_transformed) # Distancia entre la muestra y la basede datos dist = [np.linalg.norm(img_reduced-e) for e in X_reduced] df['distance'] =dist df_test = df.sort_values(['distance']) # Se conserva sólo la categiríarequerida df_test = df_test[df_test['categoria2'] == categoria_test] # Se conservan sólo las tallasrequeridas cat_ns = ['tacones', 'chanclas', 'botas', 'bolsa', 'ropa_interior'] ifnot(categoria_test in cat_ns): if(len(size_test) == 2): true_table = [(size_test[0] in sizes_r or size_test[1] in sizes_r) for sizes_r in df_test['tallas']] else: true_table = [size_test[0] in sizes_r for sizes_r in df_test['tallas']] df_test = df_test[true_table] returndf_test
  • 最后一个功能会接收人和衣服的所有信息。将服装特性与数据库中的服装进行比对。会推荐与用户身着相似的服装。 最后,考虑到用户体验,就做了一个前端。

图3:为推荐系统构建Web试图

感谢阅读!记得踊跃发言哟~

留言点赞发个朋友圈

我们一起分享AI学习与发展的干货编译组:张淑霏、王小燕

如转载,请后台留言,遵守转载规范

 
 
免责声明
• 
本文为会员免费发布,仅代表发布者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们删除处理。