What is the difference between tensorflow.keras.layers and keras.layers? - python

I have read a related question's answer about this on stackoverflow which explains the difference between tensorflow.keras.layers and tensorflow.layers, link:
What is the difference between tf.keras.layers versus tf.layers?
But, it doesn't answer the difference between tensorflow.keras.layers and keras.layers, whereas I noticed I can import them also.
So, what is the difference between them?

Keras used to be able to support different backends (tensorflow, theano and CNTK). Since keras 2.3, there is no difference between keras and tf.keras.
An excerpt from the Readme of the keras repository on github :
Multi-backend Keras and tf.keras
Multi-backend Keras has been discontinued. At this time, we recommend that Keras users who use multi-backend Keras with the TensorFlow backend switch to tf.keras in TensorFlow 2.0.
Keras 2.2.5 was the last release of Keras implementing the 2.2.* API. It was the last release to only support TensorFlow 1 (as well as Theano and CNTK).
The current release is Keras 2.4.0, which simply redirects to tf.keras.

Related

module 'torch.optim' has no attribute 'NAdam'

nadam = torch.optim.NAdam(model.parameters())
This gives the error AttributeError: module 'torch.optim' has no attribute 'NAdam'. My PyTorch version is '1.9.1+cu102', the python version is 3.7.11. VS code does not even suggest the optimizer but the documentation clearly mentions the optimizer. I can import other optimizers like Adam
https://pytorch.org/docs/1.9.1/optim.html
From the official website, NAdam is not among the optimizers in pytorch v 1.9.1.
Try upgrading to v 1.10.0, and your code should work just fine.
According to documentation, NAdam is new in 1.10. It does not show in https://pytorch.org/docs/1.9.1/optim.html?highlight=optim#module-torch.optim
It is in https://pytorch.org/docs/1.10.0/optim.html?highlight=optim#module-torch.optim

Is there any way to get CRF loss in using Tensorflow addons

I have used "from tensorflow_addons.layers import CRF" for the CRF implementation in TensorFlow. I am familiar with the way around using Keras contrib library but I was wondering how did tf didn't make any implementation of crf loss in tf 2?

Keras create dataset from CSV without TensorFlow

On every question and tutorial I have found, tf.data.Dataset is used for CSV files, but I am not using tensorflow, I am using PlaidML because my AMD GPU is not supported in ROCm. I have tried using the same code by doing
os.environ["KERAS_BACKEND"] = "plaidml.keras.backend"
from tensorflow import keras
but that still does not use the plaidml backend. How do I load this dataset: https://www.kaggle.com/keplersmachines/kepler-labelled-time-series-data into keras without tensorflow? Thank you. I check if the plaidml backend is used by looking at the output. If it says "Using plaidml.keras.backend backend", then it is using plaidml. Also, only plaidml recognizes my GPU, so tensorflow will use my CPU.

keras model weights 1.x to 2.x

I have a set of weights from a model developed in keras 1.10 with theano backend.
Right now I would like to use those weights in a more recent version of keras (2.2.4).
Just by loading them on the more recent version of keras the results are not the same (in 2.2.4 the results are not accurate). I can retrain the model but it would take some time. Is there some way to use the weights?
I tried to load the weights from 1.10 to 2.2.4 and it did not work. Also found a project on git:
https://gist.github.com/davecg/e33b9b29d218b5966fb8e2f617e90399
To update the weights from Keras 1.x to 2.x and also did not work.
Thanks for the answers.

Does the Keras implementation in TF2 support everything native Keras can do with TF1?

We are working with Keras on top of TensorFlow 1.x. But now that TF 2.0 is coming we are thinking of switching to that update, using the Keras API implementation built into TF 2.0.
But before we do so, I would like to ask you guys: Do you know whether the Keras implementation in TF 2.0 does support everything native Keras does with TF 1.0, or are there any features missing?
Moreover, will I be able to use my Keras code 1:1 with the new TF 2.0 implementation of the Keras API, or do we need to re-write parts of our existing Keras code?
If you want to use TensorFlow, then I highly recommend you to switch and use the TensorFlow implementation of Keras (i.e. tf.keras) because it will support more features of TF and also would be much more efficient and optimized than native Keras.
Actually, Keras maintainers released a new version (2.2.5) of Keras a few days ago (after more than 10 months with no new release!) and they also recommend to use tf.keras. Here are the release notes:
Keras 2.2.5 is the last release of Keras that implements the 2.2.* API. It is the last release to only support TensorFlow 1 (as well as Theano and CNTK).
The next release will be 2.3.0, which makes significant API changes and add support for TensorFlow 2.0. The 2.3.0 release will be the last major release of multi-backend Keras. Multi-backend Keras is superseded by tf.keras.
At this time, we recommend that Keras users who use multi-backend Keras with the TensorFlow backend switch to tf.keras in TensorFlow 2.0. tf.keras is better maintained and has better integration with TensorFlow features.
This: "Multi-backend Keras is superseded by tf.keras" is a strong indicator that it is better to switch to tf.keras, especially if you are still at the beginning of your project.

Categories