How to use linear activation in TF learn

This recipe helps you use linear activation in TF learn

Recipe Objective

This recipe explains how to use Linear activation in TFLearn.

Importing Libraries

We'll import tflearn, tensorflow as tf and tflearn.datasets.mnist as mnist.

import tflearn
import tensorflow as tf
import tflearn.datasets.mnist as mnist
from __future__ import division, print_function, absolute_import

Linear

Linear evaluates f(a) = a
Its syntax is: tflearn.activations.linear (x)
We have combined TFLearn built-in ops with Tensorflow graph. We have built this using MNIST Dataset.
To create a multilayer perceptron we have used TFLearn Linear activations ops.

with tf.Graph().as_default():

    x = tf.placeholder("float", [None, 784])
    y = tf.placeholder("float", [None, 10])
    u = tf.Variable(tf.random_normal([784, 256]))
    v = tf.Variable(tf.random_normal([256, 256]))
    w = tf.Variable(tf.random_normal([256, 10]))
    a = tf.Variable(tf.random_normal([256]))
    b = tf.Variable(tf.random_normal([256]))
    c = tf.Variable(tf.random_normal([10]))

    def net(X):
       X = tflearn.linear(tf.add(tf.matmul(X, u), a))
       tflearn.summaries.monitor_activation(x)
       X = tflearn.linear(tf.add(tf.matmul(X, v), b))
       tflearn.summaries.monitor_activation(x)
       X = tf.nn.linear(tf.add(tf.matmul(X, w), c))
       return X

    my_net = net(x)

What Users are saying..

profile image

Jingwei Li

Graduate Research assistance at Stony Brook University
linkedin profile url

ProjectPro is an awesome platform that helps me learn much hands-on industrial experience with a step-by-step walkthrough of projects. There are two primary paths to learn: Data Science and Big Data.... Read More

Relevant Projects

Build Customer Propensity to Purchase Model in Python
In this machine learning project, you will learn to build a machine learning model to estimate customer propensity to purchase.

Learn to Build Generative Models Using PyTorch Autoencoders
In this deep learning project, you will learn how to build a Generative Model using Autoencoders in PyTorch

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Learn to Build an End-to-End Machine Learning Pipeline - Part 2
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, incorporating Hopsworks' feature store and Weights and Biases for model experimentation.

MLOps Project to Deploy Resume Parser Model on Paperspace
In this MLOps project, you will learn how to deploy a Resume Parser Streamlit Application on Paperspace Private Cloud.

Learn to Build an End-to-End Machine Learning Pipeline - Part 1
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, addressing a major challenge in the logistics industry.

Learn Object Tracking (SOT, MOT) using OpenCV and Python
Get Started with Object Tracking using OpenCV and Python - Learn to implement Multiple Instance Learning Tracker (MIL) algorithm, Generic Object Tracking Using Regression Networks Tracker (GOTURN) algorithm, Kernelized Correlation Filters Tracker (KCF) algorithm, Tracking, Learning, Detection Tracker (TLD) algorithm for single and multiple object tracking from various video clips.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Deep Learning Project for Beginners with Source Code Part 1
Learn to implement deep neural networks in Python .

OpenCV Project for Beginners to Learn Computer Vision Basics
In this OpenCV project, you will learn computer vision basics and the fundamentals of OpenCV library using Python.