GithubHelp home page GithubHelp logo

kanavanand / flipkart_grid Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 6.0 1.46 MB

Cropping the objects from an image

Python 1.45% Jupyter Notebook 98.55%
object-localisation object-localization cropper cropping xception-model python keras

flipkart_grid's Introduction

Croppy [Flipkart GRID]

The code is used to predict the bounding box for an object in image. This is keras implementation of single object localization. It's based on UNET segmentation and regression both based on XceptionNet. Currently it supports only single object in an image. The input image provided must be of shape (480,640,3) which is further resized to (224,224,3) for training.

Example Image)

The croppy supports two modes currently

  1. Regression Mode :"reg"
  2. Segmentation Mode : "seg"

1: Regression

The XceptionNet is build using keras api with output layer giving 4 coordinates of bounding box [x1,y1,x2,y2]. The regression model got an IOU score of 93.7 on GRID dataset. You can use pre_trained_reg.py or train it again on your dataset using train.py with "reg" mode in config.py

2: Segmentation

The UNet is also build using keras api with output layer giving an mask of (224,224,1) . Further using cv2.regionprops we can get the desired bounding box coordinates. The Segmentation model alone got an IOU score of 94.12 on GRID dataset. You can use pre_trained_seg.py or train it again on your dataset using train.py with "seg" mode in config.py .

Installation

  1. Download the zip file in your current working directory.
  2. you need to run following command in shell a directory 'pretrained_weights/' download the weights in this directory.
import os
if not os.path.isdir("pretrained_weights/"):
    print('making direct pretrained_weights/')
    os.mkdir('pretrained_weights/')
! wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1Lx9uZSwbzsc3anh9lfb4RPiBEBoSDMQ8' -O pretrained_weights/regression.h5
! wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1WNe1s1RzBqiV-vvcJMo9swaAFDBO1Rh-' -O pretrained_weights/segmentation.model

Usage

You need to change the config.py file according to your use.

img_size=(224,224,3) #input size 
mode='reg'   #The mode in which you want to run "seg": segmantation and "reg": Regression
model_direc="pretrained_weights/regression.h5"
bs=16  #batch size 
epochs=10   #epochs 
training_df='training_set.csv'   #Location of training dataframe
testing_df = 'test_updated.csv'  #Location of testing dataframe 
test_direc = "testing_mini/"    #Folder containing test images
image_direc="images/"           #Folder containing training images

After you have modified the config file you can run python code using shell. For -eg.

  1. Training model
python train.py
  1. Predicting the bounding boxes for test_direc using pretrained wieghts in reg mode.
python pre_trained_reg.py
  1. Predicting the bounding boxes for test_direc using pretrained wieghts in seg mode.
python pre_trained_seg.py
Note : Be carefull, give model_direc = regression weights when in reg mode and same goes for seg mode. Interchanging models will throw an error.

Ensembling

In order to improve IOU score you can further use ensembling in following manner. The ensembling is done as depicted below.

Example Image)

python ensembling.py

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.