DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Bias and Shortcut Tests for Vision Models: A Practical Test Suite From Real-World Experiments
  • Architectural Understanding of CPUs, GPUs, and TPUs
  • Building Green AI: Lessons in GPU Efficiency From the Trenches
  • The Illusion of Deep Learning: Why "Stacking Layers" Is No Longer Enough

Trending

  • LLM Integration in Enterprise Applications: A Practical Guide
  • How AI Is Rewriting Full-Stack Java Systems: Practical Patterns with Spring Boot, Kafka and WebSockets
  • Code Quality Had 5 Pillars. AI Broke 3 and Created 2 We Can’t Measure
  • Stop Writing Dialect-Specific SQL: A Unified Query Builder for Node.js
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Building a Recommendation System Using Deep Learning Models

Building a Recommendation System Using Deep Learning Models

This tutorial explains how we can integrate some deep learning models in order to make an outfit recommendation system.

By 
Tonatiuh Banda user avatar
Tonatiuh Banda
·
Andres Vazquez Avina user avatar
Andres Vazquez Avina
·
Updated Jan. 07, 20 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
20.0K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, I am going to explain how we integrate some deep learning models, in order to make an outfit recommendation system. We want to build an outfit recommendation system. We used four deep learning models to get some important characteristics of the clothing used by the user.

The recommendation systems can be classified into 4 groups:

  • Recommendation based on product characteristics
  • Recommendation based on the behavior that other users have with the product
  • Recommendation based on the user's general characteristics
  • Recommendation based on more than one of the previously mentioned criteria

In our case, we are going to make recommendations based on the user and product characteristics. The user characteristics that we took into account were gender, age, and body mass index (BMI). The product characteristics we took into account were the type of clothes the user is wearing. So we need a photograph of the user in order to make the predictions of all the characteristics we need to make the outfit recommendation.

We are going to obtain the garment characteristics from a full-body image of the user.

We use a pose estimator named AlphaPose to determine if the user is complete or not. Alpha Pose detects 19 key points of a person. If it detects at least 17 points, we assume that the person is complete.

Image titleImage 1: AlphaPose estimation

We retrained one of the most known classifiers on the web, YOLO v3. YOLO is also one of the most accurate image classifiers. The data set, used for the training is a small set of the huge MMLAB data set, DeepFashion.

The other model used was the Dlib, get_frontal_face_detector(). This model is built over 5 HOG filters. The model detects the front view faces and side view faces. This model was chosen because it has great accuracy and is very quick. For age and gender detection, we followed the data science post where they use openCV and a convolutional neural network for the age and gender classifications.

For the IMC estimate, we based in the article “Estimating Body Mass Index from face images using Keras and transfer learning”

Image titleImage 2: Architecture of the recommendation system

Models Integration

All the code was written in Python3.5 using some computer vision libraries like OpenCV and some deep learning frameworks like Keras.

Java




xxxxxxxxxx
1
31


 
1
detector = dlib.get_frontal_face_detector()
2
# Carga de modelos
3
# CNN
4
age_net, gender_net = load_caffe_models()
5
# Boddy Mass Index
6
model_bmi = get_trained_model()
7
### Face Detection
8
img_h, img_w, _ = np.shape(image)
9
detected = detector(image, 1)
10
faces
11
=
12
np.empty((1,
13
config.RESNET50_DEFAULT_IMG_WIDTH, 3))
14
config.RESNET50_DEFAULT_IMG_WIDTH,detection = {}
15
if len(detected) > 0:
16
  for i, d in enumerate(detected):
17
    x1, y1, x2, y2, w, h = d.left(), d.top(), d.right() + 1, d.bottom() + 1, d.width(),
18
    d.height()
19
    xw1 = max(int(x1 - margin * w), 0)
20
    yw1 = max(int(y1 - margin * h), 0)
21
    xw2 = min(int(x2 + margin * w), img_w - 1)
22
    yw2 = min(int(y2 + margin * h), img_h - 1)
23
    cv2.rectangle(image, (xw1, yw1), (xw2, yw2), (255, 0, 0), 2)
24
    #Get Face
25
    face_img = frame[yw1:yw2, xw1:xw2].copy()
26
    # Estimación
27
    age, gender = get_age_and_gender(face_img, age_net, gender_net)
28
    # Boddy Mass Index
29
    faces[0,:,:,:]=cv2.resize(face_img,(config.RESNET50_DEFAULT_IMG_WIDTH, 3 )) /255.00
30
    bmi = round(float(model_bmi.predict(faces)[0][0]),2)
31
    detection[i]={'gender':gender, 'age':age, 'bmi':bmi}



In these few lines, we load the model to RAM and make the pose estimation. We also cut the area of the image where the face is in order to estimate age, gender, and BMI. Then we make the clothes classification with YOLO and get the type of clothes we’ll recommend.

Java
x
 
1
def eval_cloth(img_test, categoria_test, size_test):
2
  filename = './ClothEmbedding/X_reduced2.sav'
3
  X_reduced, hasher, pca, df = joblib.load(filename)
4
  img = cv2.imread(img_test)
5
  img_c = cv2.resize(img, (80, 80), interpolation=cv2.INTER_CUBIC)
6
  img_data_test = img_c.reshape(-1).astype(np.float32)
7
  img_transformed = hasher.transform(img_data_test.reshape(1, -1))
8
  img_reduced = pca.transform(img_transformed)
9
  # Distancia entre la muestra y la base de datos
10
  dist = [np.linalg.norm(img_reduced-e) for e in X_reduced]
11
  df['distance'] = dist
12
  df_test = df.sort_values(['distance'])
13
  # Se conserva sólo la categiría requerida
14
  df_test = df_test[df_test['categoria2'] == categoria_test]
15
  # Se conservan sólo las tallas requeridas
16
  cat_ns = ['tacones', 'chanclas', 'botas', 'bolsa', 'ropa_interior']
17
  if not(categoria_test in cat_ns):
18
    if (len(size_test) == 2):
19
  true_table = [(size_test[0] in sizes_r or size_test[1] in sizes_r) for sizes_r in df_test['tallas']]
20
    else:
21
  true_table = [size_test[0] in sizes_r for sizes_r in df_test['tallas']]
22
  df_test = df_test[true_table]
23
  return df_test
13
  # Se conserva sólo la categiría requerida


This last function receives all the information of the person and the clothes. The clothing characteristics are compared to the clothes in our database and the recommendations are made by an embedding. We recommend similar clothes to the ones the user is wearing.

And last, thinking in the UX, we made a front end.

Image titleImage 3: Web view built for the recommendation system

Thanks for reading! Let me know your thoughts in the comments.

Deep learning

Opinions expressed by DZone contributors are their own.

Related

  • Bias and Shortcut Tests for Vision Models: A Practical Test Suite From Real-World Experiments
  • Architectural Understanding of CPUs, GPUs, and TPUs
  • Building Green AI: Lessons in GPU Efficiency From the Trenches
  • The Illusion of Deep Learning: Why "Stacking Layers" Is No Longer Enough

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook