How to use Model.fit which supports generators (after fit_generator deprecation)

Model.fit_generator is deprecated starting from tensorflow 2.1.0 which is currently is in rc1. You can find the documentation for tf-2.1.0-rc1 here: https://www.tensorflow.org/versions/r2.1/api_docs/python/tf/keras/Model#fit As you can see the first argument of the Model.fit can take a generator so just pass it your generator.

Why does keras model predict slower after compile?

UPDATE – 1/15/2020: the current best practice for small batch sizes should be to feed inputs to the model directly – i.e. preds = model(x), and if layers behave differently at train / inference, model(x, training=False). Per latest commit, this is now documented. I haven’t benchmarked these, but per the Git discussion, it’s also worth … Read more

AttributeError: ‘Model’ object has no attribute ‘predict_classes’

The predict_classes method is only available for the Sequential class (which is the class of your first model) but not for the Model class (the class of your second model). With the Model class, you can use the predict method which will give you a vector of probabilities and then get the argmax of this … Read more

RNN Regularization: Which Component to Regularize?

Regularizers that’ll work best will depend on your specific architecture, data, and problem; as usual, there isn’t a single cut to rule all, but there are do’s and (especially) don’t’s, as well as systematic means of determining what’ll work best – via careful introspection and evaluation. How does RNN regularization work? Perhaps the best approach … Read more

Compute class weight function issue in ‘sklearn’ library when used in ‘Keras’ classification (Python 3.8, only in VS code)

After spending a lot of time, this is how I fixed it. I still don’t know why but when the code is modified as follows, it works fine. I got the idea after seeing this solution for a similar but slightly different issue. class_weights = compute_class_weight( class_weight = “balanced”, classes = np.unique(train_classes), y = train_classes … Read more

Keras Maxpooling2d layer gives ValueError

Quoting an answer mentioned in github, you need to specify the dimension ordering: Keras is a wrapper over Theano or Tensorflow libraries. Keras uses the setting variable image_dim_ordering to decide if the input layer is Theano or Tensorflow format. This setting can be specified in 2 ways – specify ‘tf’ or ‘th’ in ~/.keras/keras.json like … Read more

Should I use @tf.function for all functions?

TLDR: It depends on your function and whether you are in production or development. Don’t use tf.function if you want to be able to debug your function easily, or if it falls under the limitations of AutoGraph or tf.v1 code compatibility. I would highly recommend watching the Inside TensorFlow talks about AutoGraph and Functions, not … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)