tensorflow-datasets

In Tensorflow dataset api: How to use padded_batch so that a pads with a specific value without specifying the number of pads

纵然是瞬间 提交于 2020-01-29 20:34:52
问题 If you don't specify a padding_values then padded_batch will autopad with 0. However, if you want a different value such as -1, you can't just set padded_batch = -1 . You need to input a sequence for every slot that needs to be padded. However, I'm working with a dataset which has random values for the array lengths, so I can't really do that, since I don't know by how many numbers I'll need to pad. Since padding_values will automatically fill the rest of the value with 0, I hope there's some

Tensorflow 2 throwing ValueError: as_list() is not defined on an unknown TensorShape

守給你的承諾、 提交于 2020-01-24 18:42:16
问题 I'm trying to train a Unet model in Tensorflow 2.0 which takes as input an image and a segmentation mask, but I'm getting a ValueError : as_list() is not defined on an unknown TensorShape . The stack trace shows the problem occurs during _get_input_from_iterator(inputs) : /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/training_v2_utils.py in _prepare_feed_values(model, inputs, mode) 110 for inputs will always be wrapped in lists. 111 """ --> 112 inputs, targets,

Keras ImageDataGenerator for multiple inputs and image based target output

谁说胖子不能爱 提交于 2020-01-22 02:31:11
问题 I have a model which takes two Images as inputs and generates a single image as a Target output. All of my training image-data is in the following sub-folders: input1 input2 target Can I use the ImageDataGenerator class and methods like flow_from_directory and model.fit_generator method in keras to train the network? How can I do this? since most examples I have come across deal with single input and a label-based target output. In my case, I have a non-categorical target output data and

Using feed_dict is more than 5x faster than using dataset API?

那年仲夏 提交于 2020-01-20 14:34:27
问题 I created a dataset in TFRecord format for testing. Every entry contains 200 columns, named C1 - C199 , each being a strings list, and a label column to denote the labels. The code to create the data can be found here: https://github.com/codescv/tf-dist/blob/8bb3c44f55939fc66b3727a730c57887113e899c/src/gen_data.py#L25 Then I used a linear model to train the data. The first approach looks like this: dataset = tf.data.TFRecordDataset(data_file) dataset = dataset.prefetch(buffer_size=batch_size

Is there an alternative to tf.py_function() for custom Python code?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-16 19:33:12
问题 I have started using TensorFlow 2.0 and have a little uncertainty with regard to one aspect. Suppose I have this use case: while ingesting data with the tf.data.Dataset I want to apply some specific augmentation operations upon some images. However, the external libraries that I am using require that the image is a numpy array , not a tensor . When using tf.data.Dataset.from_tensor_slices() , the flowing data needs to be of type Tensor. Concrete example: def my_function(tensor_image): print

TensorFlow Serving crossed columns strange error

核能气质少年 提交于 2020-01-16 09:13:07
问题 I am receiving the following error when trying to send a prediction request to my saved model, running with TensorFlow Serving: { "error": "Expected D2 of index to be 2 got 3 at position 0\n\t [[{{node linear/linear_model/linear_model/linear_model/int2Id_X_stringId/SparseCross}}]]" } The problem appears to come from trying to use crossed columns in a linear model...? My model in service is a tf.estimator.LinearClassifier . My REST API request is a POST to 'model_directory/model:predict' with

Training classifier from TFRecords in Tensorflow

戏子无情 提交于 2020-01-14 06:43:30
问题 I already have some code which trains a classifier from numpy arrays. However, my training data set is very large. It seems the recommended solution is to use TFRecords . My attempts to use TFRecords with my own data set have failed, so I have gradually reduced my code to a minimal toy. Example: import tensorflow as tf def readsingleexample(serialized): print("readsingleexample", serialized) feature = dict() feature['x'] = tf.FixedLenFeature([], tf.int64) feature['label'] = tf.FixedLenFeature

Train Tensorflow model with estimator (from_generator)

空扰寡人 提交于 2020-01-13 02:23:11
问题 I am trying train an estimator with a generator, but I want to feed this estimator with a package of samples for each iteration. I show the code: def _generator(): for i in range(100): feats = np.random.rand(4,2) labels = np.random.rand(4,1) yield feats, labels def input_func_gen(): shapes = ((4,2),(4,1)) dataset = tf.data.Dataset.from_generator(generator=_generator, output_types=(tf.float32, tf.float32), output_shapes=shapes) dataset = dataset.batch(4) # dataset = dataset.repeat(20) iterator

How to iterate a dataset several times using TensorFlow's Dataset API?

随声附和 提交于 2020-01-12 01:48:14
问题 How to output the value in a dataset several times? (dataset is created by Dataset API of TensorFlow) import tensorflow as tf dataset = tf.contrib.data.Dataset.range(100) iterator = dataset.make_one_shot_iterator() next_element = iterator.get_next() sess = tf.Session() epoch = 10 for i in range(epoch): for j in range(100): value = sess.run(next_element) assert j == value print(j) Error message: tensorflow.python.framework.errors_impl.OutOfRangeError: End of sequence [[Node: IteratorGetNext =

Tensorflow DNN with tf-idf sparse matrix

霸气de小男生 提交于 2020-01-06 08:25:08
问题 Trying to implement tesorflow DNN for text classification. tf-idf sparse IV: X_train_sam: <31819x3122 sparse matrix of type '<class 'numpy.float64'>'with 610128 stored elements in Compressed Sparse Row format> labels as DV: y_train_sam.values:array(['mexican', 'mexican', 'italian', ..., 'chinese', 'italian','italian'], dtype=object) Converting sparse to tensor using following piece: def convert_sparse_matrix_to_sparse_tensor(X): coo = X.tocoo() indices = np.mat([coo.row, coo.col]).transpose()