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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
5. Data Test Results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
No comments:
Post a Comment