Tutorial Example

Fix TensorFlow KeyError: ‘BatchMatMulV2’ When Importing a Model – TensorFlow Tutorial

We often use tf.train.import_meta_graph() to load a saved tensorflow model to use, however, you may find a KeyError: ‘BatchMatMulV2’. In this tutorial, we will introduce how to fix this error and restore a saved model successfully.

Why does this keyerror occur?

The main reason is tensorflow versions are different.

As to us, we use a cloud gpu platform to train and save a tensorflow model, the version of tensorflow is 1.14.0

However, the version of tensorflow in our computer is 1.10.0. They are different.

How to fix this error?

We can update or install tensorflow to 1.14.0

If you are using anaconda, you can install tensorflow 1.14.0 by it.

Conda Install Specific TensorFLow Version: A Completed Guide

or update your tensorflow to 1.14.0

Anaconda Install or Update TensorFlow to Specific Version

You also can use pip to install tensorflow 1.14.0 as follow:

Then run our tensorflow code, we find this keyerror is fixed.