Tensorflow Hparam replacement - tensorflow

In TF 1.12 or TF 2.0 is there going to be a replacement for the following function:
from tensorflow.contrib.training.python.training import hparam
I read that contrib module will go away or merge into core.

In TF 2.0 there is a new API tensorboard.plugins.hparams.api that includes a class HParam
Usage of the new API is described in this guide: Hyperparameter Tuning with the HParams Dashboard

Recently found this Weights and Biases framework that seems to nail the job. It's a more comprehensive solution, and they've got a nicer dashboard.

Related

Where is source for tensorflow gym environments implementation

I need to implement custom tensorflow gym environment to use it with tf agents.
Is there a code on Github for "standard" gym environment? Eg cart pole
Please note this is tensorflow specific question not openAi
In addition to my comment:
OpenAI Gym provides a cartpole example:
Cartpole.py
If you need any additonal information regarding gym, Cartpole integration or Actor-Critics I can highly recommend the following lectures:
Reinforcement Learning # FAU
According to this tutorial:
https://www.tensorflow.org/agents/tutorials/2_environments_tutorial
you either create python (OpenAi like) environment and then use tensorflow wrapper to make it more efficient (covered in the tutorial)
or
create pure tensorflow environment, code example here:
https://github.com/tensorflow/agents/blob/master/tf_agents/environments/tf_environment_test.py

What is difference between tf.keras.models.sequential vs tf.keras.sequential?

What is difference between tf.keras.models.Sequential() vs tf.keras.Sequential()? I don't understand differences between them quite well. Can somebody explain it to me? I am new to TensorFlow but have some basic understanding on machine learning.
>>> tf.keras.models.Sequential==tf.keras.Sequential
True
Both are same as of TFv2. You could use the later.
Added in this commit.
tf.keras.models.Sequential
and
tf.keras.Sequential
Do the same thing but they are from different versions of tensorflow. By the documentation (TensorFlow 2.0), tf.keras.Sequential is the most recent way of called this function.
Keras (keras.io) is a library which is available on its own. It specifies the high-level api.
tf.keras (https://www.tensorflow.org/guide/keras) implements the Keras API specification within TensorFlow.
If you intend to stick to the Tensorflow implementation I would stick to tf.keras. Otherwise you have the advantage to be backend agnostic.
=====
update for updated question.
The renaming of the package for tf.keras.models.Sequential to tf.keras.Sequential must have happened from 1.15 to 2.x you can either downgrade your tensor flow version or update the code. I'd go for the latter

tensorflow.contrib.graph_editor in TF 2 API?

To my understanding tensorflow.contrib is removed in TF 2.0 API. What's the new 2.0 alternative for tensorflow.contrib.graph_editor in TF 1.0 API? https://www.tensorflow.org/api_docs/python/tf/contrib/graph_editor
The alternative as I understand from the documentation is the approach "Keep track of your variables!". When creating graph, you are now responsible for referencing it's nodes.

What is the difference between keras and tf.keras?

I'm learning TensorFlow and Keras. I'd like to try https://www.amazon.com/Deep-Learning-Python-Francois-Chollet/dp/1617294438/, and it seems to be written in Keras.
Would it be fairly straightforward to convert code to tf.keras?
I'm not more interested in the portability of the code, rather than the true difference between the two.
The difference between tf.keras and keras is the Tensorflow specific enhancement to the framework.
keras is an API specification that describes how a Deep Learning framework should implement certain part, related to the model definition and training.
Is framework agnostic and supports different backends (Theano, Tensorflow, ...)
tf.keras is the Tensorflow specific implementation of the Keras API specification. It adds the framework the support for many Tensorflow specific features like: perfect support for tf.data.Dataset as input objects, support for eager execution, ...
In Tensorflow 2.0 tf.keras will be the default and I highly recommend to start working using tf.keras
At this point tensorflow has pretty much entirely adopted the keras API and for a good reason - it's simple, easy to use and easy to learn, whereas "pure" tensorflow comes with a lot of boilerplate code. And yes, you can use tf.keras without any issues, though you might have to re-work your imports in the code. For instance
from keras.layers.pooling import MaxPooling2D
Would turn into:
from tensorflow.keras.layers import MaxPooling2D
The history of Keras Vs tf.keras is long and twisted.
Keras: Keras is a high-level (easy to use) API, built by Google AI Developer/Researcher, Francois Chollet. Written in Python and capable of running on top of backend engines like TensorFlow, CNTK, or Theano.
TensorFlow: A library, also developed by Google, for the Deep Learning developer Community, for making deep learning applications accessible and usable to public. Open Sourced and available on GitHub.
With the release of Keras v1.1.0, Tensorflow was made default backend engine. That meant: if you installed Keras on your system, you were also installing TensorFlow.
Later, with TensorFlow v1.10.0, for the first time tf.keras submodule was introduced in Tensorflow. The first step in integrating Keras within TensorFlow
With the release of Keras 2.3.0,
first release of Keras in sync with tf.keras
Last major release to support other multi-backend engines
And most importantly, going forward, recommend switching the code from keras to Tensorflow2.0 and tf.keras packages.
Refer this tweet from François Chollet to use tf.keras.
That means,
Change Everywhere
From
from keras.models import Sequential
from keras.models import load_model
To
from tensorflow.keras.models import Sequential
from tensorflow.keras.models import load_model
And In requirements.txt,
tensorflow==2.3.0
*Disclaimer: it might give conflicts if you were using an older version of Keras. Do pip uninstall keras in that case.

Replace "from tensorflow.contrib import layers"

How to replace from tensorflow.contrib import layers with new core functionality. I want to move my TF 1.4 code to 1.12 in preparation for TF 2.0.
The core functionality corresponding to tf.contrib.layers is in tf.layers. Some of the differences are discussed in this question. However this will not prepare you for TF 2.0.
If your goal is to prepare your code for TF 2.0, consider that tf.contrib will be removed entirely (either split from TF or integrated into it) and that tf.layers too will be removed and the high-level API will reside under tf.keras. So to best prepare for TF 2.0 you should start using tf.keras.layers instead.
Here is a blog post about some of the practical differences to expect with TF 2.0.