GithubHelp home page GithubHelp logo

sbrugman / keras-coordconv Goto Github PK

View Code? Open in Web Editor NEW

This project forked from titu1994/keras-coordconv

0.0 4.0 0.0 211 KB

Keras implementation of CoordConv for all Convolution layers

License: MIT License

Python 100.00%

keras-coordconv's Introduction

CoordConv for Keras

Keras implementation of CoordConv from the paper An intriguing failing of convolutional neural networks and the CoordConv solution.

Extends the CoordinateChannel concatenation from only 2D rank (images) to 1D (text / time series) and 3D tensors (video / voxels).

Usage

Import coord.py and call it before any convolution layer in order to attach the coordinate channels to the input.

There are 3 different versions of CoordinateChannel - 1D, 2D and 3D for each of Conv1D, Conv2D and Conv3D.

from coord import CoordinateChannel2D

# prior to first conv
ip = Input(shape=(64, 64, 2))
x = CoordinateChannel2D()(ip)
x = Conv2D(...)(x)  # This defines the `CoordConv` from the paper.
...
x = CoordinateChannel2D(use_radius=True)(x)
x = Conv2D(...)(x)  # This adds the 3rd channel for the radius.

Experiments

The experiments folder contains the Classification of a 64x64 grid using the coordinate index as input as in the paper for both Uniform and Quadrant datasets.

Creating the datasets

First, edit the make_dataset.py file to change the type parameter - to either uniform or quadrant. This will generate 2 folders for the datasets and several numpy files.

Uniform Dataset

The uniform dataset model can be trained and evaluated in less than 10 epochs using train_uniform_classifier.py.

Train Test Predictions

Quadrant Dataset

The quadrant dataset model can be trained and evaluated in less than 25 epochs using train_quadrant_classifier.py

Train Test Predictions

Checks

To see if the implementation of CoordConv index concatenation is correct, please refer to the numpy implementations in the checks directory, for the implementation of all 3 versions.

Difference from paper

This implementation of the coordinate channels creation differs slightly from the original paper.

The major difference is that for 2/3D Convolutions, it may not be the case that the height and width are the same for all layers. The original implementation would throw an error due to shape mismatch during the concatenation.

To over come this, the np.ones() operation which occurs at the first of every channel is modified and a few transpose operations are added to account for this change.

This modification along with some transpose operations allows for height and width to be different and still work.

Requirements

  • Keras 2.2.0+
  • Either Tensorflow, Theano or CNTK backend.
  • Matplotlib (to plot images only)

keras-coordconv's People

Contributors

titu1994 avatar sbrugman avatar

Watchers

James Cloos avatar  avatar  avatar paper2code - bot avatar

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.