Paradigm
Paradigm

Reputation: 498

ImportError: cannot import name 'K' from 'keras.layers'

my tensorflow version is 2.4.0, and keras version is 2.4.3, when I do from keras.layers import K, the error occured, ImportError: cannot import name 'K' from 'keras.layers' . I think it must be version issue, but how can I change to a right Keras version?

Upvotes: 0

Views: 3962

Answers (1)

Edwin Cheong
Edwin Cheong

Reputation: 979

Based on my knowledge there's no such layer known as K, i think you must be looking for the backend

import tensorflow as tf
from tensorflow.keras import backend as K # This is the most common usecase for keras using K
K.set_session(tf.Session())

from tensorflow.keras.layers import Activation, Conv2D, LSTM # Normally used like this if your using the layers, you can check out the official docs here https://blog.keras.io/keras-as-a-simplified-interface-to-tensorflow-tutorial.html

Upvotes: 1

Related Questions