tensorflow2.x

batch_size in tf model.fit() vs. batch_size in tf.data.Dataset

北慕城南 提交于 2020-08-10 02:20:31
问题 I have a large dataset that can fit in host memory. However, when I use tf.keras to train the model, it yields GPU out-of-memory problem. Then I look into tf.data.Dataset and want to use its batch() method to batch the training dataset so that it can execute the model.fit() in GPU. According to its documentation, an example is as follows: train_dataset = tf.data.Dataset.from_tensor_slices((train_examples, train_labels)) test_dataset = tf.data.Dataset.from_tensor_slices((test_examples, test

Tensorflow 2.1.0 - An op outside of the function building code is being passed a “Graph” tensor

China☆狼群 提交于 2020-08-07 05:51:06
问题 I am trying to implement a recent paper. Part of this implementation involves moving from tf 1.14 to tf 2.1.0. The code was working with tf 1.14 but is no longer working. NOTE: If I disable eager execution tf.compat.v1.disable_eager_execution() then the code works as expected. Is this the solution? I've made plenty of models before in TF 2.x and never had to disable eager execution to achieve normal functionality. I have distilled the problem to a very short gist that shows what's happening.

AttributeError: 'Tensor' object has no attribute 'numpy' in Tensorflow 2.1

走远了吗. 提交于 2020-08-05 08:37:37
问题 I am trying to convert the shape property of a Tensor in Tensorflow 2.1 and I get this error: AttributeError: 'Tensor' object has no attribute 'numpy' I already checked that the output of tf.executing eagerly() is True , A bit of context: I load a tf.data.Dataset from a TFRecords, then I apply a map . The maping function is trying to convert the shape property of one of the dataset sample Tensor to numpy: def _parse_and_decode(serialized_example): """ parse and decode each image """ features

AttributeError: 'Tensor' object has no attribute 'numpy' in Tensorflow 2.1

喜欢而已 提交于 2020-08-05 08:35:43
问题 I am trying to convert the shape property of a Tensor in Tensorflow 2.1 and I get this error: AttributeError: 'Tensor' object has no attribute 'numpy' I already checked that the output of tf.executing eagerly() is True , A bit of context: I load a tf.data.Dataset from a TFRecords, then I apply a map . The maping function is trying to convert the shape property of one of the dataset sample Tensor to numpy: def _parse_and_decode(serialized_example): """ parse and decode each image """ features

AttributeError: 'Tensor' object has no attribute 'numpy' in Tensorflow 2.1

岁酱吖の 提交于 2020-08-05 08:35:13
问题 I am trying to convert the shape property of a Tensor in Tensorflow 2.1 and I get this error: AttributeError: 'Tensor' object has no attribute 'numpy' I already checked that the output of tf.executing eagerly() is True , A bit of context: I load a tf.data.Dataset from a TFRecords, then I apply a map . The maping function is trying to convert the shape property of one of the dataset sample Tensor to numpy: def _parse_and_decode(serialized_example): """ parse and decode each image """ features

How to get other metrics in Tensorflow 2.0 (not only accuracy)?

为君一笑 提交于 2020-07-03 08:27:17
问题 I'm new in the world of Tensorflow and I'm working on the simple example of mnist dataset classification. I would like to know how can I obtain other metrics (e.g precision, recall etc) in addition to accuracy and loss (and possibly to show them). Here's my code: from __future__ import absolute_import, division, print_function, unicode_literals import tensorflow as tf from tensorflow.keras.callbacks import ModelCheckpoint from tensorflow.keras.callbacks import TensorBoard import os #load

TensorFlowOpLayer messes up the TensorBoard graphs

僤鯓⒐⒋嵵緔 提交于 2020-05-29 07:08:09
问题 This question is about TensorFlow (and TensorBoard) version 2.2rc3, but I have experienced the same issue with 2.1. It is a continuation of the question 'Messed up TensorBoard graphs due to Python operations'. Consider the following code: from datetime import datetime import tensorflow as tf from tensorflow import keras inputs = keras.layers.Input(shape=(784, )) outputs = tf.zeros([32, 10], tf.float32) for i in range(0, 3): x = keras.layers.Dense(32, activation='relu', name='Model/Block' +

Messed up TensorBoard graphs due to Python operations

半腔热情 提交于 2020-05-17 07:09:06
问题 This question is about TensorFlow (and TensorBoard) version 2.2rc3, but I have experienced the same issue with 2.1. Consider the following weird code: from datetime import datetime import tensorflow as tf from tensorflow import keras inputs = keras.layers.Input(shape=(784, )) x1 = keras.layers.Dense(32, activation='relu', name='Model/Block1/relu')(inputs) x1 = keras.layers.Dropout(0.2, name='Model/Block1/dropout')(x1) x1 = keras.layers.Dense(10, activation='softmax', name='Model/Block1

Best practice to write code compatible to both TensorFlow 1 and 2

拥有回忆 提交于 2020-04-17 22:56:06
问题 This official guide explains how to migrate TF 1 code to TF 2. This is however not what I want. I want that my code runs fine on both TF 1 and TF 2 (and I only want the non-eager mode). Also, I slowly want to use some of the new features, but in an optional way. (E.g. the user could pass some option like --use-fancy-new-tf2-feature , which would only work with TF 2. That's fine.) And maybe after one or two years, I would slowly drop the TF 1 support. But I definitely need this transition

Tensorflow 2.0 can't use GPU, something wrong in cuDNN? :Failed to get convolution algorithm. This is probably because cuDNN failed to initialize

…衆ロ難τιáo~ 提交于 2020-04-10 06:02:50
问题 I am trying to understand and debug my code. I try to predict with a CNN model developed under tf2.0/tf.keras on GPU, but get those error messages. could someone help me to fix it? here is my environmental configuration enviroments: python 3.6.8 tensorflow-gpu 2.0.0-rc0 nvidia 418.x CUDA 10.0 cuDNN 7.6+** and the log file, 2019-09-28 13:10:59.833892: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0 2019-09-28 13:11:00.228025