All Projects → few-shot-learning → Keras Fewshotlearning

few-shot-learning / Keras Fewshotlearning

Some State-of-the-Art few shot learning algorithms in tensorflow 2

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Keras Fewshotlearning

Sru Deeplearning Workshop
دوره 12 ساعته یادگیری عمیق با چارچوب Keras
Stars: ✭ 66 (-51.11%)
Mutual labels:  keras-tensorflow
Har Keras Cnn
Human Activity Recognition (HAR) with 1D Convolutional Neural Network in Python and Keras
Stars: ✭ 97 (-28.15%)
Mutual labels:  keras-tensorflow
Self Driving Car
A End to End CNN Model which predicts the steering wheel angle based on the video/image
Stars: ✭ 106 (-21.48%)
Mutual labels:  keras-tensorflow
Tf Serving K8s Tutorial
A Tutorial for Serving Tensorflow Models using Kubernetes
Stars: ✭ 78 (-42.22%)
Mutual labels:  keras-tensorflow
Text Detection Using Yolo Algorithm In Keras Tensorflow
Implemented the YOLO algorithm for scene text detection in keras-tensorflow (No object detection API used) The code can be tweaked to train for a different object detection task using YOLO.
Stars: ✭ 87 (-35.56%)
Mutual labels:  keras-tensorflow
Unet
Generic U-Net Tensorflow 2 implementation for semantic segmentation
Stars: ✭ 100 (-25.93%)
Mutual labels:  keras-tensorflow
Pneumonia Detection From Chest X Ray Images With Deep Learning
Detecting Pneumonia in Chest X-ray Images using Convolutional Neural Network and Pretrained Models
Stars: ✭ 64 (-52.59%)
Mutual labels:  keras-tensorflow
Repo 2019
BERT, AWS RDS, AWS Forecast, EMR Spark Cluster, Hive, Serverless, Google Assistant + Raspberry Pi, Infrared, Google Cloud Platform Natural Language, Anomaly detection, Tensorflow, Mathematics
Stars: ✭ 133 (-1.48%)
Mutual labels:  keras-tensorflow
Deep Residual Unet
ResUNet, a semantic segmentation model inspired by the deep residual learning and UNet. An architecture that take advantages from both(Residual and UNet) models.
Stars: ✭ 97 (-28.15%)
Mutual labels:  keras-tensorflow
Unet Segmentation In Keras Tensorflow
UNet is a fully convolutional network(FCN) that does image segmentation. Its goal is to predict each pixel's class. It is built upon the FCN and modified in a way that it yields better segmentation in medical imaging.
Stars: ✭ 105 (-22.22%)
Mutual labels:  keras-tensorflow
Unet Tgs
Applying UNET Model on TGS Salt Identification Challenge hosted on Kaggle
Stars: ✭ 81 (-40%)
Mutual labels:  keras-tensorflow
Automatic Image Captioning
Generating Captions for images using Deep Learning
Stars: ✭ 84 (-37.78%)
Mutual labels:  keras-tensorflow
Talos
Hyperparameter Optimization for TensorFlow, Keras and PyTorch
Stars: ✭ 1,382 (+923.7%)
Mutual labels:  keras-tensorflow
Santosnet
A simple self driving car in GTAV that uses the Xception deep neural network model with DeepGTAV
Stars: ✭ 67 (-50.37%)
Mutual labels:  keras-tensorflow
Motionblur Detection By Cnn
Stars: ✭ 126 (-6.67%)
Mutual labels:  keras-tensorflow
Sign Language
Sign Language Recognition for Deaf People
Stars: ✭ 65 (-51.85%)
Mutual labels:  keras-tensorflow
Deepeeg
Deep Learning with Tensor Flow for EEG MNE Epoch Objects
Stars: ✭ 100 (-25.93%)
Mutual labels:  keras-tensorflow
Intelegent lock
lock mechanism with face recognition and liveness detection
Stars: ✭ 134 (-0.74%)
Mutual labels:  keras-tensorflow
Inferpy
InferPy: Deep Probabilistic Modeling with Tensorflow Made Easy
Stars: ✭ 130 (-3.7%)
Mutual labels:  keras-tensorflow
Cloudml Samples
Cloud ML Engine repo. Please visit the new Vertex AI samples repo at https://github.com/GoogleCloudPlatform/vertex-ai-samples
Stars: ✭ 1,452 (+975.56%)
Mutual labels:  keras-tensorflow

Install Package Tests codecov

Currently supporting python 3.6, 3.7 and tensorflow ^2.1.

Welcome to keras-fsl!

As years go by, Few Shot Learning (FSL) and especially Metric Learning is becoming a hot topic not only in academic papers but also in production applications.

While a lot of researcher nowadays tend to publish their code on github, there is still no easy framework to get started with FSL. Especially when it comes to benchmarking existing models on personal datasets it is not always easy to find its path into each single repo. Not mentioning the Tensorflow/PyTorch issue.

This repo aims at filling this gap by providing a single entry-point for Few Shot Learning. It is deeply inspired by Keras because it shares the same philosophy:

It was developed with a focus on enabling fast experimentation. Being able to go from idea to result with the least possible delay is key to doing good research.

Thus this repo mainly relies on two of the main high-level python packages for data science: Keras and Pandas. While Pandas may not seem very useful for researchers working with static dataset, it becomes a strong backbone in production applications when you always need to tinker with your data.

Few-Shot Learning

Few-shot learning is a task consisting in classifying unseen samples into n classes (so called n way task) where each classes is only described with few (from 1 to 5 in usual benchmarks) examples.

Most of the state-of-the-art algorithms try to sort of learn a metric into a well suited (optimized) feature space. Thus deep networks usually first encode the base images into a feature space onto which a distance or similarity is learnt.

This similarity is meant to be used to later classify samples according to their relative distance, either in a pair-wise manner where the nearest support set samples is used to classify the query sample (Voronoi diagram) or in a more advanced classifier. Indeed, this philosophy is most commonly known as the kernel trick where the kernel is actually the similarity learnt during training. Hence any kind of usual kernel based Machine Learning could potentially be plugged onto this learnt similarity (see the min_eigenvalue metric to track eigenvalues of the learnt similarity to see if it as actually a kernel).

There is no easy answer to the optimal choice of such a classifier in the feature space. This may depend on performance as well as on complexity and real application parameters. For instance if the support set is strongly imbalanced, you may not want to fit an advanced classifier onto it but rather use a raw nearest neighbor approach.

All these considerations lead to the need of a code architecture that will let you play with these parameters with your own data in order to take the best from them.

Amongst other, the original Siamese Nets is usually known as the network from Koch et al. This algorithm learns a pair-wise similarity between images. More precisely it uses a densely connected layers on top of the absolute difference between the two embeddings to predict 0 (different) or 1 (same).

Actually, and as it is now expressed in recent papers, the representation learning framework is as follows:

  • a data augmentation module A
  • an encoder network E
  • a projection network P
  • a loss L

This repo mimics this framework by proving model builders and notebooks to implement current SOTA algorithms and your own tweaks seamlessly:

  • use tf.data.Dataset.map to apply data augmentation
  • define a tf.Keras.Sequential model for your encoder
  • define a kernel, ie a tf.keras.Layer with two inputs and a real-valued output (see head models)
  • use any support_layers to wrap the kernel and compute similarities in a tf.keras.Sequential manner (see notebooks for instance).
  • use any loss chosen accordingly to the output of the tf.keras.Sequential model (GramMatrix or CentroidsMatrix for instance)

As an example, the TripletLoss algorithm uses indeed:

  • data augmentation: whatever you want
  • encoder: any backbone like ResNet50 or MobileNet
  • kernel: the l2 norm: k(x, x') = ||x - x'||^2 = tf.keras.layers.Lambda(lambda inputs: tf.reduce_sum(tf.square(inputs[0] - inputs[1]), axis=1))
  • support_layer: triplet loss uses all the pair-wises distances, hence it is the GramMatrix
  • loss: k(a, p) + margin - k(a, n) with semi-hard mining (see triplet_loss)

Overview

This repos provides several tools for few-shot learning:

  • Keras layers and models
  • Keras sequences and Tensorflow datasets for training the models
  • Notebooks with proven learning sequences

All these tools can be used all together or separately. One may want to stick with the keras model trained on regular numpy arrays, with or without callbacks. When designing more advanced keras.Sequence or tf.data.Dataset for training, it is advised (and some examples are provided) to use Pandas though it is not necessary at all.

Feel free to experiment and share your thought on this repo by contributing to it!

Getting started

The notebooks section provides some examples. For instance, just run:

import tensorflow as tf
import tensorflow_datasets as tfds
from tensorflow.keras.models import Sequential

from keras_fsl.models.encoders import BasicCNN
from keras_fsl.layers import GramMatrix
from keras_fsl.losses.gram_matrix_losses import BinaryCrossentropy
from keras_fsl.metrics.gram_matrix_metrics import classification_accuracy, min_eigenvalue
from keras_fsl.utils.tensors import get_dummies


#%% Get data
train_dataset, val_dataset, test_dataset = [
    dataset.shuffle(1024).batch(64).map(lambda x, y: (tf.image.convert_image_dtype(x, tf.float32), get_dummies(y)[0]))
    for dataset in tfds.load(name="omniglot", split=["train[:90%]", "train[90%:]", "test"], as_supervised=True)
]
input_shape = next(tfds.as_numpy(train_dataset.take(1)))[0].shape[1:]  # first shape is batch_size

#%% Training
encoder = BasicCNN(input_shape=input_shape)
support_layer = GramMatrix(kernel="DenseSigmoid")
model = Sequential([encoder, support_layer])
model.compile(optimizer="Adam", loss=BinaryCrossentropy(), metrics=[classification_accuracy(), min_eigenvalue])
model.fit(train_dataset, validation_data=val_dataset, epochs=5)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].