"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

December 01, 2019

Day #300 - Lessons Learnt from Multi-Label Classification

Today is 300th Post on Data Science. It has been a long journey. Still I feel there is a lot more to catchup. Keep Learning, Keep Going.

There are different tasks involved

1. Data Collection - Fatkun Batch Download Image chrome extension to download images
2. Script to reshape images and store in a standard format
3. Simple DB script to update and prepare data

import pyodbc
import os
files = os.listdir(r'E:\Multi_Label\Input_Data\T-Shirt_Jeans')
base_filepath = r'E:\Multi_Label\Input_Data\T-Shirt_Jeans'
cnxn = pyodbc.connect(r'DRIVER={SQL SERVER};SERVER=XXXXX\SQLEXPRESS;DATABASE=DataGeneration;Trusted_Connection=yes;')
cursor = cnxn.cursor()
for file in files:
filepath = base_filepath + '\\' + file
cursor.execute("insert into Dataset([FileName],[Cap],[Jeans],[Jacket],[TShirt],[Shirt],[Pants]) values (?,0,1,0,1,0,0)",filepath)
cnxn.commit()
cnxn.close()
4. This base implementation was useful for model implementation link
5. Data Test Results

#Test Code
import cv2
import os
import numpy as np
from keras.models import save_model, load_model
test_dataset = r'E:\Multi_Label\Test'
model = load_model(r'E:\Multi_Label\\model_multi_label.h5')
print(model.summary())
test_images = []
arr = os.listdir(test_dataset)
files = []
for file in arr:
path = test_dataset + '\\'+file
img = cv2.imread(path,1)
img = cv2.resize(img,(256,256))
test_images.append([np.array(img)])
files.append(path)
i = 0
for data in test_images:
test_img_data = np.array(data).reshape(-1,256,256,3)
result = model.predict(test_img_data)
#print(result)
item = ['1-Cap','2 Jeans','3 - Jacket','4-TShirt','5-Shirt','6-Pants']
values = []
values.append(result[0][0])
values.append(result[0][1])
values.append(result[0][2])
values.append(result[0][3])
values.append(result[0][4])
values.append(result[0][5])
print(files[i])
if(float(result[0][0])>0.5):
print('Cap')
if(float(result[0][1])>0.5):
print('Jeans')
if(float(result[0][2])>0.5):
print('Jacket')
if(float(result[0][3])>0.5):
print('Tshirt')
if(float(result[0][4])>0.5):
print('Shirt')
if(float(result[0][5])>0.5):
print('Pants')
#print(values)
i = i+1
#E:\Multi_Label\Test\Cap_Jean.jpeg
#Cap
#Jeans
#E:\Multi_Label\Test\Cap_Jean_2.jpeg
#Cap
#Jeans
#E:\Multi_Label\Test\Cap_Jean_3.jpeg
#Cap
#Jeans
#E:\Multi_Label\Test\Jacket_5.jpg
#Cap
#Jeans
#E:\Multi_Label\Test\Jacket_WM2.jpg
#Cap
#Jeans
#Jacket
#E:\Multi_Label\Test\Jacket_WM3.jpg
#Cap
#Jeans
#Jacket
#E:\Multi_Label\Test\Jacket_WM4.jpg
#Cap
#Jeans
#E:\Multi_Label\Test\Jacket_WML1.jpg
#Cap
#Jeans
#E:\Multi_Label\Test\T_Shirt_Target.jpg
#Cap
#Jeans
#E:\Multi_Label\Test\T_Shirt_Target1.jpg
#Cap
#Jeans
view raw Test_Results.py hosted with ❤ by GitHub
Happy Learning!!!


No comments: