tensorflow-estimator

tf.estimator.train_and_evaluate got wrong Evaluation accuray and loss

两盒软妹~` 提交于 2020-01-02 05:22:07
问题 I use tf.estimator.train_and_evaluate to train and evaluate my model. This is my code: import tensorflow as tf import numpy as np from tensorflow.contrib.slim.nets import resnet_v2 import tensorflow.contrib.slim as slim (x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data(path='mnist.npz') x_train = np.expand_dims(x_train, 3).astype(np.float32)[:5000] y_train = y_train.astype(np.int32)[:5000] x_test = np.expand_dims(x_test, 3).astype(np.float32)[:1000] y_test = y_test

Transfer learning with tf.estimator.Estimator framework

落花浮王杯 提交于 2019-12-31 13:58:08
问题 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

Tensorflow error : unsupported callable

吃可爱长大的小学妹 提交于 2019-12-29 06:32:00
问题 I follow the tutorial https://www.tensorflow.org/tutorials/layers and I want use it to use my own dataset. def train_input_fn_custom(filenames_array, labels_array, batch_size): # Reads an image from a file, decodes it into a dense tensor, and resizes it to a fixed shape. def _parse_function(filename, label): image_string = tf.read_file(filename) image_decoded = tf.image.decode_png(image_string, channels=1) image_resized = tf.image.resize_images(image_decoded, [40, 40]) return image_resized,

Data type mismatch in streaming F1 score calculation in Tensorflow

泪湿孤枕 提交于 2019-12-24 20:25:10
问题 I was trying to use this code as it is on Tensorflow 1.13.1. However, it throws the following error: sherlock@mybox:~/cs273/autocat/bert$ python streaming2.py Traceback (most recent call last): File "streaming2.py", line 233, in <module> tf_f1 = tf_f1_score(t, p) File "streaming2.py", line 161, in tf_f1_score f1s[2] = tf.reduce_sum(f1 * weights) File "/home/sherlock/.virtualenvs/autocat/local/lib/python2.7/site-packages/tensorflow/python/ops/math_ops.py", line 812, in binary_op_wrapper return

How to verify optimized model in tensorflow

£可爱£侵袭症+ 提交于 2019-12-24 17:17:24
问题 I'm following a tutorial from codelabs. They use this script to optimize the model python -m tensorflow.python.tools.optimize_for_inference \ --input=tf_files/retrained_graph.pb \ --output=tf_files/optimized_graph.pb \ --input_names="input" \ --output_names="final_result" they verify the optimized_graph.pb using this script python -m scripts.label_image \ --graph=tf_files/optimized_graph.pb \ --image=tf_files/flower_photos/daisy/3475870145_685a19116d.jpg The problem is I try to use optimize

tensorflow pipeline for pickled pandas data input

我的未来我决定 提交于 2019-12-24 10:16:43
问题 I would like to input compressed pd.read_pickle(filename, compression='xz') pandas dataframes as a pipeline to tensorflow. I want to use the high level API tf.estimator classifier which requires an input function. My data files are large matrices ~(1400X16) of floats, and each matrix corresponds to a particular type (label). Each type (label) is contained in a different directory, so I know the matrix label from its directory. At the low level, I know I can populate data using a feed_dict={X

Tensorflow Estimator: Execute an operation at a specific epoch

北城以北 提交于 2019-12-24 01:45:16
问题 I built a model in Tensorflow and I'm trying to convert it into a TensorFlow Estimator. Here is an example of what I have: train_op = tf.train.AdamOptimizer(learning_rate=lr).minimize(cost) saver = tf.train.Saver() init = tf.global_variables_initializer() assign_Wvh = pretrained_rsm.temporal_assignment(params['W']) with tf.Session() as sess: sess.run(init) for epoch in range(epochs): start = time.time() _ = sess.run(train_op, feed_dict={x: input}) print("%i. elapsed time: %0.2f" % (epoch,

How to save and restore a tf.estimator.Estimator model with export_savedmodel?

╄→尐↘猪︶ㄣ 提交于 2019-12-24 01:23:55
问题 I started using Tensorflow recently and I try to get use to tf.estimator.Estimator objects. I would like to do something a priori quite natural: after having trained my classifier, i.e. an instance of tf.estimator.Estimator (with the train method), I would like to save it in a file (whatever the extension) and then reload it later to predict the labels for some new data. Since the official documentation recommends to use Estimator APIs, I guess something as important as that should be

How to fix “module 'tensorflow' has no attribute 'estimator' ” error

╄→гoц情女王★ 提交于 2019-12-23 21:25:11
问题 I'm using conda (env created via YAML) + pip to set up a Tensorflow v1.13.1 environment on my Linux Mint box. After setup, whenever I try to import tf.estimator I receive the AttributeError described in the title: AttributeError: module 'tensorflow' has no attribute 'estimator' I do not have any version of TF installed outside of a conda environment (or on pip). I do have another conda environment set up the same way but with Tensorflow 2.0 alpha, which can import tf.estimator just fine. I

TensorFlow ExportOutputs, PredictOuput, and specifying signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY

岁酱吖の 提交于 2019-12-23 14:40:54
问题 Context I have a colab with a very simple demo Estimator for the purpose of learning / understanding the Estimator API with the goal of making a convention for a plug-and-play model with useful bells and whistles of the trade in tack (e.g. early stopping if the validation set stops improving, exporting the model, etc). Each of the three Estimator modes ( TRAIN , EVAL , and PREDICT ) return an EstimatorSpec. According to the docs: __new__( cls, mode, predictions=None, # required by PREDICT