kerasClassifier is deprecated warning - keras

C:\Users\Zia\Desktop\Ann\Hyperparameter.py:72: DeprecationWarning: KerasClassifier is deprecated, use Sci-Keras (https://github.com/adriangb/scikeras) instead. See https://www.adriangb.com/scikeras/stable/migration.html for help migrating.
model = KerasClassifier(build_fn=create_model, verbose=0)
I am using Keras Classifier for cross validation in Deeplearning but show me the warning , i want to know that which class or methods are deprecated in keras instead of KerassClassifier
i am importing this like as
from keras.wrappers.sklearn import KerasClassifier
expecting the answer

Related

getting an attribution error that AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike' in tensorflow?

I'm trying to make encoder decoder like model where I'm getting the following error at model.fit
AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'
model.fit(train_dataloader,
validation_data = test_dataloader,
steps_per_epoch=len(train_dataset)//8,
epochs=10)
I'm using keras 2.3.1 and segmentaion-model
How to resolve it?
This issue is fixed in latest keras version 2.6.0
Workaround for older Keras version
Change is_tensor in file keras/backend/tensorflow_backend.py, as of keras with tensorflow 2.3.0
from tensorflow.python.framework import tensor_util
def is_tensor(x):
return tensor_util.is_tensor(x)
#return isinstance(x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(x)

Run into the following issue: build_tensor_flow is not supported in Eager Mode

I am playing around with TensorFlow, and I am trying to export a Keras Model as a TensorFlow Model. And I ran into the above-mentioned error. I am following the "Build Deep Learning Applications with Keras 2.0" from Lynda (https://www.linkedin.com/learning/building-deep-learning-applications-with-keras-2-0/exporting-google-cloud-compatible-models?u=42751868)
While trying to build a tensor flow model, I came across this error, thrown at line 66 where the add meta graphs and variables function is defined.
line 66, in build_tensor_info
raise RuntimeError("build_tensor_info is not supported in Eager mode.")
RuntimeError: build_tensor_info is not supported in Eager mode.
...model_builder.add_meta_graph_and_variables(
K.get_session(),
tags=[tf.compat.v1.saved_model.tag_constants.SERVING],
signature_def_map={
tf.compat.v1.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature_def
}
)
...
Any thoughts folks?
Is because you are using tensorflow v2. You have to use the tensorflow v2 compatibility and disable eager mode.
Be careful with the tensorflow imports that you use, for example if you use tensorflow_core, be sure that you are using all the dependencies from "tensorflow".
You have to add before your code:
import tensorflow as tf
if tf.executing_eagerly():
tf.compat.v1.disable_eager_execution()
Ran into that exact same problem when compiling that code from LinkedIn Learning for exporting the Keras model that was written using TensorFlow 1.x API. After replacing everything with the equivalent tf.compat.v1 functions, such as changing
model_builder = tf.saved_model.builder.SavedModelBuilder("exported_model")
to
model_builder = tf.compat.v1.saved_model.Builder("exported_model")
and disables eager execution as suggested above by Cristian Zumelzu, the code was able to run fine with the expected warnings about the deprecated functions.

Import ONNX model to tensorflow-ValidationError: BatchNormalization.scale in initializer but not in graph input

I have downloaded ONNX model form CustomVision.ai and now I want to import into tensorflow and I am follwing "https://github.com/onnx/tutorials/blob/master/tutorials/OnnxTensorflowImport.ipynb" for guidance.
I have installed all the prerequisites as discussed in the above link. I am facing an error while executing "tf_rep = prepare(model)"---ValidationError: BatchNormalization.scale in initializer but not in graph input
import onnx
from onnx_tf.backend import prepare
model = onnx.load('C:\\Pankaj\\XYZ\\abc.onnx')
tf_rep = prepare(model)
Thank you for your help and time.

Keras, tensorflow import error

Need help.
(I also checked thread: How do I install Keras and Theano in Anaconda Python on Windows?)
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.layers.recurrent import LSTM
Although I have done everything explained in this thread I keep getting an error for the above prompts.
The error message when I place the cursor on the statements:
Unable to resolve "keras.models". Intellisense may be missing for this module
Unable to resolve "keras.layers.core". Intellisense may be missing for this module
Unable to resolve "keras.layers.recurrent". Intellisense may be missing for this module
I un-istalled, re-installed, deleted theano, updated keras. everything but nothing changed.
Could anyone come up with a possible solution?
thank you

Keras-CNTK saving model-v2 format

I'm using CNTK as the backend for Keras. I'm trying to use my model which I have trained using Keras in C++.
I have trained and saved my model using Keras which is in HDF5. How do I now use CNTK API to save it in their model-v2 format?
I tried this:
model = load_model('model2.h5')
cntk.ops.functions.Function.save(model, 'CNTK_model2.pb')
but i got the following error:
TypeError: save() missing 1 required positional argument: 'filename'
If tensorflow were the backend I would have done this:
model = load_model('model2.h5')
sess = K.get_session()
tf_saver = tf.train.Saver()
tf_saver.save(sess=sess, save_path=checkpoint_path)
How can I achieve the same thing?
As per the comments here, I was able to use this:
import cntk as C
import keras.backend as K
keras_model = K.load_model('my_keras_model.h5')
C.combine(keras_model.model.outputs).save('my_cntk_model')
cntk_model = C.load_model('my_cntk_model')
You can do something like this
model.outputs[0].save('CNTK_model2.pb')
I'm assuming here you have called model.compile (i.e. that's the only case I have tried :-)
The reason you see this error is because keras' cntk backend use a user defined function to do reshape on batch axis, which can't been serialized. We have fixed this issue in CNTK v2.2. Please upgrade your cntk to v2.2, and upgrade keras to last master.
Please see this pull request:
https://github.com/fchollet/keras/pull/7907

Resources