What is a block class in MXNet

This recipe explains what is a block class in MXNet

Recipe Objective: What is a block class in MXNet?

This recipe explains what a block class in MXNet is.

Build a Chatbot in Python from Scratch!

Step 1: Importing library

Let us first import the necessary libraries. We'll import ndarray(nd as alias) from mxnet and Block and neural network(nn as alias) from mxnet.gluon.

import mxnet as mx
from mxnet import nd
from mxnet.gluon import nn, Block

Step 2: Blocks

Block will take data as input and store the state in the form of passed parameters. These parameters are initialized as part of the forward call in an unorthodox manner. Block invokes a forward pass in the background to compute forward propagation. Block will automatically calculate gradient while invoking backward pass.

class obj(nn.Block):
    def __init__(self, **kwargs):
       super(obj, self).__init__(**kwargs)
       with self.name_scope():
          self.dense0 = nn.Dense(10)
          self.dense1 = nn.Dense(10)

    def forward(self, x):
       for block in self._children.values():
          x = block(x)
       return 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

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.

Classification Projects on Machine Learning for Beginners - 1
Classification ML Project for Beginners - A Hands-On Approach to Implementing Different Types of Classification Algorithms in Machine Learning for Predictive Modelling

GCP MLOps Project to Deploy ARIMA Model using uWSGI Flask
Build an end-to-end MLOps Pipeline to deploy a Time Series ARIMA Model on GCP using uWSGI and Flask

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Build Regression Models in Python for House Price Prediction
In this Machine Learning Regression project, you will build and evaluate various regression models in Python for house price prediction.

Forecasting Business KPI's with Tensorflow and Python
In this machine learning project, you will use the video clip of an IPL match played between CSK and RCB to forecast key performance indicators like the number of appearances of a brand logo, the frames, and the shortest and longest area percentage in the video.

Time Series Forecasting Project-Building ARIMA Model in Python
Build a time series ARIMA model in Python to forecast the use of arrival rate density to support staffing decisions at call centres.

End-to-End Speech Emotion Recognition Project using ANN
Speech Emotion Recognition using RAVDESS Audio Dataset - Build an Artificial Neural Network Model to Classify Audio Data into various Emotions like Sad, Happy, Angry, and Neutral

Build Portfolio Optimization Machine Learning Models in R
Machine Learning Project for Financial Risk Modelling and Portfolio Optimization with R- Build a machine learning model in R to develop a strategy for building a portfolio for maximized returns.

Expedia Hotel Recommendations Data Science Project
In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.