tf.keras

Should I use @tf.function for all functions?

痞子三分冷 提交于 2020-08-21 06:30:28
问题 An official tutorial on @tf.function says: To get peak performance and to make your model deployable anywhere, use tf.function to make graphs out of your programs. Thanks to AutoGraph, a surprising amount of Python code just works with tf.function, but there are still pitfalls to be wary of. The main takeaways and recommendations are: Don't rely on Python side effects like object mutation or list appends. tf.function works best with TensorFlow ops, rather than NumPy ops or Python primitives.

Should I use @tf.function for all functions?

Deadly 提交于 2020-08-21 06:30:22
问题 An official tutorial on @tf.function says: To get peak performance and to make your model deployable anywhere, use tf.function to make graphs out of your programs. Thanks to AutoGraph, a surprising amount of Python code just works with tf.function, but there are still pitfalls to be wary of. The main takeaways and recommendations are: Don't rely on Python side effects like object mutation or list appends. tf.function works best with TensorFlow ops, rather than NumPy ops or Python primitives.

Tensorflow 2.0 does not iterate through entire dataset when tf.keras.model.fit is called

亡梦爱人 提交于 2020-08-09 10:17:09
问题 I am training a model in tf.keras with tensorflow 2.0. I am having an issue where my model appears to train successfully, but it is not iterating through the entire dataset. I restructured the code into tensorflow 1.15, and I do not have this issue in tensorflow 1.x. I am following this tutorial for Multiple Input Series. Below are more details: I have a time-series dataset. It is very small so I am able to load it into memory, so I do not need the dataset API. I am windowing the time-series

What is the difference between MaxPool and MaxPooling layers in Keras?

让人想犯罪 __ 提交于 2020-08-07 07:56:38
问题 I just started working with Keras and noticed that there are two layers with very similar names for max pooling: MaxPool and MaxPooling . I was surprised that I couldn't find the difference between these two on Google; so I am wondering what the difference is between the two if any. 回答1: they are the same. you can test it by your own import numpy as np import tensorflow as tf from tensorflow.keras.layers import * # create dummy data X = np.random.uniform(0,1, (32,5,3)).astype(np.float32)

What is the difference between MaxPool and MaxPooling layers in Keras?

余生长醉 提交于 2020-08-07 07:56:19
问题 I just started working with Keras and noticed that there are two layers with very similar names for max pooling: MaxPool and MaxPooling . I was surprised that I couldn't find the difference between these two on Google; so I am wondering what the difference is between the two if any. 回答1: they are the same. you can test it by your own import numpy as np import tensorflow as tf from tensorflow.keras.layers import * # create dummy data X = np.random.uniform(0,1, (32,5,3)).astype(np.float32)

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.

Tensorflow: FailedPreconditionError: Error while reading resource variable from Container: localhost. When running sess.run() on custom loss function

耗尽温柔 提交于 2020-08-06 05:47:35
问题 I have a code running Keras with TensorFlow 1. The code modifies the loss function in order to do deep reinforcement learning: import os import gym import numpy as np import pandas as pd import matplotlib.pyplot as plt env = gym.make("CartPole-v0").env env.reset() n_actions = env.action_space.n state_dim = env.observation_space.shape from tensorflow import keras import random from tensorflow.keras import layers as L import tensorflow as tf from tensorflow.python.keras.backend import set

Tensorflow: FailedPreconditionError: Error while reading resource variable from Container: localhost. When running sess.run() on custom loss function

≯℡__Kan透↙ 提交于 2020-08-06 05:47:27
问题 I have a code running Keras with TensorFlow 1. The code modifies the loss function in order to do deep reinforcement learning: import os import gym import numpy as np import pandas as pd import matplotlib.pyplot as plt env = gym.make("CartPole-v0").env env.reset() n_actions = env.action_space.n state_dim = env.observation_space.shape from tensorflow import keras import random from tensorflow.keras import layers as L import tensorflow as tf from tensorflow.python.keras.backend import set

Tensorflow: FailedPreconditionError: Error while reading resource variable from Container: localhost. When running sess.run() on custom loss function

被刻印的时光 ゝ 提交于 2020-08-06 05:46:24
问题 I have a code running Keras with TensorFlow 1. The code modifies the loss function in order to do deep reinforcement learning: import os import gym import numpy as np import pandas as pd import matplotlib.pyplot as plt env = gym.make("CartPole-v0").env env.reset() n_actions = env.action_space.n state_dim = env.observation_space.shape from tensorflow import keras import random from tensorflow.keras import layers as L import tensorflow as tf from tensorflow.python.keras.backend import set

ValueError: Expect x to be a non-empty array or dataset (Tensor Flow lite model maker on Collab)

半腔热情 提交于 2020-08-06 05:03:13
问题 I am following this tutorial on creating a custom Model using TensorFlow lite Model Maker on Collab. import pathlib path = pathlib.Path('/content/employee_pics') count = len(list(path.glob('*/*.jpg'))) count data = ImageClassifierDataLoader.from_folder(path) train_data, test_data = data.split(0.5) I have an issue with step 2: model = image_classifier.create(train_data) I get an error: ValueError: Expect x to be a non-empty array or dataset. Am I doing something wrong? The data set provided in