Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of from keras import backend as K error in keras

Shulou Source: shulou.com Published: 2022-06-01 12:28:34 10月28日 Update

This article introduces the relevant knowledge of "how to solve from keras import backend as K errors in keras". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Introduction of principle

Keras is a module-based advanced deep learning development framework. It does not only rely on a certain high-speed low-level tensor library, but encapsulates a variety of low-level tensor libraries by high-level modules, allowing the underlying library to complete operations such as tensor product and convolution.

Currently, Keras provides three backend implementations: TensorFlow backend, Theano backend, and CNTK backend.

TensorFlow is an open source symbol tensor manipulation framework developed by Google.

Theano is an open source symbolic tensor manipulation framework developed by LISA Lab of the University of Montreal.

CNTK is an open source toolkit for deep learning developed by Microsoft.

Meaning

That is, you can write new code using the abstract Keras backend.

The following code instantiates the input placeholder. It is equivalent to tf.placeholder () or th.tensor.matrix (), th.tensor.tensor3 (), and so on.

Inputs = K.placeholder (shape= (2,4,5)) # also works:inputs = K.placeholder (shape= (None, 4,5)) # also works:inputs = K.placeholder (ndim=3)

Add: keras, from keras import backend as K reported an error

If you encounter an error in from keras import backend as K, it may be because "backend" in the keras.json file is not set to mxnet or tensorflow, etc.

Solution: 1. Modify Backend: find this file ~ / .keras/keras.json

Secondly, modify the framework behind backend to mxnet or tensorflow.

Cd ~ / .kerasvim keras.json#-- {# keras.json file content "image_dim_ordering": "tf", "epsilon": 1e-07, "floatx": "float32", "backend": "theano"}

If option 1 cannot solve the problem, you can try option 2.

2. Add an environment variable modification statement import osos.environ ['KERAS_BACKEND'] =' tensorflow' "before import keras in the python code." how to solve the from keras import backend as K error in keras "is introduced here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Tensor framework development code content bottom layer file scheme learning situation is made up of more modules depth knowledge symbols practical advanced learned and then Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Xiaomi Microsoft Shulou Tech Info MySQL