What is a HybridBlock class in MXNet

This recipe explains what is a HybridBlock class in MXNet

Recipe Objective: What is a HybridBlock class in MXNet?

This recipe explains what a HybridBlock class in MXNet is.

Learn to Build a Multi Class Image Classification Model 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 HybridBlock 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: Class

HybridBlock and Block are similar in a few manners it uses both Symbol and NDArray for forwarding. The forward computation must not be dynamic to work with the symbol.

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

    def hybrid_forward(self, F, x):
       x = F.relu(self.dense0(x))
       return self.dense1(x)

Step 3: HybridBlocks

After calling hybridize(), HybridBlock will create a symbolic graph resembling the forward computation and cache it. Before calling hybridize(), HybridBlock is similar to regular Block. Further forwards, the cached graph will be used instead of hybrid_forward().

Obj=obj()
Obj.initialize(ctx=mx.cpu(0))
Obj.hybridize()
Obj(mx.nd.ones(5))

What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

Time Series Classification Project for Elevator Failure Prediction
In this Time Series Project, you will predict the failure of elevators using IoT sensor data as a time series classification machine learning problem.

Time Series Analysis with Facebook Prophet Python and Cesium
Time Series Analysis Project - Use the Facebook Prophet and Cesium Open Source Library for Time Series Forecasting in Python

BigMart Sales Prediction ML Project in Python
The goal of the BigMart Sales Prediction ML project is to build and evaluate different predictive models and determine the sales of each product at a store.

MLOps Project for a Mask R-CNN on GCP using uWSGI Flask
MLOps on GCP - Solved end-to-end MLOps Project to deploy a Mask RCNN Model for Image Segmentation as a Web Application using uWSGI Flask, Docker, and TensorFlow.

Model Deployment on GCP using Streamlit for Resume Parsing
Perform model deployment on GCP for resume parsing model using Streamlit App.

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

MLOps AWS Project on Topic Modeling using Gunicorn Flask
In this project we will see the end-to-end machine learning development process to design, build and manage reproducible, testable, and evolvable machine learning models by using AWS

Build a Review Classification Model using Gated Recurrent Unit
In this Machine Learning project, you will build a classification model in python to classify the reviews of an app on a scale of 1 to 5 using Gated Recurrent Unit.

Build Multi Class Text Classification Models with RNN and LSTM
In this Deep Learning Project, you will use the customer complaints data about consumer financial products to build multi-class text classification models using RNN and LSTM.

Build a Multi Touch Attribution Machine Learning Model in Python
Identifying the ROI on marketing campaigns is an essential KPI for any business. In this ML project, you will learn to build a Multi Touch Attribution Model in Python to identify the ROI of various marketing efforts and their impact on conversions or sales..