How to load a keras model saved as .pb

Written by - Aionlinecourse3135 times views

How to load a keras model saved as .pb

To load the saved model, you will need to define a function that loads the model and returns it.

How to load a keras model saved as .pb

Solution 1:

The function tf.keras.models.load_model load a SavedModel into a tf.keras -model. The argument of the function is path to a saved model.

So try model = tf.keras.models.load_model('model')


Solution 2:

You should load all model folder instead of loading .pb file. If you save model to './_models/vgg50_finetune' (I used this path in my project), you get folder vgg50_finetune with two .pb files (keras_metadata.pb and saved_model.pb) and two subfolders (assets and variables). The only thing you should do is use this code: model = tf.keras.models.load_model('./_models/vgg50_finetune') And you can both train model or use it for prediction.


Thank you for reading the article.

Recommended Projects

Deep Learning Interview Guide

Topic modeling using K-means clustering to group customer reviews

Have you ever thought about the ways one can analyze a review to extract all the misleading or useful information?...

Natural Language Processing
Deep Learning Interview Guide

Medical Image Segmentation With UNET

Have you ever thought about how doctors are so precise in diagnosing any conditions based on medical images? Quite simply,...

Computer Vision
Deep Learning Interview Guide

Build A Book Recommender System With TF-IDF And Clustering(Python)

Have you ever thought about the reasons behind the segregation and recommendation of books with similarities? This project is aimed...

Machine LearningDeep LearningNatural Language Processing
Deep Learning Interview Guide

Automatic Eye Cataract Detection Using YOLOv8

Cataracts are a leading cause of vision impairment worldwide, affecting millions of people every year. Early detection and timely intervention...

Computer Vision
Deep Learning Interview Guide

Crop Disease Detection Using YOLOv8

In this project, we are utilizing AI for a noble objective, which is crop disease detection. Well, you're here if...

Computer Vision
Deep Learning Interview Guide

Vegetable classification with Parallel CNN model

The Vegetable Classification project shows how CNNs can sort vegetables efficiently. As industries like agriculture and food retail grow, automating...

Machine LearningDeep Learning
Deep Learning Interview Guide

Banana Leaf Disease Detection using Vision Transformer model

Banana cultivation is a significant agricultural activity in many tropical and subtropical regions, providing a vital source of income and...

Deep LearningComputer Vision