Deep Fashion: In Shop Clothes Retrieval Playground

Deep Fashion: In Shop Clothes Retrieval

Just a playground jupyter notebook to check the Deep Fashion dataset and the detection accuracy. Then I also tried the saliency of the given images.

To know more details about the dataset, visit the Deep Fashion project page. The dataset can be downloaded from here.

Import necessary modules

import pandas as pd
import os
import cv2
from matplotlib import pyplot as plt
ROOT_DIR = '/Users/sparrow/Learning/machine-learning/wicked-wench/deep-fashion/in-shop-clothes-retrieval'
DATA_DIR = '/srv/downloads/moshfiqur-ml-datasets/deep-fashion/in-shop-clothes-retrieval'
df_bbox = pd.read_csv(os.path.join(DATA_DIR, 'annotations', 'list_bbox_inshop.txt'), delimiter='t')

Overview of the dataset

df_bbox.head()

.dataframe thead tr:only-child th {
text-align: right;
}

.dataframe thead th {
text-align: left;
}

.dataframe tbody tr th {
vertical-align: top;
}

image_name clothes_type pose_type x_1 y_1 x_2 y_2
0 img/WOMEN/Blouses_Shirts/id_00000001/02_1_fron... 1 1 50 49 208 235
1 img/WOMEN/Blouses_Shirts/id_00000001/02_2_side... 1 2 119 48 136 234
2 img/WOMEN/Blouses_Shirts/id_00000001/02_3_back... 1 3 50 42 213 240
3 img/WOMEN/Blouses_Shirts/id_00000001/02_4_full... 1 4 82 30 162 129
4 img/WOMEN/Dresses/id_00000002/02_1_front.jpg 3 1 65 45 233 252

Lets have a look at a sample image

test_image = cv2.imread(os.path.join(DATA_DIR, 'img/WOMEN/Dresses/id_00000002/02_1_front.jpg'))
test_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2RGB)
plt.imshow(test_image)
plt.show()

png

Test 1: Crop an image with associated bbox

for index, row in df_bbox.iterrows():
    test_image = cv2.imread(os.path.join(DATA_DIR, row['image_name']))
    test_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2RGB)
    plt.imshow(test_image)
    plt.show()

    y_min = row['y_1']
    x_min = row['x_1']
    y_max = row['y_2']
    x_max = row['x_2']

    cropped_image = test_image[y_min:y_max, x_min:x_max]
    print(cropped_image.shape)

    plt.imshow(cropped_image)
    plt.show()

    if index > 10:
        break

png

(186, 158, 3)

png

png

(186, 17, 3)

png

png

(198, 163, 3)

png

png

(99, 80, 3)

png

png

(207, 168, 3)

png

png

(206, 56, 3)

png

png

(133, 80, 3)

png

png

(211, 121, 3)

png

png

(88, 109, 3)

png

png

(99, 10, 3)

png

png

(150, 186, 3)

png

png

(64, 85, 3)

png

Test 2: Crop images into their cloth type directories

def mkdir_p(path):
    try:
        os.makedirs(path)
    except OSError as exc:  # Python >2.5
        if exc.errno == errno.EEXIST and os.path.isdir(path):
            pass
        else:
            raise
image_written_count = 0

for index, row in df_bbox.iterrows():
    _, gender, cloth_type, id_, image_name = row['image_name'].split('/')

    # The side image bbox are very thin and not perfect
    # So we are skipping them for now
    if 'side' in image_name:
        continue

    test_image = cv2.imread(os.path.join(DATA_DIR, row['image_name']))
    test_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2RGB)

    x_min = row['x_1']
    y_min = row['y_1']
    x_max = row['x_2']
    y_max = row['y_2']

    cropped_image = test_image[y_min:y_max, x_min:x_max]
    cropped_image = cv2.cvtColor(cropped_image, cv2.COLOR_BGR2RGB)

    output_dir = os.path.join(DATA_DIR, 'cropped_img', gender, cloth_type)

    if not os.path.isdir(output_dir):
        mkdir_p(output_dir)

    cv2.imwrite(os.path.join(output_dir, cloth_type+'_'+id_+'_'+image_name), cropped_image)

    # if index > 10:
    #     break

    image_written_count += 1

    if image_written_count % 10 == 0:
        print(image_written_count, 'images has been cropped')

Test 3: Saliency detection

for index, row in df_bbox.iterrows():
    test_image = cv2.imread(os.path.join(DATA_DIR, row['image_name']))
    test_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2RGB)
    plt.imshow(test_image)
    plt.show()

    # initialize OpenCV's static saliency spectral residual detector and
    # compute the saliency map
    saliency = cv2.saliency.StaticSaliencySpectralResidual_create()
    (success, saliencyMap) = saliency.computeSaliency(test_image)
    saliencyMap = (saliencyMap * 255).astype("uint8")
    # cv2.imshow("Image", image)
    # cv2.imshow("Output", saliencyMap)
    # cv2.waitKey(0)

    plt.imshow(saliencyMap)
    plt.show()

    if index > 10:
        break

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

Test 4: Saliency detection with different settings

for index, row in df_bbox.iterrows():
    test_image = cv2.imread(os.path.join(DATA_DIR, row['image_name']))
    test_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2RGB)
    plt.imshow(test_image)
    plt.show()

    # initialize OpenCV's static fine grained saliency detector and
    # compute the saliency map
    saliency = cv2.saliency.StaticSaliencyFineGrained_create()
    (success, saliencyMap) = saliency.computeSaliency(test_image)

    # if we would like a *binary* map that we could process for contours,
    # compute convex hull's, extract bounding boxes, etc., we can
    # additionally threshold the saliency map
    threshMap = cv2.threshold(saliencyMap, 0, 255,
        cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]

    plt.imshow(saliencyMap)
    plt.show()
    plt.imshow(threshMap)
    plt.show()

    if index > 10:
        break

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

png

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back To Top