Home

Awesome

K-CAI NEURAL API VERSIONDOI

<img align="right" src="docs/cai.png" height="192">

K-CAI NEURAL API is a Keras based neural network API that allows you to:

This project is a subproject from a bigger and older project called CAI and is sister to the free pascal based CAI NEURAL API.

Prerequisites

All you need is Keras, python and pip. Alternatively, if you prefer running on your web browser without installing any software on your computer, you can run it on Google Colab. Open In Colab

Quick Start with Image Classification on Your Own Web Browser

For a quick start, you can try the Simple Image Classification with any Dataset example. This example shows how to create a model and train it with a dataset passed as parameter. Feel free to modify the parameters and to add/remove neural layers directly from your browser. Open In Colab

Installation

Via Shell

Installing via shell is very simple:

git clone https://github.com/joaopauloschuler/k-neural-api.git k
cd k && pip install .

Installing on Google Colab

Place this on the top of your Google Colab Jupyter Notebook:

import os

if not os.path.isdir('k'):
  !git clone https://github.com/joaopauloschuler/k-neural-api.git k
else:
  !cd k && git pull

!cd k && pip install .

Documentation

The documentation is composed by examples and PyDoc.

Image Classification Examples

These examples show how to train a neural network for the task of image classification. Most examples train a neural network with the CIFAR-10 or CIFAR-100 datasets.

Advanced Image Classification Examples

These papers show how to create parameter-efficient models (source code is available):

First Layer Filters

The Heatmap and Activation Map with CIFAR-10 example shows how to quickly display heatmaps (CAM), activation maps and first layer filters/patterns.

These are filter examples:

<p><img src="docs/cai-filters.png"></img></p>

Above image has been created with a code similar to this:

weights = model.get_layer('layer_name').get_weights()[0]
neuron_patterns = cai.util.show_neuronal_patterns(weights, NumRows = 8, NumCols = 8, ForceCellMax = True)
...
plt.imshow(neuron_patterns, interpolation='nearest', aspect='equal')

Activation Maps

These are activation map examples:

<p><img src="docs/cai-activations.png"></img></p>

The above shown activation maps have been created with a code similar to this:

conv_output = cai.models.PartialModelPredict(InputImage, model, 'layer_name', False)
...
activation_maps = cai.util.slice_3d_into_2d(aImage=conv_output[0], NumRows=8, NumCols=8, ForceCellMax=True);
...
plt.imshow(activation_maps, interpolation='nearest', aspect='equal')

Heatmaps

The following image shows a car (left - input sample), its heatmap (center) and both added together (right).

<p><img src="docs/cai-heatmap.png"></img></p>

Heatmaps can be produced following this example:

heat_map = cai.models.calculate_heat_map_from_dense_and_avgpool(InputImage, image_class, model, pOutputLayerName='last_conv_layer', pDenseLayerName='dense')

Gradient Ascent & Deep Dream

With cai.gradientascent.run_gradient_ascent_octaves, you can easily run gradient ascent to create Deep Dream like images:

base_model = tf.keras.applications.InceptionV3(include_top=False, weights='imagenet')
pmodel = cai.models.CreatePartialModel(base_model, 'mixed3')
new_img = cai.gradientascent.run_gradient_ascent_octaves(img=original_img, partial_model=pmodel, low_range=-4, high_range=1)
plt.figure(figsize = (16, 16))
plt.imshow(new_img, interpolation='nearest', aspect='equal')
plt.show()
<p><img src="docs/park-ga.jpg"></img></p>

Above image was generated from:

<p><img src="https://github.com/joaopauloschuler/neural-api/blob/master/docs/park.jpg?raw=true" width=714px></img></p>

There is a ready to use example: Gradient Ascent / Deep Dream Example. Open In Colab

PyDoc

After installing K-CAI, you can find documentation with:

python -m pydoc cai.datasets
python -m pydoc cai.densenet
python -m pydoc cai.layers
python -m pydoc cai.models
python -m pydoc cai.util

Scientific Research

These papers were made with K-CAI API:

Feature List

New Layers

Give this Project a Star

This project is an open source project. If you like what you see, please give it a star on github.

Citing this API

You can cite this API in BibTeX format with:

@software{k_cai_neural_api_2021_5810092,
  author       = {Joao Paulo Schwarz Schuler},
  title        = {K-CAI NEURAL API},
  month        = dec,
  year         = 2021,
  publisher    = {Zenodo},
  doi          = {10.5281/zenodo.5810092},
  url          = {https://doi.org/10.5281/zenodo.5810092}
}