Kmeans clustering using TENSORFLOW2 - python

How could I convert a pandas database that contains 47 columns and 99999 lines into a tensors in
Tensorflow 2? is the Kmeans algorithm already implemented under TF 2? because the command tf.contrib.factorization.KMeans does not work under TF2 since tf.contrib no longer exists on the second API Tensorflow
List item

I got my TF2 example working with KMeans implementation from here tf.compat.v1.estimator.experimental.KMeans
Note: As of Nov 7, 2019 the code example has a problem. Change tf.estimator.experimental.KMeans to tf.compat.v1.estimator.experimental.KMeans
Also for anyone looking for TF 2 contrib, there's a quote on the r1.15 tf.contrib page:
Warning: The tf.contrib module will not be included in TensorFlow 2.0.
Many of its submodules have been integrated into TensorFlow core, or
spun-off into other projects like tensorflow_io, or tensorflow_addons.
For instructions on how to upgrade see the Migration guide.

Related

module tensorflow has no attribute contrib

I've made a piece of code using a tutorial based on tensorflow 1.6 which uses 'contrib' and this is not compatible with my current tensorflow verison (2.1.0).
I haven't been able to run the upgrade script and downgrading my version of tf causes another host of problems.
I've also tried using other modules in tensor flow 2 such as tensorflow-addons and disabling version 2 behaviour.
What to do??
Thank you to #jdehesa
Here is the information on TensorFlow official website.
Warning: The tf.contrib module is not included in TensorFlow 2. Many
of its submodules have been integrated into TensorFlow core, or
spun-off into other projects like tensorflow_io, or tensorflow_addons.
For instructions on how to upgrade see the Migration guide.
https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib
https://www.tensorflow.org/guide/migrate
Or, you can just convert the code to an appropriate version for TF 2.x.

Unable to train dataset for RCNN due to attribute error?

I am currently following the tutorial by EdjeElectronics: https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#1-install-anaconda-cuda-and-cudnn and I am in the step no:6. Run the Training. I had certain errors before but I cleared them so I have generated the TFrecords and I am stuck here.image
If there are any files that I need to attach for your convenience pls let me know.
The contrib attribute has moved out of Tesnsorflow version 2.
To use version 1, replace the 'import tensorflow as tf' line as follows:
#import tensorflow as tf
import tensorflow.compat.v1 as tf #using v1 of tf
Actually, when looking at this link - https://www.tensorflow.org/guide/migrate, there is a line -
It is still possible to run 1.X code, unmodified (except for contrib), in TensorFlow 2.0
The link goes to page - https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md which explains what happened to each contrib module.
You can try to migrate code to Tensorflow 2 or whatever version you are using.
Another alternative is to uninstall your Tensorflow installation and install Tensorflow with version 1.x.

tensorflow.contrib.predictor.from_saved_model() in Tensorflow 2

Currently using Tensorflow 1 and noticed tensorflow.contrib has been removed in Tensorflow 2. How to convert tensorflow.contrib.predictor.from_saved_model() to work on Tensorflow 2?
In TF2 the Predictor API is no longer supported and is not in TF2 at all (the whole contrib module is gone). You can either attempt using TF-HUB (the link above says Predictor is replaced by it), convert your model to a Keras model (the way I'd recommend if you have a custom model architecture), convert it to an Estimator, or stick to the latest TF1 release.

Why I am getting DatasetV1Adapter return type instead of TensorSliceDataset for tf.data.Dataset.from_tensor_slices(X)

I was just following code samples in the Book "Hands on Machine Learning with scikit-learn and tensorflow".
import tensorflow as tf
X = tf.range(10)
dataset = tf.data.Dataset.from_tensor_slices(X)
According to the book I should get type of variable 'dataset' 'TensorSliceDataset shapes:(), types: tf.int32', but instead I am getting 'DatasetV1Adapter shapes: (), types: tf.int32'
Based on their documentation, if you're using tf 2.0 (or below) it doesn't support TensorSliceDataset, and will give you DatasetV1Adapter
https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/raw_ops
You will need TF 2.1.x and up
You probably have a different TensorFlow version than the one used in the book. I encountered a similar issue running this notebook and compared to my locally running machine until I installed the latest version of TensorFlow using pip and not the anaconda version.

CoreML load model saved with Keras 2

Apple's new CoreML can work with models trained on popular framework. At least they say so at 18" in the WWDC video. But in the docs it seems that concerning neural nets they only support Caffe and Keras 1.2.2 (see code), while Keras it on it 2.0 version and Tensorflow and Theano are quite popular in their own rights.
To get the conversion running with Keras 2, is there a better way than implementing the conversion myself? The Keras conversion code in the coremltools package is ~2000 lines longs and I don't have a deep knowledge of all Keras model representation so I really don't want to go that route.
I've tried converting a model saved with Keras 2 directly, but that doesn't work and fails with
TypeError: ('Keyword argument not understood:', u'gamma_initializer')
from site-packages/keras/engine/topology.py", line 326
They also don't have a github for coremltools so it's hard to discuss this package in more details. I've uploaded a copy of the package: https://github.com/gsabran/coremltools
Keras 2.0 support is already there (released yesterday), with coremltools v.0.4.0
Also, refer to newest comments on Apple Developer Forums

Categories

Resources