tensorflow-estimator

How to use tf.data's initializable iterator and reinitializable interator and feed data to estimator api?

馋奶兔 提交于 2019-12-04 08:22:20
All the official google tutorials use the one shot iterator for all the estimator api implementation, i couldnt find any documentation on how to use tf.data's initializable iterator and reinitializable interator instead of one shot iterator. Can someone kindly show me how to switch between train_data and test_data using tf.data's initializable iterator and reinitializable interator. We need to run a session to use feed dict and switch the dataset in the initializable iterator, its a low level api and its confusing how to use it part of estimator api architecture PS : I did find that google

Tensorflow 2.0 Keras is training 4x slower than 2.0 Estimator

笑着哭i 提交于 2019-12-04 00:58:39
We recently switched to Keras for TF 2.0, but when we compared it to the DNNClassifier Estimator on 2.0, we experienced around 4x slower speeds with Keras. But I cannot for the life of me figure out why this is happening. The rest of the code for both are identical, using an input_fn() that returns the same tf.data.Dataset, and using identical feature_columns. Been struggling with this problem for days now. Any help would be greatly greatly appreciated. Thank you Estimator code: estimator = tf.estimator.DNNClassifier( feature_columns = feature_columns, hidden_units = [64,64], activation_fn =

Converting Tensorflow Graph to use Estimator, get 'TypeError: data type not understood' at loss function using `sampled_softmax_loss` or `nce_loss`

自作多情 提交于 2019-12-03 20:14:03
问题 I am trying to convert Tensorflow's official basic word2vec implementation to use tf.Estimator. The issue is that the loss function( sampled_softmax_loss or nce_loss ) gives an error when using Tensorflow Estimators. It works perfectly fine in the original implementation. Here's is Tensorflow's official basic word2vec implementation: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/tutorials/word2vec/word2vec_basic.py Here is the Google Colab notebook where I

Input multiple files into Tensorflow dataset

余生长醉 提交于 2019-12-03 17:41:28
I have the following input_fn. def input_fn(filenames, batch_size): # Create a dataset containing the text lines. dataset = tf.data.TextLineDataset(filenames).skip(1) # Parse each line. dataset = dataset.map(_parse_line) # Shuffle, repeat, and batch the examples. dataset = dataset.shuffle(10000).repeat().batch(batch_size) # Return the dataset. return dataset It works great if filenames=['file1.csv'] or filenames=['file2.csv'] . It gives me an error if filenames=['file1.csv', 'file2.csv'] . In Tensorflow documentation it says filenames is a tf.string tensor containing one or more filenames. How

TensorFlow Custom Estimator - Restore model after small changes in model_fn

隐身守侯 提交于 2019-12-03 13:37:46
I am using tf.estimator.Estimator for developing my model, I wrote a model_fn and trained 50,000 iterations, now I want to make a small change in my model_fn , for example add a new layer. I don't want to start training from scratch, I want to restore all the old variables from the 50,000 checkpoint, and continue training from this point. When I try to do so I get a NotFoundError How can this be done with tf.estimator.Estimator ? TL;DR The easiest way to load variables from a previous checkpoint is to use the function tf.train.init_from_checkpoint() . Just one call to this function inside the

How to use tensorflow debugging tool tfdbg on tf.estimator in Tensorflow?

为君一笑 提交于 2019-12-03 12:37:28
I am working with Tensorflow version 1.4, and I want to debug my train() function. In this link https://www.tensorflow.org/programmers_guide/debugger#debugging_tf-learn_estimators_and_experiments there is a way to do it for tf.contrib.learn Estimators , but I can not find a way to adapt it to the (new in version 1.4) tf.estimator . This is what I have tried: from tensorflow.python import debug as tf_debug # Create an estimator my_estimator = tf.estimator.Estimator(model_fn=model_fn, params=model_params, model_dir='/tb_dir', config=config_estimator) # Create a LocalCLIDebugHook and use it as a

How to switch between training and validation dataset with tf.MonitoredTrainingSession?

回眸只為那壹抹淺笑 提交于 2019-12-03 06:51:13
I want to use feedable iterator design in tensorflow Dataset API, so I can switch to validation data after some training steps. But if I switched to validation data, it will end the whole session. The following code demonstrate what I want to do: import tensorflow as tf graph = tf.Graph() with graph.as_default(): training_ds = tf.data.Dataset.range(32).batch(4) validation_ds = tf.data.Dataset.range(8).batch(4) handle = tf.placeholder(tf.string, shape=[]) iterator = tf.data.Iterator.from_string_handle( handle, training_ds.output_types, training_ds.output_shapes) next_element = iterator.get_next

Transfer learning with tf.estimator.Estimator framework

╄→尐↘猪︶ㄣ 提交于 2019-12-03 00:24:59
I'm trying to do transfer learning of an Inception-resnet v2 model pretrained on imagenet, using my own dataset and classes. My original codebase was a modification of a tf.slim sample which I can't find anymore and now I'm trying to rewrite the same code using the tf.estimator.* framework. I am running, however, into the problem of loading only some of the weights from the pretrained checkpoint, initializing the remaining layers with their default initializers. Researching the problem, I found this GitHub issue and this question , both mentioning the need to use tf.train.init_from_checkpoint

Prediction from model saved with `tf.estimator.Estimator` in Tensorflow

本小妞迷上赌 提交于 2019-12-02 22:26:43
I am using tf.estimator.Estimator to train a model: def model_fn(features, labels, mode, params, config): input_image = features["input_image"] eval_metric_ops = {} predictions = {} # Create model with tf.name_scope('Model'): W = tf.Variable(tf.zeros([784, 10]), name="W") b = tf.Variable(tf.zeros([10]), name="b") logits = tf.nn.softmax(tf.matmul(input_image, W, name="MATMUL") + b, name="logits") loss = None train_op = None if mode != tf.estimator.ModeKeys.PREDICT: loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=labels, logits=logits)) train_op = tf.contrib.layers.optimize

Using a created tensorflow model for predicting

流过昼夜 提交于 2019-12-02 18:04:37
问题 I'm looking at source code from this Tensorflow article that talks about how to create a wide-and-deep learning model. https://www.tensorflow.org/versions/r1.3/tutorials/wide_and_deep Here is the link to the python source code: https://github.com/tensorflow/tensorflow/blob/r1.3/tensorflow/examples/learn/wide_n_deep_tutorial.py What the goal of it is, is to train a model that will predict if someone makes more or less than $50k a year given the data in the census information. As instructed, I