Skip to main content

Multiple classification from many of directories

 # %%  Import nessacary libraries


import numpy as np
import pandas as pd
import cv2
import matplotlib.pyplot as plt
import os
import glob

# %%   Keras Tensorflow libraries

from keras import layers
from keras.models import Model
from keras.optimizers import RMSprop , Adam , Nadam
from keras.preprocessing.image import ImageDataGenerator
from keras.layers import Input, BatchNormalization, Dense, Dropout, Conv2D, Flatten, GlobalAveragePooling2D, LeakyReLU
from keras.preprocessing.image import ImageDataGenerator, img_to_array, load_img

# %%  Path

path = r'G:/Machine Learning/Project/Lego Mnifigures Classification/dataset'

open_dir = os.listdir(path)
open_dir


# %%  Visualization in array form

cv2.imread('G:/Machine Learning/Project/Lego Mnifigures Classification/marvel/0006/005.jpg'
# %%
pltpic = plt.imread('G:/Machine Learning/Project/Lego Mnifigures Classification/marvel/0006/005.jpg'
plt.imshow(pltpic)
# %%
# %%
cv2pic = cv2.imread('G:/Machine Learning/Project/Lego Mnifigures Classification/marvel/0006/005.jpg'
plt.imshow(cv2pic)


# %%

index = pd.read_csv('index.csv')
index
# %%
index.shape, index.columns
# %%

index.drop('Unnamed: 0'axis=1inplace=True)
index

# %%   Create name coloumn because we have to add name of charactors into the class id from index and metadata 
 
index['Name'= None
index
# %%

metadata = pd.read_csv(path + 'metadata.csv')
# metadata.drop(['Unnamed: 0', 'lego_ids', 'lego_names'], axis=1, inplace=True)
metadata

# %%
    
zipped_data = zip(metadata['class_id'], metadata['minifigure_name'])
zipped_data
# %% 

# loop in metadata
# loop in index
# if class id of both metadata and index, then add their name in empty name column

for id_, name in zipped_data :
    for sr , cl_id in enumerate(index['class_id']):
        if id_ == cl_id :
            index.iat[sr, 3= name
            

index
# %%  Create valid dataset A new dataset that copy of index dataset 

valid = index.copy()
valid
# %%  

# we have two catagories 'train' and 'valid' in index
# split the dataset into valid and index set, we will use 'where' function

true_train = index['train-valid'== 'train'
true_valid = valid['train-valid'== 'valid'

index.where( true_train , inplace=True)

valid.where( true_valid , inplace=True)

# %%  
 
# After run above the code you would seen there nan value in data sets
# so we have drop all nan values

# index.dropna(axis=0) # axis = 0 because we have to drop its row not whole column
# inplace = True is defualt, use when you don't want to make new variable

index.dropna(inplace=Trueaxis=0)
valid.dropna(inplace=Trueaxis=0

# %%  Load image

for i in range(len(open_dir)):
    images = load_img(path + '/' + open_dir[i] +'/')

# %%




Comments

Popular posts from this blog

Gradient Descent with RSME

Optimization Alorithms Ex : G.D. , S.D. ,  Adam, RMS prop , momentum , adelta Gradient Descent is an  optimization algorithm that find a best fit line and local minima of a differentiable function for given training data set. S imply used to find the coefficients (weights) and intercept (bias) that minimize a cost function as far as possible.  There are three types of  g radient descent techniques:   Regular Batch GD (Gradient Descent) -  Studiously descend the curve in one path towards one minima ; every hop calculates the cost function for entire training data. If training data is large, one should not use this. Random GD (Stochastic GD) -   Calculates the Cost function for only one (randomly selected) training data per hop ; tend to jump all over the place due to randomness but due to it actually jump across minima’s.  Mini Batch gradient descent - Somewhere midway between the above 2. Does the calculation for a bunch of random data poin...

Why python ? What is Python?

Python is a generally interpreted and  interactive dynamic symmetric   high-level  object oriented programming language. It is widely used in Machine Learning today. Pretty easy to understand, learn, code and explain because it has very crisp and clear syntaxes than other languages.  Guido van Rossum made Python in 1991, named his programming language after the television show Monty Python's Flying Circus. Python has got features or derived features from ABC named programming language. Interactive - The result will be printed on the screen, immediately return, in the next line as we entered. High-level - Humans can easy to interpret; the source code contains easy-to-read syntax that is later converted into a low-level language (0 , 1) Dynamic-symmetric – Don’t need to clarify the data type. It Allows the type casting. Type Casting –  We can transform the one data type in another data type Object Oriented – language is focused on Object...