Git Product home page Git Product logo

clothing-dataset's Introduction

clothing-dataset's People

Contributors

alexeygrigorev avatar igorsusmelj avatar shruti-shyam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

clothing-dataset's Issues

How to balance the imbalanced classes ?

Hi, Recently I tried transfer learning methods to this dataset and I got about 70 percent accuracy on the validation set when weighting the classes. When I tried not to weight the classes I got about 80 percent validation accuracy. But when it comes to predicting, The model prediction result is always between 2 classes and never got the other classes in the result. Is there any other method better than weighting my classes? Or any opinion do you have why it is working like that?

The code:


import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from tensorflow import keras
############################# Creating Model #############################
base_model = keras.applications.Xception(
    weights='imagenet',  # Load weights pre-trained on ImageNet.
    input_shape=(150, 150, 3),
    include_top=False)  # Do not include the ImageNet classifier at the top.

image_size=(150,150)

inputs = keras.Input(shape= image_size + (3,))
## Set the base model trainable false to freeze training on the resnet model
# x = base_model(inputs, training = False)
base_model.training = False
model = keras.Sequential()
model.add(base_model)
model.add(keras.layers.Flatten())
## Dense layer with 20 nodes ( we had 20 classes )
model.add(keras.layers.Dense(20, activation='softmax'))

############################# Getting dataset batches #############################
train_generator = tf.keras.preprocessing.image.ImageDataGenerator(
    rescale=1./255,
    validation_split=0.1)
valid_generator = tf.keras.preprocessing.image.ImageDataGenerator(
    rescale=1./255,
    validation_split=0.1)
### Note here we classified folders so we're using flow_from directory method
train_dataset = train_generator.flow_from_directory('dataset',
                                                    target_size=image_size, 
                                                    batch_size=12,
                                                    subset='training',
                                                    class_mode='categorical',
                                                    shuffle=True,
                                                    seed=123)
validation_dataset = valid_generator.flow_from_directory('dataset',
                                                          target_size=image_size,
                                                          batch_size=12,
                                                          shuffle=True,
                                                          subset='validation',
                                                          interpolation='bilinear',
                                                          class_mode='categorical',
                                                          seed=123)

############################# Calculating classes weight #############################
cloth_df = pd.read_csv('images.csv')

## Get the each class values count 
class_values_count = cloth_df.label.value_counts()

## Sort them by index ( indexes are label names as 'T-Shirt', 'Blouse',etc )
class_values_count = class_values_count.sort_index()


## Because our classes don't have similar count
## we would define a function to calculate wights for us
def calculate_weights(class_values_count):
    ## get the max class count
    max_count = class_values_count.max()
    ## Create an empty dictionary
    weights = {}
    ## indexes are used to add to dictionary
    index = 0
    for counts in class_values_count:
        ## Calculate the weights
        ## max_count is 1011 for T-Shirt class
        weights[index] = max_count/counts
        index+=1
    
    return weights
        
class_weight = calculate_weights(class_values_count)
## Also the scikit learn function for weighting was tried ( It is as below )
## sklearn.utils.class_weight.compute_class_weight('balanced', np.unique(values), values)

############################# Compiling and Training the model #############################
model.compile(optimizer=keras.optimizers.Adam(),
            loss="categorical_crossentropy",
            metrics=["categorical_accuracy"],)


epochs = 40

callbacks = [
    tf.keras.callbacks.ModelCheckpoint("transfer_learning_save_at_{epoch}.h5"),
]

## Here I tried both with weight and without weight training
## The last time I tried without weight training, So class_weight is commented
history = model.fit(
    train_dataset, epochs=epochs, callbacks=callbacks,
    validation_data=validation_dataset
#     ,class_weight=class_weight
)

Corrupt files with 0 size in the dataset

Hey @alexeygrigorev, there are a few images in the dataset which have 0 size and won't load properly:

  • 040d73b7-21b5-4cf2-84fc-e1a80231b202.jpg
  • 1d0129a1-f29a-4a3f-b103-f651176183eb.jpg
  • 784d67d4-b95e-4abb-baf7-8024f18dc3c8.jpg
  • b72ed5cd-9f5f-49a7-b12e-63a078212a17.jpg
  • c60e486d-10ed-4f64-abab-5bb698c736dd.jpg
  • d028580f-9a98-4fb5-a6c9-5dc362ad3f09.jpg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.