All Projects → meownoid → tensorflow-rbm

meownoid / tensorflow-rbm

Licence: MIT license
Tensorflow implementation of the Restricted Boltzmann Machine

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to tensorflow-rbm

Grokking-Machine-Learning
This repo aims to contain different machine learning use cases along with the descriptions to the model architectures
Stars: ✭ 54 (-82.47%)
Mutual labels:  machine-learning-algorithms, tensorflow2
GradCAM and GuidedGradCAM tf2
Implementation of GradCAM & Guided GradCAM with Tensorflow 2.x
Stars: ✭ 16 (-94.81%)
Mutual labels:  tensorflow2
ML-For-Beginners
12 weeks, 26 lessons, 52 quizzes, classic Machine Learning for all
Stars: ✭ 40,023 (+12894.48%)
Mutual labels:  machine-learning-algorithms
Training-BatchNorm-and-Only-BatchNorm
Experiments with the ideas presented in https://arxiv.org/abs/2003.00152 by Frankle et al.
Stars: ✭ 23 (-92.53%)
Mutual labels:  tensorflow2
spectral normalization-tf2
🌈 Spectral Normalization implemented as Tensorflow 2
Stars: ✭ 36 (-88.31%)
Mutual labels:  tensorflow2
ExCon
ExCon: Explanation-driven Supervised Contrastive Learning
Stars: ✭ 17 (-94.48%)
Mutual labels:  machine-learning-algorithms
BoostSRL
BoostSRL: "Boosting for Statistical Relational Learning." A gradient-boosting based approach for learning different types of SRL models.
Stars: ✭ 31 (-89.94%)
Mutual labels:  machine-learning-algorithms
tfworldhackathon
GitHub repo for my Tensorflow World hackathon submission
Stars: ✭ 17 (-94.48%)
Mutual labels:  tensorflow2
Self-Driving-Car
Implemented a Convolutional Neural Network for end-to-end driving in a simulator using Tensorflow and Keras. The project involves training over 13,000 images in a unity3d simulator to steer the car successfully throughout the track
Stars: ✭ 29 (-90.58%)
Mutual labels:  machine-learning-algorithms
farm-animal-tracking
Farm Animal Tracking (FAT)
Stars: ✭ 19 (-93.83%)
Mutual labels:  tensorflow2
Autoregressive-models
Tensorflow 2.0 implementation of Deep Autoregressive Models
Stars: ✭ 18 (-94.16%)
Mutual labels:  tensorflow2
GrouProx
FedGroup, A Clustered Federated Learning framework based on Tensorflow
Stars: ✭ 20 (-93.51%)
Mutual labels:  tensorflow2
online-course-recommendation-system
Built on data from Pluralsight's course API fetched results. Works with model trained with K-means unsupervised clustering algorithm.
Stars: ✭ 31 (-89.94%)
Mutual labels:  machine-learning-algorithms
bonsai-dt
Programmable Decision Tree Framework
Stars: ✭ 34 (-88.96%)
Mutual labels:  machine-learning-algorithms
Handwritten-Digits-Classification-Using-KNN-Multiclass Perceptron-SVM
🏆 A Comparative Study on Handwritten Digits Recognition using Classifiers like K-Nearest Neighbours (K-NN), Multiclass Perceptron/Artificial Neural Network (ANN) and Support Vector Machine (SVM) discussing the pros and cons of each algorithm and providing the comparison results in terms of accuracy and efficiecy of each algorithm.
Stars: ✭ 42 (-86.36%)
Mutual labels:  machine-learning-algorithms
deep autoviml
Build tensorflow keras model pipelines in a single line of code. Now with mlflow tracking. Created by Ram Seshadri. Collaborators welcome. Permission granted upon request.
Stars: ✭ 98 (-68.18%)
Mutual labels:  tensorflow2
Clustering-Python
Python Clustering Algorithms
Stars: ✭ 23 (-92.53%)
Mutual labels:  machine-learning-algorithms
ntga
Code for "Neural Tangent Generalization Attacks" (ICML 2021)
Stars: ✭ 33 (-89.29%)
Mutual labels:  tensorflow2
perceptron
The simplest Perceptron you'll ever see
Stars: ✭ 45 (-85.39%)
Mutual labels:  machine-learning-algorithms
TTS tf
WIP Tensorflow implementation of https://github.com/mozilla/TTS
Stars: ✭ 14 (-95.45%)
Mutual labels:  tensorflow2

tensorflow-rbm

Tensorflow implementation of Restricted Boltzmann Machine for layer-wise pretraining of deep autoencoders.

Restricted Boltzmann Machine diagram

This is a fork of a Michal Lukac repository with some corrections and improvements.

The Restricted Boltzmann Machine is a legacy machine learning model that is no longer used anywhere. This repository is of historical and educational value only. I have updated the code using the TensorFlow 2 to run on modern systems, but I will no longer maintain it.

Installation

git clone https://github.com/meownoid/tensorfow-rbm.git
cd tensorfow-rbm
python -m pip install -r requirements.txt
python setup.py

Example

Bernoulli-Bernoulli RBM is good for Bernoulli-distributed binary input data. MNIST, for example. To train the model, simply construct the tf.data.Dataset containing vectors of shape (n_visible,) and pass it to the fit method.

import tensorflow as tf

from tfrbm import BBRBM


(x_train, _), (x_test, _) = tf.keras.datasets.mnist.load_data()

x_train = x_train / 255
x_test = x_test / 255

dataset = tf.data.Dataset.from_tensor_slices(x_train.reshape(-1, 28 * 28))
dataset = dataset.shuffle(1024, reshuffle_each_iteration=True)

rbm = BBRBM(n_visible=28 * 28, n_hidden=64)
rbm.fit(dataset, epoches=100, batch_size=10)

Now you can use reconstruct method to check the model performance.

# x_tensor: (1, n_visible)
# x_reconstructed_tensor: (1, n_visible)
x_reconstructed_tensor = rbm.reconstruct(x_tensor)

Full example code can be found in the examples/mnist.py.

API

BBRBM(n_visible, n_hidden, learning_rate=0.01, momentum=0.95)
GBRBM(n_visible, n_hidden, learning_rate=0.01, momentum=0.95, sample_visible=False, sigma=1.0)

Initializes Bernoulli-Bernoulli RBM or Gaussian-Bernoulli RBM.

  • n_visible — number of visible neurons (input size)
  • n_hidden — number of hidden neurons

Only for GBRBM:

  • sample_visible — sample reconstructed data with Gaussian distribution (with reconstructed value as a mean and a sigma parameter as deviation) or not (if not, every gaussoid will be projected into a single point)
  • sigma — standard deviation of the input data

Advices:

  • Use BBRBM for Bernoulli distributed data. Input values in this case must be in the interval from 0 to 1.
  • Use GBRBM for normally distributed data with 0 mean and sigma standard deviation. Normalize input data if necessary.
rbm.fit(dataset, epoches=10, batch_size=10)

Trains the model and returns a list of errors.

  • datasettf.data.Dataset composed of tensors of shape (n_visible,)
  • epoches — number of epoches
  • batch_size — batch size, should be as small as possible
rbm.step(x)

Performs one training step and returns reconstruction error.

  • x – tensor of shape (batch_size, n_visible)
rbm.compute_hidden(x)

Computes hidden state from the input.

  • x – tensor of shape (batch_size, n_visible)
rbm.compute_visible(hidden)

Computes visible state from hidden state.

  • x – tensor of shape (batch_size, n_hidden)
rbm.reconstruct(x)

Computes visible state from the input. Reconstructs data.

  • x – tensor of shape (batch_size, n_visible)

Original README

Tensorflow implementation of Restricted Boltzman Machine and Autoencoder for layerwise pretraining of Deep Autoencoders with RBM. Idea is to first create RBMs for pretraining weights for autoencoder. Then weigts for autoencoder are loaded and autoencoder is trained again. In this implementation you can also use tied weights for autoencoder(that means that encoding and decoding layers have same transposed weights!).

I was inspired with these implementations but I need to refactor them and improve them. I tried to use also similar api as it is in tensorflow/models:

myme5261314

saliksyed

Thank you for your gists!

More about pretraining of weights in this paper:

Reducing the Dimensionality of Data with Neural Networks

Feel free to make updates, repairs. You can enhance implementation with some tips from:

Practical Guide to training RBM

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].