tensorflow2.0

What does InvalidArgumentError in tensorflow 2 mean?

半世苍凉 提交于 2021-02-11 13:17:39
问题 I am new tensorflow. I am trying to implement Linear Regression with custom training, following this tutorial. But when I try to compute W*x + b I am getting this error tf.add(tf.matmul(W,x),b) InvalidArgumentError: cannot compute Add as input #1(zero-based) was expected to be a double tensor but is a float tensor [Op:Add] I initialized W and b W = tf.Variable(np.random.rand(1,9)) b = tf.Variable([1],dtype = tf.float32) x = tf.Variable(np.random.rand(9,100)) But when I changed the

Tensorflow @tf.function - Cannot get session inside Tensorflow graph function

两盒软妹~` 提交于 2021-02-11 02:50:30
问题 I'm trying to use the @tf.function directive with the Keras functional API, to create a TF graph in the training step of a simple neural network. I'm using Tensorflow v 2.1.0 installed with Python 3.7. However I obtain the runtime error as in title and I would appreciate any hint to understand the reason of that. The code is the following. import tensorflow as tf import numpy as np # import the CIFAR10 dataset and normalise the feature distributions (train_images, train_labels), (test_images,

Tensorflow @tf.function - Cannot get session inside Tensorflow graph function

无人久伴 提交于 2021-02-11 02:49:36
问题 I'm trying to use the @tf.function directive with the Keras functional API, to create a TF graph in the training step of a simple neural network. I'm using Tensorflow v 2.1.0 installed with Python 3.7. However I obtain the runtime error as in title and I would appreciate any hint to understand the reason of that. The code is the following. import tensorflow as tf import numpy as np # import the CIFAR10 dataset and normalise the feature distributions (train_images, train_labels), (test_images,

Tensorflow @tf.function - Cannot get session inside Tensorflow graph function

巧了我就是萌 提交于 2021-02-11 02:47:59
问题 I'm trying to use the @tf.function directive with the Keras functional API, to create a TF graph in the training step of a simple neural network. I'm using Tensorflow v 2.1.0 installed with Python 3.7. However I obtain the runtime error as in title and I would appreciate any hint to understand the reason of that. The code is the following. import tensorflow as tf import numpy as np # import the CIFAR10 dataset and normalise the feature distributions (train_images, train_labels), (test_images,

Tensorflow-IO Dataset input pipeline with very large HDF5 files

孤街醉人 提交于 2021-02-10 12:19:31
问题 I have very big training (30Gb) files. Since all the data does not fit in my available RAM, I want to read the data by batch. I saw that there is Tensorflow-io package which implemented a way to read HDF5 into Tensorflow this way thanks to the function tfio.IODataset.from_hdf5() Then, since tf.keras.model.fit() takes a tf.data.Dataset as input containing both samples and targets, I need to zip my X and Y together and then use .batch and .prefetch to load in memory just the necessary data. For

Tensorflow-IO Dataset input pipeline with very large HDF5 files

亡梦爱人 提交于 2021-02-10 12:18:26
问题 I have very big training (30Gb) files. Since all the data does not fit in my available RAM, I want to read the data by batch. I saw that there is Tensorflow-io package which implemented a way to read HDF5 into Tensorflow this way thanks to the function tfio.IODataset.from_hdf5() Then, since tf.keras.model.fit() takes a tf.data.Dataset as input containing both samples and targets, I need to zip my X and Y together and then use .batch and .prefetch to load in memory just the necessary data. For

Tensorflow-IO Dataset input pipeline with very large HDF5 files

佐手、 提交于 2021-02-10 12:18:10
问题 I have very big training (30Gb) files. Since all the data does not fit in my available RAM, I want to read the data by batch. I saw that there is Tensorflow-io package which implemented a way to read HDF5 into Tensorflow this way thanks to the function tfio.IODataset.from_hdf5() Then, since tf.keras.model.fit() takes a tf.data.Dataset as input containing both samples and targets, I need to zip my X and Y together and then use .batch and .prefetch to load in memory just the necessary data. For

How can we use lbfgs_minimize in TensorFlow 2.0

馋奶兔 提交于 2021-02-10 12:00:33
问题 I have been unable to reproduce this example from tensorflow having tensorflow 2.0 installed. This is the original snippet: # A high-dimensional quadratic bowl. ndims = 60 minimum = np.ones([ndims], dtype='float64') scales = np.arange(ndims, dtype='float64') + 1.0 # The objective function and the gradient. def quadratic(x): value = tf.reduce_sum(scales * (x - minimum) ** 2) return value, tf.gradients(value, x)[0] start = np.arange(ndims, 0, -1, dtype='float64') optim_results = tfp.optimizer

How can we use lbfgs_minimize in TensorFlow 2.0

余生长醉 提交于 2021-02-10 11:58:16
问题 I have been unable to reproduce this example from tensorflow having tensorflow 2.0 installed. This is the original snippet: # A high-dimensional quadratic bowl. ndims = 60 minimum = np.ones([ndims], dtype='float64') scales = np.arange(ndims, dtype='float64') + 1.0 # The objective function and the gradient. def quadratic(x): value = tf.reduce_sum(scales * (x - minimum) ** 2) return value, tf.gradients(value, x)[0] start = np.arange(ndims, 0, -1, dtype='float64') optim_results = tfp.optimizer

How to use model input in loss function?

梦想的初衷 提交于 2021-02-10 03:28:07
问题 I am trying to use a custom loss-function which depends on some arguments that the model does not have. The model has two inputs ( mel_specs and pred_inp ) and expects a labels tensor for training: def to_keras_example(example): # Preparing inputs return (mel_specs, pred_inp), labels # Is a tf.train.Dataset for model.fit(train_data, ...) train_data = load_dataset(fp, 'train).map(to_keras_example).repeat() In my loss function I need to calculate the lengths of mel_specs and pred_inp . This